chroot(8) — Maintenance
NAME
chroot − Changes the root directory of a command
SYNOPSIS
/usr/sbin/chroot directory command
DESCRIPTION
Only root can use the chroot command. The chroot command changes the root directory from / to the specified directory when the command executes. (The command specified includes both the command name as well as any arguments.) Consequently, the root of any path (as indicated by the first / (slash) in the pathname) changes to directory and is always relative to the current root. Even if the chroot command is in effect, directory is relative to the current root of the running process.
Several programs may not operate properly after chroot executes. For example, the ls −l command fails to give user and group names if the current root location and the /etc/passwd file are on different file systems. You must ensure that all vital data files are present in the new root file system and that the relevant pathnames for the data files correspond to the new root file system.
Please note that the command specified cannot be in a shell script.
EXAMPLES
1.To run a subshell with another file system as the root, enter a command similar to the following. Note in this example, the file system is on the /dev/ra1a device and is mounted to /mnt/ra1a:
chroot /mnt/ra1a /sbin/sh
The command shown in the previous example specifies a change from the current root file system to the one mounted on /mnt/ra1a while /sbin/sh (which itself is relative to the new root file system) executes. When /bin/sh executes, the original root file system is inaccessible. The file system mounted on /mnt/ra1a must contain the standard directories of a root file system. In particular, the shell looks for commands in /sbin, /bin, and /usr/bin (among others) on the new root file system. Running the /sbin/sh command creates a subshell that runs as a separate process from the original shell. Press <Ctrl-d> to exit the subshell and return to the original shell. This restores the environment of the original shell, including the meanings of the current directory (.) and the root directory (/).
2.To run a command in another root file system and save the output on the initial root file system, enter a command similar to the following. Note in this example, the file system is on the /dev/ra1a device and is mounted to /mnt/ra1a:
chroot /mnt/ra1a /bin/cc -E /u/bob/prog.c > prep.out
The previous command runs the /bin/cc command with /mnt/ra1a as the specified root file system. It compiles the /mnt/ra1a/u/bob/prog.c file, reads the #include files from the /mnt/ra1a/usr/include directory, and puts the compiled text in the prep.out file on the initial root file system.
3.To create a file relative to the original root rather than the new one, use this syntax and enter:
chroot directory command > file
CAUTIONS
If special files in the new root have different major and minor device numbers than the initial root directory, it is possible to overwrite the file system.
FILES
/usr/sbin/chroot
Specifies the command path.