Related Posts:

HOWTO: /dev file system in chroot-ed environment

Delicious

As a a traditional UNIX system, Linux systems also followed the static device nodes in /dev directory. During the installation process, /dev directory is filled with most commonly used device files. But modern linux system is not so. While booting the system, the the device nodes are created for the available (only) hardware devices. This makes the /dev not cluttered too much with mostly unused nodes.

But this behaviour results in absence of /dev/<nodes> in chroot-ed environment. This will result in failure of many commands based on /dev/<nodes>. The following is an example of such failure in a chroot-ed environment. In this example, a user tries to change root passwd of chroot-ed system.

dreambox:/# passwd
Changing password for root.
New Password:
Bad password: too simple
Reenter New Password:
Cannot open /dev/urandom for reading: No such file or directory
Cannot create salt for blowfish crypt
Error: Password NOT changed.

passwd: Authentication token manipulation error
dreambox:/#

Here is how to solve this issue:

1. Mount new root partition in a directory. (e.g.): # mount /dev/hda2 /mnt/newroot

2. Bind the current /dev with would-be root. (e.g.): # mount –bind /dev /mnt/newroot/dev

3. changing the root file system. (e.g.): # chroot /mnt/newroot /bin/bash

That is it. This will be useful during rescue process of a system.

Follow-up

RSSBlack God - RSS   Print

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...


More posts in this category


7 Responses to “HOWTO: /dev file system in chroot-ed environment”

  1. This isn’t quite correct, at least for my distro (ubuntu). the command at step 2 is:

    mount -o bind /dev /location/of/mountpoint/dev

  2. Thanks toolman for pointing out the syntax error. It is a typo mistake. “bind” should be preceded with two hyphens as shown below:

    # mount –bind /dev /mnt/newroot/dev

  3. In some system mount command does not accept “–bind” option, it accepts “-o bind” instead.

  4. Thanks for this bind option in rescue system.

    In openSuse 10.2 the “-o bind” option works.

    Rescue:~ # mount -o rw /dev/rootpartion /mnt/newroot
    Rescue:~ # mount -o bind /dev /mnt/newroot/dev

    Then

    Rescue:~ # chroot /mnt/newroot

    Then one can change root password etc.

    Rescue:/ # passwd root

  5. drsputnik0815 on July 30th, 2007 at 2:43 pm

    Thank You – if got the same problem, and you help me!!!!!

    it works fine

  6. Well it works, many thanks

  7. Thanks a lot, works great!!

Leave a Reply

Subscribe without commenting