08

September
2012

initramfs pivot_root solution

In the previous post I discussed initramfs, its pros and cons. The worst problem was the fact it doesn't support pivot_root, which seems to be essential for clean shutdown of Slax (or a live distro in general) since it is used to switch between ramfs root and union root (back and forth, once during the boot, and finally switching back during shutdown).

I wasn't able to pivot_root back to initramfs durnig shutdown of the live OS, thus wasn't able to unmount the media Slax is running from. Fortunately I found a workaround, which completely eliminates the need for the hack mentioned in previous post.

It's relatively simple, yet not obvious. Immediately after the kernel is booted and init is started in the initramfs root, we make a directory /m (or something) and copy the current initramfs filesystem to it. This doubles RAM usage for a while, but don't worry, since the next step we do is to switch root to /m. This does two things. First, it frees all the memory used by initramfs, and second it simply restarts the init process from a mounted filesystem. And as soon as root is mounted, the real startup procedures of LiveKit can be started (mounting union, and so on), and finally pivot_root is now magically available again. Voila!

User comments