How to properly unmount AUFS filesystem used as root filesystem

2

2

I have an embedded system that has an (always) read-only root filesystem with a writeable filesystem overlayed on top of it. However, I'm having problems on system shutdown unmounting or remounting it as a read-only filesystem (which results in things like orphan i-nodes and such when it's checked on the next boot).

# mount -o remount,ro /initrd/root-overlay/
mount: mounting /dev/mmcblk0p7 on /initrd/root-overlay failed: Device or resource busy

The system boots up with an initrd image that performs the filesystem mounting, before continuing on with the boot. We do this in the initrd's linuxrc file because sometimes we want to select another partition as the root filesystem.

Here is the linuxrc script that's setting up the root partition and its overlay:

echo "Mounting /proc..."
mount -t proc none /proc

echo "Mounting /dev/mmcblk0p5 on /ro-root..."
mkdir -p /ro-root
mount -o ro -t ext4 /dev/mmcblk0p5 /ro-root

echo "Mounting /dev/mmcblk0p7 on /root-overlay..."
mkdir -p /root-overlay
mount -o rw -t ext4 /dev/mmcblk0p7 /root-overlay

echo "Creating union of /ro-root and /root-overlay on /realroot..."
mkdir -p /real-root
mount -t aufs -o br:/root-overlay=rw:/ro-root=ro none /real-root

echo "Pivoting to /real-root... initrd will be at /initrd."
cd /real-root
mkdir -p initrd
pivot_root . initrd

echo "Unmounting /proc..."
umount /initrd/proc
echo "Unmounting /dev..."
umount /initrd/dev

echo "Executing real init..."
exec /sbin/init

I'm guessing that there might be special syntax that I can use with the mount command (passed via the -o option) to accomplish this, but I don't know what that is.

I'm open to alternate ways of performing the initial mounting of the filesystems, if it's necessary.

Steve

Posted 2015-04-20T21:32:09.737

Reputation: 518

Answers

1

Try this. It unmounts all aufs mounted:

umount -l $(grep 'aufs' /proc/mounts | awk '{print$2}' | sort -r)

user3240746

Posted 2015-04-20T21:32:09.737

Reputation: 11