Patchwork [02/12] image.bbclass: add a hook funtion to support readonly rootfs

login
register
mail settings
Submitter Qi.Chen@windriver.com
Date Jan. 24, 2013, 8:16 a.m.
Message ID <3d6b90b5ad79166eda3883ad4e9d5ca1ed937f10.1359014474.git.Qi.Chen@windriver.com>
Download mbox | patch
Permalink /patch/43267/
State New
Headers show

Comments

Qi.Chen@windriver.com - Jan. 24, 2013, 8:16 a.m.
From: Chen Qi <Qi.Chen@windriver.com>

read_only_rootfs_hook: this funtion is invoked only if 'read-only-rootfs'
is in IMAGE_FEATURES. It tweaks some basic files and makes populate-
volatile.sh script run at rootfs time.

For now, it has real effect only if the init system is sysvinit.

[YOCTO #3406]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 meta/classes/image.bbclass |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Mark Hatle - Jan. 24, 2013, 7:44 p.m.
On 1/24/13 2:16 AM, Qi.Chen@windriver.com wrote:
> From: Chen Qi <Qi.Chen@windriver.com>
>
> read_only_rootfs_hook: this funtion is invoked only if 'read-only-rootfs'
> is in IMAGE_FEATURES. It tweaks some basic files and makes populate-
> volatile.sh script run at rootfs time.
>
> For now, it has real effect only if the init system is sysvinit.
>
> [YOCTO #3406]
>
> Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
> ---
>   meta/classes/image.bbclass |   18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
>
> diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> index 0293d2e..91045fc 100644
> --- a/meta/classes/image.bbclass
> +++ b/meta/classes/image.bbclass
> @@ -201,6 +201,24 @@ run_intercept_scriptlets () {
>   	fi
>   }
>
> +# A hook function to support read-only-rootfs IMAGE_FEATURES
> +# Currently, it only supports sysvinit system.
> +read_only_rootfs_hook () {
> +	if ${@base_contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then
> +	        # Tweak the mount option in fstab
> +		sed -i '/rootfs/ s/defaults/ro/' ${IMAGE_ROOTFS}/etc/fstab

There is a slight bug in the above.  Not all configurations will contain an 
/etc/fstab!  So you need to check for the existence of the file before you try 
to sed it.

(Initramfs is where I hit a problem trying to test this.)

--Mark

> +	        # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes
> +		if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then
> +			sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default/rcS
> +		fi
> +	        # Run populate-volatile.sh at rootfs time to set up basic files
> +	        # and directories to support read-only rootfs.
> +		if [ -e ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
> +			${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
> +		fi
> +	fi
> +}
> +
>   fakeroot do_rootfs () {
>   	#set -x
>   	# When use the rpm incremental image generation, don't remove the rootfs
>
Qi.Chen@windriver.com - Jan. 25, 2013, 2:49 a.m.
On 01/25/2013 03:44 AM, Mark Hatle wrote:
> On 1/24/13 2:16 AM, Qi.Chen@windriver.com wrote:
>> From: Chen Qi <Qi.Chen@windriver.com>
>>
>> read_only_rootfs_hook: this funtion is invoked only if 
>> 'read-only-rootfs'
>> is in IMAGE_FEATURES. It tweaks some basic files and makes populate-
>> volatile.sh script run at rootfs time.
>>
>> For now, it has real effect only if the init system is sysvinit.
>>
>> [YOCTO #3406]
>>
>> Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
>> ---
>>   meta/classes/image.bbclass |   18 ++++++++++++++++++
>>   1 file changed, 18 insertions(+)
>>
>> diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
>> index 0293d2e..91045fc 100644
>> --- a/meta/classes/image.bbclass
>> +++ b/meta/classes/image.bbclass
>> @@ -201,6 +201,24 @@ run_intercept_scriptlets () {
>>       fi
>>   }
>>
>> +# A hook function to support read-only-rootfs IMAGE_FEATURES
>> +# Currently, it only supports sysvinit system.
>> +read_only_rootfs_hook () {
>> +    if ${@base_contains("DISTRO_FEATURES", "sysvinit", "true", 
>> "false", d)}; then
>> +            # Tweak the mount option in fstab
>> +        sed -i '/rootfs/ s/defaults/ro/' ${IMAGE_ROOTFS}/etc/fstab
>
> There is a slight bug in the above.  Not all configurations will 
> contain an /etc/fstab!  So you need to check for the existence of the 
> file before you try to sed it.
>
> (Initramfs is where I hit a problem trying to test this.)
>
> --Mark
>

Thank you for pointing it out. I'll fix it.

Thanks,
Chen Qi

>> +            # Change the value of ROOTFS_READ_ONLY in 
>> /etc/default/rcS to yes
>> +        if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then
>> +            sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' 
>> ${IMAGE_ROOTFS}/etc/default/rcS
>> +        fi
>> +            # Run populate-volatile.sh at rootfs time to set up 
>> basic files
>> +            # and directories to support read-only rootfs.
>> +        if [ -e ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
>> +            ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
>> +        fi
>> +    fi
>> +}
>> +
>>   fakeroot do_rootfs () {
>>       #set -x
>>       # When use the rpm incremental image generation, don't remove 
>> the rootfs
>>
>
>
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-core
>
>

Patch

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 0293d2e..91045fc 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -201,6 +201,24 @@  run_intercept_scriptlets () {
 	fi
 }
 
+# A hook function to support read-only-rootfs IMAGE_FEATURES
+# Currently, it only supports sysvinit system.
+read_only_rootfs_hook () {
+	if ${@base_contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then
+	        # Tweak the mount option in fstab
+		sed -i '/rootfs/ s/defaults/ro/' ${IMAGE_ROOTFS}/etc/fstab
+	        # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes
+		if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then
+			sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default/rcS
+		fi
+	        # Run populate-volatile.sh at rootfs time to set up basic files
+	        # and directories to support read-only rootfs.
+		if [ -e ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
+			${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
+		fi
+	fi
+}
+
 fakeroot do_rootfs () {
 	#set -x
 	# When use the rpm incremental image generation, don't remove the rootfs