Bug 3155 - init-live.sh should clean up temporary mounts
Summary: init-live.sh should clean up temporary mounts
Status: VERIFIED FIXED
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: core (show other bugs)
Version: 1.2.1
Hardware: x86 Multiple
: Medium enhancement
Target Milestone: 1.4 M2
Assignee: Chen Qi
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2012-09-21 14:27 UTC by Marc Ferland
Modified: 2013-01-31 07:47 UTC (History)
7 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Ferland 2012-09-21 14:27:18 UTC
A live system currently has to following mounted filesystems at boot:

>rootfs on / type rootfs (rw)
>proc on /proc type proc (rw,relatime)
>sysfs on /sys type sysfs (rw,relatime)
>/dev/sda on /media/sda type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
>/dev/loop0 on / type ext3 (rw,noatime,nodiratime,barrier=1,data=ordered)
>devtmpfs on /dev type devtmpfs (rw,relatime,size=439740k,nr_inodes=109935,mode=755)
>proc on /proc type proc (rw,relatime)
>tmpfs on /mnt/.psplash type tmpfs (rw,relatime,size=40k)
>sysfs on /sys type sysfs (rw,relatime)
>devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
>tmpfs on /var/volatile type tmpfs (rw,relatime)
>tmpfs on /media/ram type tmpfs (rw,relatime)

I think the recipes-core/initrdscripts/files/init-live.sh script should cleanup the temporary /proc and /sys mounts before it calls switch_root.

Something like:
># Clean up temporary mounts
>umount /proc
>umount /sys
>
>cd $ROOT_MOUNT
>exec switch_root -c /dev/console $ROOT_MOUNT /sbin/init
Comment 1 Marc Ferland 2012-09-21 14:29:35 UTC
This would get rid of the duplicate /proc and /sys mounts. The thing I'm not sure is if something else would depend on these mounts...
Comment 2 Marc Ferland 2012-10-02 15:55:36 UTC
After looking at this a little closer, I found out that switch_root already moves the /proc and /sys file systems. It is actually the init-boot.sh script that unconditionally remounts the /proc and /sys file systems even if there already mounted.

Based on this, the solution would be to at least check if these two file systems are already mounted.

BTW, the sysfs.sh script in recipe-core/initscripts also tries to mount /sys and proc... this might be a little redundant with the content of init-boot.sh.
Comment 3 Marc Ferland 2012-10-03 17:57:35 UTC
(In reply to comment #2)
> After looking at this a little closer, I found out that switch_root already
> moves the /proc and /sys file systems.

Actually busybox's switch_root does _not_ move /proc and /sys but util-linux's one does. This means init-live.sh should manually move them. Sorry for the confusion.
Comment 4 Chen Qi 2012-11-06 03:27:51 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > After looking at this a little closer, I found out that switch_root already
> > moves the /proc and /sys file systems.
> 
> Actually busybox's switch_root does _not_ move /proc and /sys but
> util-linux's one does. This means init-live.sh should manually move them.
> Sorry for the confusion.

Hi Marc:
It seems that currently Yocto only supports the "live" feature for core-image-mininal and only for x86 archs. I searched in current project and the result is as following.

~/poky$ grep -R COMPATIBLE_HOST meta/recipes-core/initrdscripts/initramfs-live-install_1.0.bb
# on the COMPATIBLE_HOST below, which needs to take precedence
COMPATIBLE_HOST = "(i.86|x86_64).*-linux"
~/poky$ find meta* -name *image*.bb | grep init
meta/recipes-core/images/core-image-minimal-initramfs.bb

Is it right? Or maybe I missed something?
Comment 5 Marc Ferland 2012-11-06 13:52:44 UTC
Hi Chen,

I realize the problem description could have been a little bit clearer! Sorry about that! Let me re-explain the problem.

When I boot a machine that uses the poky/meta/recipes-core/initrdscripts/files/init-live.sh script to perform a live bootup I see duplicated /proc and /sys in mounted filesystems (look at the bug description for an example).

This is caused by a missing 'mount -n --move' inside the boot_live_root function (from init-live.sh).

So the problem could be fixed by adding something like:
 # Move virtual filesystems over to the real filesystem
 mount -n --move /sys $ROOT_MOUNT/sys
 mount -n --move /proc $ROOT_MOUNT/proc

just before calling switch_root.

One other thing that surprised me, is that busybox's implementation of switch_root does _not_ move /proc and /sys _but_ the util-linux's one does. Guess we should be careful which version we package along with this script.

Hope this helps!
Comment 6 Chen Qi 2012-11-07 10:39:45 UTC
Thanks Marc!

BTW, I'm wondering whether there's any way to boot an iso image with runqemu?
I just built an image: core-image-minimal-qemux86-20121107085353.iso, but I can't boot it up. Any suggestion?
Comment 7 Marc Ferland 2012-11-07 15:58:11 UTC
(In reply to comment #6)
> Thanks Marc!
> 
> BTW, I'm wondering whether there's any way to boot an iso image with runqemu?
> I just built an image: core-image-minimal-qemux86-20121107085353.iso, but I
> can't boot it up. Any suggestion?

I usually just use ext3 files with runqemu. I know it is possible to boot from an iso using straight qemu but I've never tried with runqemu.
Comment 8 Chen Qi 2012-12-31 02:29:13 UTC
Problem reproduced, and the patch will be sent in a day or two.
Comment 9 Chen Qi 2013-01-08 06:55:46 UTC
merged in poky/master: 14649c003550ee08b73b1d8dbf51343087295e7b

http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=ChenQi/live-image
Comment 10 Yi Zhao 2013-01-31 07:47:39 UTC
Verified with master branch: 27c8af1e3a9092caa19bd813c4dd0747de766dc5

Steps:
###########
1. Add line IMAGE_FSTYPES = "live" to conf/local.conf
2. Build the qemux86 minimal image
3. Run command: runqemu qemux86 iso
###########

################
root@qemux86:~# mount
rootfs on / type rootfs (rw)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
none on /dev type devtmpfs (rw,relatime,size=55400k,nr_inodes=13850,mode=755)
/dev/hdc on /media/realroot type iso9660 (ro,relatime)
/dev/loop0 on / type ext3 (ro,noatime,nodiratime,barrier=1,data=ordered)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
tmpfs on /var/volatile type tmpfs (rw,relatime)
tmpfs on /media/ram type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
#################