4

Preface: I've made a boot-image that boots up Debian/Ubuntu using SquashFS and aufs. The image contains a cleaned up debootstrap install, compressed into a squashfs image.

The squashfs image is considered the readonly part of my filesystem. The local harddrive is considered the writable part of my root filesystem.

All setup of the rootfs is done from initramfs which calls switch_root to boot-up Debian/Ubuntu. The rootfs itself is mounted using aufs on the squash image (ro) and the harddrive (rw).

When the initramfs is running, I check if the harddrive is cleanly unmounted. I make sure it's clean before I mount it by calling 'fsck -Cp' (I know, I shouldn't).

The Problem: The problem that I have, is that the writable part of my root filesystem is never unmounted properly, leaving it (eg, the hdd) in an unclean state.

The base of the problem is obviously that the hdd is in use by the aufs filesystem. The aufs filesystem is obviously in use by the rootfs. Next to that, I figure that the Debian/Ubuntu shutdown procedure must be modified to allow this.

What have I done so far: I have tried to shutdown by hand, by first going into runlevel 1, and forcing ro-remounts of the rootfs and the hdd, but the hdd is still never unmounted cleanly.

I also changed the way aufs is mounted by adding an option to create the xino file outside the harddrive mount. I never see the file being created, nor can I see any open files on the harddrive using lsof.

Last but not least, I added the harddrive to the fstab of the Ubuntu install to have it recognize it. Didn't change a thing when Debian/Ubuntu shuts down though :(

From the looks of it, I have created a "chicken and egg" problem, as I can't unmount the harddrive without first unmounting the root filesystem, which I need to unmount the harddrive lol.

I haven't got the faintest idea of what commands to run, in order to unmount it properly, so any help is very much appreciated.

1
  • 1
    Technically speaking this should have been migrated to serverfault, as the question is regarding aufs and the way it't used properly, and not Ubuntu or Debian in specific. I'm already working on images for Redhat, Suse and Slackware. Haven't started on Gentoo or others though. The idea behind it, is that it could be used in low memory/drivespace environments like the Raspberry Pi on which I'm testing it out...
    – djBo
    Aug 31, 2012 at 17:36

1 Answer 1

2

You can never unmount root filesystem, sorry -- no matter if you're using squashfs+aufs, or just plain ext2/ext3/ext4...

What you can do is remount it read-only, which is the same from data integrity standpoint. For regular filesystem:

mount -oremount,ro /
sync # initiate writing any pending writes to disk
sleep 5 # and give writes some time to finish.

note that aufs is somewhat different as you should make sure the rw-backing of it still writeable while aufs itself is being put read-only... for example, assuming /mnt/sq/rw is ext4 read-write part of your aufs "/" mount:

 cat /proc/mounts > /etc/mtab # may not be needed if your mtab is symlink or otherwise reflects real situation
 fuser -mv / # show debug of what is using this disk and blocking unmount/ro-remount, if anything
 auplink / flush 
 mount -oremount,noxino,noplink,ro /
 mount -oremount,sync /mnt/sq/rw
 mount -oremount,mod:/mnt/sq/rw=ro /
 mount -oremount,ro /mny/sq/rw
 sync
 sleep 5
 cat /proc/mounts
 dmesg
 sleep 300 # to give you time to read mounts/dmesg info
 halt -d -f

in production you obviously won't need debug info...

In short, you flush to disk and disable aufs features that require writing to ext4 overlay, then force ext4 itself to sync and go read-only, so it will be marked as cleanly unmounted next time you boot.

2
  • You have a very good answer, thanks. Problem is that nowadays in 2019 people switched from aufs to overlayfs and I do not see these options anymore. Maybe you can help with update of you answer for overlayfs? Dec 16, 2019 at 14:57
  • @MaxLapshin you should ask new question for that, so someone can hopefully answer Dec 16, 2019 at 21:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .