1

I would like to chroot to another rootfs and unmount the former one so, after mounting a SD card containing a rootfs (on /mnt/disk/) and killing almost every process, I tried to run:

umount /tmp
mount --move /proc /mnt/disk/proc
mount --move /sys /mnt/disk/sys

and then, mount --move /dev /mnt/disk/dev which fails with the error message:

mount: mounting /dev/ on /mnt/disk/dev failed: No such file or directory


Some more information:

  • I also tried umount /dev giving

    umount: can't umount /dev/: Invalid argument
    # (same error with /dev/root)

  • The former rootfs is on a NAND partition (JFFS2)

  • /proc/cmdline contains:

    root=/dev/mtdblock3

  • mount -t jffs2 /dev/mtdblock3 /mnt/disk/dev works (mounts the former root) Could it be related to a filesystem conflict between the SD card and the root partition ?

  • cat /mnt/disk/proc/mounts

    rootfs / rootfs rw 0 0
    /dev/root / jffs2 rw 0 0
    /proc /mnt/disk/proc proc rw 0 0
    /sys /mnt/disk/sys sysfs rw 0 0
    /dev/mmcblk0p0 /mnt/disk ext2 rw,errors=continue 0 0

  • Kernel: 2.6.29.4

  • busybox: 1.16.1
2
# cat /mnt/disk/proc/mounts
rootfs / rootfs rw 0 0
/dev/root / jffs2 rw 0 0
/proc /mnt/disk/proc proc rw 0 0
/sys /mnt/disk/sys sysfs rw 0 0
/dev/mmcblk0p0 /mnt/disk ext2 rw,errors=continue 0 0

umount /dev: Invalid argument

mount: mounting /dev/ on /mnt/disk/dev failed: No such file or directory

There is no filesystem mounted at /dev, therefore you cannot unmount it or move it. That is what these error messages mean. (Possibly busybox mount uses more generic error messages than its heavyweight counterpart).


If the target /dev/ isn't going to have the device nodes you need, hopefully you have a MAKEDEV in there you can use.

If you try copying them from the original /dev/ using cp -a, there's a risk that the UIDs will not match the target rootfs, and hence permissions won't work as desired for non-root users. (Less secure or "so secure it doesn't work").

  • ok, unmounting /dev doesn't make sense but why cannot I unmount /dev/mtdblock3 ? (also triggers an invalid argument error but if I mount it at a random location I can successfully run umount /dev/mtdblock3). [/dev/root does not exist, that's why I'm focusing on /dev/mtdblock3 shown by proc/cmdline.] – Zermingore Aug 30 '16 at 14:22
  • You can't unmount / because lol. (You're using it. Although from that error message, it sounds like it's special-cased as well). chroot doesn't change that. I'm pretty sure you can't unmount implicitly, and that's a terrible idea anyway. Close resources explicitly in order to receive errors. The solution you're looking for was created for old-style initrds (initial ramdisks). Use pivot_root – sourcejedi Aug 30 '16 at 15:47
  • Sorry I meant I cannot unmount my old root from the new. (pivot_root <new_root> <old_root> and then umount /old_root/dev/mtdblock3) – Zermingore Aug 30 '16 at 15:51
  • that is not the command sequence documented in pivot_root(8). Open a new question (or edit this one) to specify unambiguously what you have tried and what the result was. – sourcejedi Aug 30 '16 at 16:51
  • Actually, I opened another question about pivot_root() earlier and then opened this one to solve it. As you perfectly answered the question (how to umount /dev playing with chroot), I think we agree that this question is closed. – Zermingore Aug 31 '16 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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