Skip to contentSkip to conversation

initscripts: support read-only rootfs

PATCH Superseded [email protected] 1 participant 2 messages Dec 25, 2012 1 message not in the archive

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/2 initscripts: support read-only rootfs

From: Chen Qi <[email protected]>

Add read-only rootfs support to sysvinit startup system.

The main ideas here are:
1) Let populate-volatile.sh run at rootfs time to set up basic directories and files needed by read-only rootfs.
2) Use symbolic links to create the illusion that some directories/files are writable.

Two extra config files for read-only rootfs support are created, one for minimal image -- volatiles-readonly-minimal, and the other for sato image -- volatiles-readonly-sato.

[YOCTO #3404]
[YOCTO #3406]

---
 .../initscripts/initscripts-1.0/bootmisc.sh        |    9 +-
 .../initscripts-1.0/populate-volatile.sh           |  285 ++++++++++----------
 .../initscripts/initscripts-1.0/volatiles          |    1 +
 .../initscripts-1.0/volatiles-readonly-minimal     |   23 ++
 .../initscripts-1.0/volatiles-readonly-sato        |   30 +++
 meta/recipes-core/initscripts/initscripts_1.0.bb   |   15 +-
 6 files changed, 210 insertions(+), 153 deletions(-)
 create mode 100644 meta/recipes-core/initscripts/initscripts-1.0/volatiles-readonly-minimal
 create mode 100644 meta/recipes-core/initscripts/initscripts-1.0/volatiles-readonly-sato
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +1 -8
index 4f76cb4..3b5a47f 100755
@@ -54,14 +54,7 @@ fi
 
 #
 # This is as good a place as any for a sanity check
-# /tmp should be a symlink to /var/tmp to cut down on the number
-# of mounted ramdisks.
-if test ! -L /tmp && test -d /var/tmp
-then
-	rm -rf /tmp
-	ln -sf /var/tmp /tmp
-fi
-
+#
 # Set the system clock from hardware clock
 # If the timestamp is more recent than the current time,
 # use the timestamp instead.
meta/recipes-core/initscripts/initscripts-1.0/populate-volatile.sh +142 -143

334 lines not on this page · raw message

meta/recipes-core/initscripts/initscripts-1.0/volatiles +1 -0
index e0741aa..f7e2ef7 100644
@@ -31,6 +31,7 @@ l root root 1777 /var/lock /var/volatile/lock
 l root root 0755 /var/log /var/volatile/log
 l root root 0755 /var/run /var/volatile/run
 l root root 1777 /var/tmp /var/volatile/tmp
+l root root 1777 /tmp /var/tmp
 d root root 0755 /var/lock/subsys none
 f root root 0664 /var/log/wtmp none
 f root root 0664 /var/run/utmp none
meta/recipes-core/initscripts/initscripts-1.0/volatiles-readonly-minimal new file +23 -0
new file mode 100644
index 0000000..6169ecc
@@ -0,0 +1,23 @@
+# This configuration file lists filesystem objects specific to readonly rootfs
+# that should get verified during startup and be created if missing.
+#
+# Every line must either be a comment starting with #
+# or a definition of format:
+# <type> <owner> <group> <mode> <path> <linksource>
+# where the items are separated by whitespace !
+#
+# <type> : d|f|l : (d)irectory|(f)ile|(l)ink
+#
+# A linking example:
+# l root root 0777 /var/test /tmp/testfile
+# f root root 0644 /var/test none
+#
+# Understanding links:
+# When populate-volatile is to verify/create a directory or file, it will first
+# check its existence. If a link is found to exist in the place of the target,
+# the path of the target is replaced with the target the link points to.
+# Thus, if a link is in the place to be verified, the object will be created
+# in the place the link points to instead.
+# This explains the order of "link before object" as in the example above, where
+# a link will be created at /var/test pointing to /tmp/testfile and due to this
+# link the file defined as /var/test will actually be created as /tmp/testfile.
meta/recipes-core/initscripts/initscripts-1.0/volatiles-readonly-sato new file +30 -0
new file mode 100644
index 0000000..e128869
@@ -0,0 +1,30 @@
+# This configuration file lists filesystem objects specific to readonly rootfs
+# that should get verified during startup and be created if missing.
+#
+# Every line must either be a comment starting with #
+# or a definition of format:
+# <type> <owner> <group> <mode> <path> <linksource>
+# where the items are separated by whitespace !
+#
+# <type> : d|f|l : (d)irectory|(f)ile|(l)ink
+#
+# A linking example:
+# l root root 0777 /var/test /tmp/testfile
+# f root root 0644 /var/test none
+#
+# Understanding links:
+# When populate-volatile is to verify/create a directory or file, it will first
+# check it's existence. If a link is found to exist in the place of the target,
+# the path of the target is replaced with the target the link points to.
+# Thus, if a link is in the place to be verified, the object will be created
+# in the place the link points to instead.
+# This explains the order of "link before object" as in the example above, where
+# a link will be created at /var/test pointing to /tmp/testfile and due to this
+# link the file defined as /var/test will actually be created as /tmp/testfile.
+d root root 0755 /var/volatile/lib/ none
+d root root 0755 /var/volatile/lib/dropbear/ none
+d root root 0755 /var/volatile/lib/nfs/ none
+d root root 1777 /var/volatile/lib/dbus/ none
+l root root 0755 /var/lib/dropbear /var/volatile/lib/dropbear
+l root root 0755 /var/lib/nfs /var/volatile/lib/nfs
+l root root 0755 /var/lib/dbus /var/volatile/lib/dbus
meta/recipes-core/initscripts/initscripts_1.0.bb +13 -2
index 39be9a8..d0869ea 100644
@@ -3,7 +3,7 @@ DESCRIPTION = "Initscripts provide the basic system startup initialization scrip
 SECTION = "base"
 LICENSE = "GPLv2"
 LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe"
-PR = "r138"
+PR = "r139"
 
 INHIBIT_DEFAULT_DEPS = "1"
 
@@ -30,8 +30,10 @@ SRC_URI = "file://functions \
            file://device_table.txt \
            file://populate-volatile.sh \
            file://volatiles \
+           file://volatiles-readonly-minimal \
+           file://volatiles-readonly-sato \
            file://save-rtc.sh \
-	   file://GPLv2.patch"
+           file://GPLv2.patch"
 
 SRC_URI_append_arm = " file://alignment.sh"
 
@@ -86,6 +88,15 @@ do_install () {
 	install -m 0755    ${WORKDIR}/populate-volatile.sh ${D}${sysconfdir}/init.d
 	install -m 0755    ${WORKDIR}/save-rtc.sh	${D}${sysconfdir}/init.d
 	install -m 0644    ${WORKDIR}/volatiles		${D}${sysconfdir}/default/volatiles/00_core
+        # Install read-only rootfs specific config files in case of an read-only-rootfs image
+	if ${@base_contains("IMAGE_FEATURES", "read-only-rootfs", "true", "false" ,d)}; then
+	        if ${@base_contains("IMAGE_FEATURES", "x11-sato", "true", "false" ,d)}; then
+                        install -m 0644 ${WORKDIR}/volatiles-readonly-sato ${D}${sysconfdir}/default/volatiles/00_core_readonly
+                else
+                        install -m 0644 ${WORKDIR}/volatiles-readonly-minimal ${D}${sysconfdir}/default/volatiles/00_core_readonly
+                fi
+	fi
+
 	if [ "${TARGET_ARCH}" = "arm" ]; then
 		install -m 0755 ${WORKDIR}/alignment.sh	${D}${sysconfdir}/init.d
 	fi
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 2/2 rootfs: support read-only-rootfs image feature

In reply to a message not in the archive

From: Chen Qi <[email protected]>

Two small tweaks at rootfs time:
1) If IMAGE_FEATUERS contains 'read-only-rootfs', we make populate-volatile.sh run at rootfs time to set up basic files and directories.
2) If IMAGE_FEATURES contains 'read-only-rootfs', mount options in /etc/fstab is automatically tweaked to the appropriate value.

[YOCTO #3406]

---
 meta/classes/core-image.bbclass |    4 +++-
 meta/classes/image.bbclass      |    6 ++++++
 meta/classes/rootfs_deb.bbclass |   14 ++++++++++++++
 meta/classes/rootfs_ipk.bbclass |   15 +++++++++++++++
 meta/classes/rootfs_rpm.bbclass |   20 +++++++++++++++++++-
 5 files changed, 57 insertions(+), 2 deletions(-)
meta/classes/core-image.bbclass +3 -1
index 2e67018..ee0b397 100644
@@ -28,6 +28,7 @@ LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3
 # - dev-pkgs            - development packages (headers, etc.) for all installed packages in the rootfs
 # - dbg-pkgs            - debug symbol packages for all installed packages in the rootfs
 # - doc-pkgs            - documentation packages for all installed packages in the rootfs
+# - read-only-rootfs    - tweaks an image to support read-only rootfs
 #
 PACKAGE_GROUP_x11 = "packagegroup-core-x11"
 PACKAGE_GROUP_x11-base = "packagegroup-core-x11-base"
@@ -78,4 +79,5 @@ ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp ; "
 ROOTFS_POSTPROCESS_COMMAND += '${@base_contains("IMAGE_FEATURES", "debug-tweaks", "", "zap_root_password ; ",d)}'
 # Allow openssh accept empty password login if both debug-tweaks and ssh-server-openssh are enabled
 ROOTFS_POSTPROCESS_COMMAND += '${@base_contains("IMAGE_FEATURES", "debug-tweaks ssh-server-openssh", "openssh_allow_empty_password; ", "",d)}'
-
+# Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled
+ROOTFS_POSTPROCESS_COMMAND += '${@base_contains("IMAGE_FEATURES", "read-only-rootfs", "fstab_tweak_mount_opt; ", "",d)}'
meta/classes/image.bbclass +6 -0
index 8bf718a..3854ee7 100644
@@ -394,6 +394,12 @@ zap_root_password () {
 	mv ${IMAGE_ROOTFS}/etc/passwd.new ${IMAGE_ROOTFS}/etc/passwd
 } 
 
+# Change the mount options for rootfs in case of a read-only-rootfs image
+fstab_tweak_mount_opt () {
+	sed '/rootfs/ s/defaults/ro/' < ${IMAGE_ROOTFS}/etc/fstab > ${IMAGE_ROOTFS}/etc/fstab.new
+	mv ${IMAGE_ROOTFS}/etc/fstab.new ${IMAGE_ROOTFS}/etc/fstab
+}
+
 # allow openssh accept login with empty password string
 openssh_allow_empty_password () {
 	if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
meta/classes/rootfs_deb.bbclass +14 -0
index 293953d..052d5d9 100644
@@ -84,6 +84,20 @@ fakeroot rootfs_deb_do_rootfs () {
 
 	${ROOTFS_POSTPROCESS_COMMAND}
 
+	# Let populate-volatile.sh run at rootfs time in case of an read-only rootfs
+	if ${@base_contains("IMAGE_FEATURES", "read-only-rootfs", "true", "false", d)}; then
+		if [ ! -e ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
+			echo "${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh doesn't exist."
+			exit 1
+		else
+			${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
+			if [ $? != 0 ]; then
+				echo "Running populate-volatile.sh under ${IMAGE_ROOTFS} failed"
+				exit 1
+			fi
+		fi
+	fi
+
 	log_check rootfs
 }
 
meta/classes/rootfs_ipk.bbclass +15 -0
index 5c962de..b851049 100644
@@ -114,6 +114,21 @@ fakeroot rootfs_ipk_do_rootfs () {
 			remove_packaging_data_files
 		fi
 	fi
+
+        # Let populate-volatile.sh run at rootfs time in case of a read-only-rootfs image
+	if ${@base_contains("IMAGE_FEATURES", "read-only-rootfs", "true", "false", d)}; then
+		if [ ! -e ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
+			echo "${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh doesn't exist."
+			exit 1
+		else
+			${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
+			if [ $? != 0 ]; then
+				echo "Running populate-volatile.sh under ${IMAGE_ROOTFS} failed"
+				exit 1
+			fi
+		fi
+	fi
+
 	set +x
 	log_check rootfs
 }
meta/classes/rootfs_rpm.bbclass +19 -1
index f7e4c5e..733764a 100644
@@ -89,6 +89,8 @@ fakeroot rootfs_rpm_do_rootfs () {
 
 	# Report delayed package scriptlets
 	for i in ${IMAGE_ROOTFS}/etc/rpm-postinsts/*; do
+                # We should add a check here to check whether we're building a read-only rootfs
+                # If so, exit 1, because there are still postintalls that are to be run on target.
 		if [ -f $i ]; then
 			echo "Delayed package scriptlet: `head -n 3 $i | tail -n 1`"
 		fi
@@ -104,7 +106,7 @@ for i in /etc/rpm-postinsts/*; do
 	if [ -f $i ] && $i; then
 		rm $i
 	else
-		echo "ERROR: postinst $i failed."
+		[ -f $i ] && echo "ERROR: postinst $i failed."
 	fi
 done
 rm -f ${sysconfdir}/rcS.d/S${POSTINSTALL_INITPOSITION}run-postinsts
@@ -127,6 +129,22 @@ EOF
 	# Remove all remaining resolver files
 	rm -rf ${IMAGE_ROOTFS}/install
 
+	# Run init scripts that are necessary in case of an read-only rootfs
+	if ${@base_contains("IMAGE_FEATURES", "read-only-rootfs", "true", "false", d)}; then
+		if [ ! -e ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
+			echo "${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh doesn't exist."
+			exit 1
+		else
+			# Run populate_volatile.sh under ${IMAGE_ROOTFS} to set up basic
+                        # directories and files which are related to volatile storage.
+			${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
+			if [ $? != 0 ]; then
+				echo "Running populate-volatile.sh under ${IMAGE_ROOTFS} failed"
+				exit 1
+			fi
+		fi
+	fi
+
 	log_check rootfs
 }
 
Signature · 1 line
1.7.9.5