Patchwork [V6,2/6] image.bbclass: add two funtions to support readonly rootfs

login
register
mail settings
Submitter Qi.Chen@windriver.com
Date Jan. 6, 2013, 9:44 a.m.
Message ID <589cb89b315809bf657c394c4ad5e7aac83d43e5.1357465230.git.Qi.Chen@windriver.com>
Download mbox | patch
Permalink /patch/42089/
State New
Headers show

Comments

Qi.Chen@windriver.com - Jan. 6, 2013, 9:44 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.

choose_volatile_conf: this function is exported and should be overriden
by the specific image recipe. Config files specific to read-only rootfs
are closely related to the image types. So these config file should be
provided by the corresponding image recipes.
In addition, this function adds support to customized config files for
customized images.

[YOCTO #3406]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 meta/classes/image.bbclass |   29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)
Saul Wold - Jan. 11, 2013, 11:33 p.m.
On 01/06/2013 01:44 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.
>
> choose_volatile_conf: this function is exported and should be overriden
> by the specific image recipe. Config files specific to read-only rootfs
> are closely related to the image types. So these config file should be
> provided by the corresponding image recipes.
> In addition, this function adds support to customized config files for
> customized images.
>
> [YOCTO #3406]
>
> Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
> ---
>   meta/classes/image.bbclass |   29 ++++++++++++++++++++++++-----
>   1 file changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> index d3a416d..0cd49f0 100644
> --- a/meta/classes/image.bbclass
> +++ b/meta/classes/image.bbclass
> @@ -167,6 +167,7 @@ inherit ${IMAGE_CLASSES}
>   IMAGE_POSTPROCESS_COMMAND ?= ""
>   MACHINE_POSTPROCESS_COMMAND ?= ""
>   ROOTFS_POSTPROCESS_COMMAND_prepend = "run_intercept_scriptlets; "
> +ROOTFS_POSTPROCESS_COMMAND_prepend = "choose_volatile_conf; "
>
>   # some default locales
>   IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
> @@ -185,6 +186,11 @@ do_build[nostamp] = "1"
>   # task, so that we have a single fakeroot context for the whole process.
>   do_rootfs[umask] = "022"
>
> +choose_volatile_conf () {
> +        # This task should be overriden by the specific image recipe.
> +        # It is used to install the correct conf file for volatile storage
> +        # handling to support read-only rootfs.
> +}
>
>   run_intercept_scriptlets () {
>   	if [ -d ${WORKDIR}/intercept_scripts ]; then
> @@ -396,6 +402,21 @@ zap_root_password () {
>   	mv ${IMAGE_ROOTFS}/etc/passwd.new ${IMAGE_ROOTFS}/etc/passwd
>   }
>
> +# A hook function to support read-only-rootfs IMAGE_FEATURES
> +read_only_rootfs_hook () {
> +	# 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
> +}
> +
>   # allow openssh accept login with empty password string
>   openssh_allow_empty_password () {
>   	if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
> @@ -458,11 +479,9 @@ rootfs_trim_schemas () {
>   	done
>   }
>
> -EXPORT_FUNCTIONS zap_root_password remove_init_link do_rootfs make_zimage_symlink_relative set_image_autologin rootfs_update_timestamp rootfs_no_x_startup
> +EXPORT_FUNCTIONS zap_root_password remove_init_link do_rootfs make_zimage_symlink_relative set_image_autologin rootfs_update_timestamp rootfs_no_x_startup choose_volatile_conf
>
> -do_fetch[noexec] = "1"
> -do_unpack[noexec] = "1"
> -do_patch[noexec] = "1"
> +# do_fetch, do_unpack and do_patch are needed to copy conf files to workdir
>   do_configure[noexec] = "1"
>   do_compile[noexec] = "1"
>   do_install[noexec] = "1"
> @@ -472,4 +491,4 @@ do_package_write_ipk[noexec] = "1"
>   do_package_write_deb[noexec] = "1"
>   do_package_write_rpm[noexec] = "1"
>
> -addtask rootfs before do_build
> +addtask rootfs before do_build after do_patch
>
Why is this needed, and will it continue to be needed if we move to the 
*-volatile-conf packages?

Sau!
Qi.Chen@windriver.com - Jan. 14, 2013, 2:34 a.m.
On 01/12/2013 07:33 AM, Saul Wold wrote:
> On 01/06/2013 01:44 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.
>>
>> choose_volatile_conf: this function is exported and should be overriden
>> by the specific image recipe. Config files specific to read-only rootfs
>> are closely related to the image types. So these config file should be
>> provided by the corresponding image recipes.
>> In addition, this function adds support to customized config files for
>> customized images.
>>
>> [YOCTO #3406]
>>
>> Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
>> ---
>>   meta/classes/image.bbclass |   29 ++++++++++++++++++++++++-----
>>   1 file changed, 24 insertions(+), 5 deletions(-)
>>
>> diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
>> index d3a416d..0cd49f0 100644
>> --- a/meta/classes/image.bbclass
>> +++ b/meta/classes/image.bbclass
>> @@ -167,6 +167,7 @@ inherit ${IMAGE_CLASSES}
>>   IMAGE_POSTPROCESS_COMMAND ?= ""
>>   MACHINE_POSTPROCESS_COMMAND ?= ""
>>   ROOTFS_POSTPROCESS_COMMAND_prepend = "run_intercept_scriptlets; "
>> +ROOTFS_POSTPROCESS_COMMAND_prepend = "choose_volatile_conf; "
>>
>>   # some default locales
>>   IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
>> @@ -185,6 +186,11 @@ do_build[nostamp] = "1"
>>   # task, so that we have a single fakeroot context for the whole 
>> process.
>>   do_rootfs[umask] = "022"
>>
>> +choose_volatile_conf () {
>> +        # This task should be overriden by the specific image recipe.
>> +        # It is used to install the correct conf file for volatile 
>> storage
>> +        # handling to support read-only rootfs.
>> +}
>>
>>   run_intercept_scriptlets () {
>>       if [ -d ${WORKDIR}/intercept_scripts ]; then
>> @@ -396,6 +402,21 @@ zap_root_password () {
>>       mv ${IMAGE_ROOTFS}/etc/passwd.new ${IMAGE_ROOTFS}/etc/passwd
>>   }
>>
>> +# A hook function to support read-only-rootfs IMAGE_FEATURES
>> +read_only_rootfs_hook () {
>> +    # 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
>> +}
>> +
>>   # allow openssh accept login with empty password string
>>   openssh_allow_empty_password () {
>>       if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
>> @@ -458,11 +479,9 @@ rootfs_trim_schemas () {
>>       done
>>   }
>>
>> -EXPORT_FUNCTIONS zap_root_password remove_init_link do_rootfs 
>> make_zimage_symlink_relative set_image_autologin 
>> rootfs_update_timestamp rootfs_no_x_startup
>> +EXPORT_FUNCTIONS zap_root_password remove_init_link do_rootfs 
>> make_zimage_symlink_relative set_image_autologin 
>> rootfs_update_timestamp rootfs_no_x_startup choose_volatile_conf
>>
>> -do_fetch[noexec] = "1"
>> -do_unpack[noexec] = "1"
>> -do_patch[noexec] = "1"
>> +# do_fetch, do_unpack and do_patch are needed to copy conf files to 
>> workdir
>>   do_configure[noexec] = "1"
>>   do_compile[noexec] = "1"
>>   do_install[noexec] = "1"
>> @@ -472,4 +491,4 @@ do_package_write_ipk[noexec] = "1"
>>   do_package_write_deb[noexec] = "1"
>>   do_package_write_rpm[noexec] = "1"
>>
>> -addtask rootfs before do_build
>> +addtask rootfs before do_build after do_patch
>>
> Why is this needed, and will it continue to be needed if we move to 
> the *-volatile-conf packages?
>

The read_only_rootfs_hook function is always needed.
The choose_volatile_conf function is not needed any more if we move to 
the *-volatile-conf package.

Thanks,
Chen Qi

> Sau!
>
>
>

Patch

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index d3a416d..0cd49f0 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -167,6 +167,7 @@  inherit ${IMAGE_CLASSES}
 IMAGE_POSTPROCESS_COMMAND ?= ""
 MACHINE_POSTPROCESS_COMMAND ?= ""
 ROOTFS_POSTPROCESS_COMMAND_prepend = "run_intercept_scriptlets; "
+ROOTFS_POSTPROCESS_COMMAND_prepend = "choose_volatile_conf; "
 
 # some default locales
 IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
@@ -185,6 +186,11 @@  do_build[nostamp] = "1"
 # task, so that we have a single fakeroot context for the whole process.
 do_rootfs[umask] = "022"
 
+choose_volatile_conf () {
+        # This task should be overriden by the specific image recipe.
+        # It is used to install the correct conf file for volatile storage
+        # handling to support read-only rootfs.
+}
 
 run_intercept_scriptlets () {
 	if [ -d ${WORKDIR}/intercept_scripts ]; then
@@ -396,6 +402,21 @@  zap_root_password () {
 	mv ${IMAGE_ROOTFS}/etc/passwd.new ${IMAGE_ROOTFS}/etc/passwd
 } 
 
+# A hook function to support read-only-rootfs IMAGE_FEATURES
+read_only_rootfs_hook () {
+	# 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
+}
+
 # allow openssh accept login with empty password string
 openssh_allow_empty_password () {
 	if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
@@ -458,11 +479,9 @@  rootfs_trim_schemas () {
 	done
 }
 
-EXPORT_FUNCTIONS zap_root_password remove_init_link do_rootfs make_zimage_symlink_relative set_image_autologin rootfs_update_timestamp rootfs_no_x_startup
+EXPORT_FUNCTIONS zap_root_password remove_init_link do_rootfs make_zimage_symlink_relative set_image_autologin rootfs_update_timestamp rootfs_no_x_startup choose_volatile_conf
 
-do_fetch[noexec] = "1"
-do_unpack[noexec] = "1"
-do_patch[noexec] = "1"
+# do_fetch, do_unpack and do_patch are needed to copy conf files to workdir
 do_configure[noexec] = "1"
 do_compile[noexec] = "1"
 do_install[noexec] = "1"
@@ -472,4 +491,4 @@  do_package_write_ipk[noexec] = "1"
 do_package_write_deb[noexec] = "1"
 do_package_write_rpm[noexec] = "1"
 
-addtask rootfs before do_build
+addtask rootfs before do_build after do_patch