Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to setup a Linux system that runs from an LVM-formatted image file. After some tinkering with the initramfs and boot options I managed to make it up and running by mounting the host file system to /run/initramfs/host, losetuping the image to /dev/loop0 and making sure the kernel and udev detect the LVM (and the root LV) in there. So far so good.

The problem is that when shutting down (or rebooting, or …) the system neither the root file system nor the host are unmounted properly, because of a chicken-and-egg scenario: the root (or /oldroot, as it's referred to by the shutdown script) cannot be unmounted, because /oldroot/run/initramfs/host is still mounted, and the host cannot be unmounted, because doing so would make /oldroot inaccessible.

Unclean shutdowns aren't the end of the world, because both file systems are journaled, so during the next boot fsck simply replays the journals, but obviously clean shutdowns would be better.

So the question is: is it somehow possible to arrange the shutdown sequence (I can modify the shutdown script), or the bootup sequence (perhaps by moving the host mount point to a different place) so that both file systems can be cleanly unmounted?

share|improve this question
Why losetup under lvm? Lvm use dmsetup wich is a kind of more featured losetup. –  F. Hauri Jan 13 '13 at 16:55
See mount --move –  F. Hauri Jan 13 '13 at 16:57
@F.Hauri: losetup, because it's the first thing I thought of that turns a file into a block device. Also, the chicken-and-egg problem at hand is not really related to LVM, is it? –  Fanael Jan 13 '13 at 17:42
add comment

3 Answers

up vote 2 down vote accepted

In case somebody has the same problem:

All I needed was to move the mount point of the host file system to a place outside the root file system in the shutdown script (that's fine, because it runs in a tmpfs pivot root) before any unmounting takes place:

mount --move /oldroot/run/initramfs/host /host

This allows /oldroot to unmount cleanly. The host file system can be then unmounted with a simple

umount /host
share|improve this answer
Thanks for the report and welcome! –  F. Hauri Jan 13 '13 at 18:30
add comment

There is some linux trick to do this kind of work:

  • mount --move which let you swap filesystem on mount point
  • pivot_root which work with chroot for switch / root filesystem

Initialy, the feature's goal was:

  1. booting kernel with an initramdisk as root filesystem (reserving some RAM for uncompressed initrd).
  2. All needed modules and scripts to access real root device are initiated in this 1'st boot step. (This could contain network initialisation and network devices mounting)
  3. After preparing, checking real root device and mounting as a ready root filesytem. Running pivot_root (and chroot), so after operation, the ramdisk will become an unused ram disk mounted at /initrd.
  4. So from there, it is possible to umount /initrd and freeing memory.

Have a look at man mount and man pivot_root!

share|improve this answer
+1 for mount --move –  Fanael Jan 13 '13 at 18:16
As I don't know your hierarchy and not sure to clearly understand your goal, I can't offer a more detailed solution (than you could find in man mount ... and I hate to simply cut'n past from man pages) –  F. Hauri Jan 13 '13 at 18:25
That's okay, you pointed me in the right direction by mentioning mount --move. –  Fanael Jan 13 '13 at 18:27
Just for my comprehension: Why did you need to umount /old before umount /old/blah/host ?? –  F. Hauri Jan 13 '13 at 18:35
Because /old is actually (a part of) a file stored in /old/blah/host. –  Fanael Jan 13 '13 at 18:45
add comment

To mark a filesystem as cleanly unmounted without making the files on it unavailable, remount it as read-only:

mount -o remount,ro /mount/point

This can be done even if there are files open for reading, running executables, current directories or active mount points on that filesystem. Only files open for writing prevent remounting read-only.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.