HOWTO: /dev file system in chroot-ed environment

5 July 2015 8:05 AM Centos 6, Linux , , , , ,

HOWTO: /dev file system in chroot-ed environment

Chroot is an operation that changes the apparent root directory for the current running process and their children. A program that is run in such a modified environment cannot access files and commands outside that environmental directory tree. This modified environment is called a chroot jail.

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.

 

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

Cr: https://cutecomputer.wordpress.com/2007/01/07/howto-dev-file-system-in-chroot-ed-environment/

Ref: http://help.directadmin.com/item.php?id=42