How to umount initrd?

Denys Vlasenko vda.linux at googlemail.com
Sun Nov 1 01:03:26 UTC 2009


On Friday 30 October 2009 12:37, Pan ruochen wrote:
> Hi All,
> 
> I am porting Linux. I desire the system to start up in the flowing steps:
> 1.  Kernel mount rootfs from initrd.
> 2.  Install the NTFL drivers.
> 3.  Mount the real filesystem which resides in NAND flash and change
> root from initrd to nand.
> 4.  Umount initrd to reclaim system memory.
> 
> All seem okay except step 4.
> Here is my linuxrc script:
> =====================================================================
> #!/bin/sh
> mkdir /sysroot
> mkdir /sysroot/dev
> mknod /sysroot/dev/console c 5 1
> mknod /sysroot/dev/null    c 1 3
> mknod /sysroot/dev/nftla   b 93 0
> mknod /sysroot/dev/nftla1  b 93 1
> cd sysroot
> exec <dev/console >dev/console 2>&1
> insmod /lib/modules/2.6.27.29/nftl.ko
> mount -t ext2 dev/nftla1 .
> cd /sysroot
> pivot_root . old_root
> umount -n /old_root

/sysroot/dev/console is still in use!

(I do not understand why do you create /sysroot/dev/* stuff at all)

> exec chroot . /sbin/init
> =====================================================================
> 
> I got an error as:
> can't umount /old_root: Device or resource busy

As expected.

My initrd does it like this:

...
mount <something> /new_root
mount -n -t ramfs none /new_root/dev
cp -dp /dev/console /dev/null /new_root/dev
cd /new_root
# making sure we dont keep /dev busy
exec <dev/console >dev/console 2>&1
# proc/ in new root is used here as a temp mountpoint for old root
pivot_root . proc
exec \
chroot . \
sh -c 'umount -n /proc; exec /bin/env - /sbin/init'


Note that I create /new_root/dev/* AFTER I mounted my to-be-new-root
filesystem. You do it before. Thus, your opened /sysroot/dev/console
is still on the old filesystem.
--
vda


More information about the busybox mailing list