[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Patch] live-config: make umountfs service unmount local file system when rebooting



Hi Daniel,
Attached please find a patch to make umountfs service unmount local file system when rebooting. Without this kind of mechanism, a mounted local file system in Debian live won't be cleanly unmounted when rebooting. I believe you might have a better patch or mechanism for this.
Let me explain more in the following:
How to reproduce the problem:
1. Booting http://live.debian.net/cdimage/daily-builds/squeeze/20101224-1/i386/iso-hybrid/debian-live-squeeze-i386-standard.iso
2. Mount a local file system, e.g. /dev/sdb1 by "sudo mount /dev/sdb1 /mnt"
It's a clean ext3 partition. you can see the kernel messages:
========================
[  118.181345] kjournald starting.  Commit interval 5 seconds
[  118.183104] EXT3 FS on sdb1, internal journal
[  118.184463] EXT3-fs: mounted filesystem with ordered data mode.
========================
3. Then run "sudo poweroff" without unmounting it:
========================
Cleaning up ifupdown....
Deactivating swap...done.
live-boot is resyncing snapshots and caching reboot files...

Please remove the disc, close the the tray (if any) and press ENTER to continue:
========================
In the above rebooting messages, you can see the umountfs service only deactivate swap, no unmounting local file system.

4. Reboot the system with the same Debian live again, and in the command line, run "sudo mount /dev/sdb1 /mnt"
========================
[   30.864182] kjournald starting.  Commit interval 5 seconds
[   30.865997] EXT3 FS on sdb1, internal journal
[   30.867242] EXT3-fs: recovery complete.
[   30.868518] EXT3-fs: mounted filesystem with ordered data mode.
========================
In the above kernel messages you can see the recovery was issued due to it was not cleanly unmounted.

I dug more and found that the regular umountfs service (/etc/init.d/umountfs) has a mechanism to list the protected mounting points:
        PROTECTED_MOUNTS="$(sed -n '0,/^\/[^ ]* \/ /p' /proc/mounts)"
As you can see, it's looking for something like:
========================
/dev/sda1 / reiserfs rw,relatime,notail 0 0
========================
then list it and the earlier mounting points as the protected ones.
However, a regular /proc/mounts on a booting Debian live environment with a local file system mounted is:
========================
user@debian:~$ cat /proc/mounts
rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
none /dev devtmpfs rw,relatime,size=548848k,nr_inodes=137212,mode=755 0 0
none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
/dev/sr0 /live/image iso9660 ro,noatime 0 0
/dev/loop0 /filesystem.squashfs squashfs ro,noatime 0 0
tmpfs /live/cow tmpfs rw,noatime,mode=755 0 0
aufs / aufs rw,relatime,si=363cece4,noxino 0 0
tmpfs /live tmpfs rw,relatime 0 0
tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
tmpfs /tmp tmpfs rw,nosuid,nodev,relatime 0 0
/dev/sdb1 /mnt ext3 rw,relatime,errors=continue,data=ordered 0 0
========================

As you see, due to the aufs (not /dev/sda1 for example) is mounted as /, all the mounting points, including /dev/sdb1, will be listed as protected ones in PROTECTED_MOUNTS. That's why. Please consider this as an important case, since it might cause a file system crashes if an user does not unmount file system before she/he issues a reboot or shutdown command in Debian live.
BTW, in the patch file, this line:
========================
sed -i -r -e "s@\|/lib/init/rw@&|/live@g" /etc/init.d/umountfs
========================
is used to make umountfs skip unmounting /live.

My 2 cents.
Thanks.

Regards,
Steven.

--
Steven Shiau<steven _at_ nchc org tw>  <steven _at_ stevenshiau org>
National Center for High-performance Computing, Taiwan.
http://www.nchc.org.tw
Public Key Server PGP Key ID: 1024D/9762755A
Fingerprint: A2A1 08B7 C22C 3D06 34DB  F4BC 08B3 E3D7 9762 755A

--- a/scripts/config/120-umountfs
+++ a/scripts/config/120-umountfs
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+## live-config(7) - System Configuration Scripts
+## Copyright (C) 2006-2010 Daniel Baumann <daniel@debian.org>
+##
+## live-config comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+
+Umountfs ()
+{
+	# Checking if package is already configured
+	if [ ! -e /etc/init.d/umountfs ] || \
+	   [ -e /var/lib/live/config/umountfs ]
+	then
+		return
+	fi
+
+	echo -n " umountfs"
+
+	Configure_umountfs
+}
+
+Configure_umountfs ()
+{
+	sed -i -r -e "s@PROTECTED_MOUNTS=.*@PROTECTED_MOUNTS=\"\$\(sed -r -n '0,/^(\\\/[^ ]*|aufs|unionfs|unionfs-fuse\) \\\/ /p' /proc/mounts\)\"@g" /etc/init.d/umountfs
+	sed -i -r -e "s@\|/lib/init/rw@&|/live@g" /etc/init.d/umountfs
+
+	# Creating state file
+	touch /var/lib/live/config/umountfs
+}
+
+Umountfs

Reply to: