CHROOT(8,C) AIX Commands Reference CHROOT(8,C)
-------------------------------------------------------------------------------
chroot
PURPOSE
Changes the root directory of a command.
SYNTAX
chroot -- directory -- command --|
DESCRIPTION
Warning: If special files in the new root directory have different major and
minor device numbers than they have in the real root directory, it is possible
to overwrite the file system.
The chroot command can be used only by a user operating with superuser
authority (see "su"). If you have superuser authority, the chroot command
changes the root directory to the specified directory when executing command.
The first / (slash) in any path name changes to directory for the specified
command and any of its children. The chroot command simulates a call to the
setlocal with the process's current <LOCAL> alias. As a result, the alias is
re-evaluated within the new root directory.
Notice that:
chroot directory command > file
creates the file relative to the original root directory, not the new one.
The directory path name is always relative to the current root directory. Even
if a chroot command is in effect, directory is relative to the current root
directory of the running process.
Several programs may not operate properly after the chroot command runs. For
example, the command ls -l fails to give user and group names if the location
of the current root directory makes the /etc/passwd beyond reach. In addition,
utilities that depend on description files produced by the ctab command (see
page ctab-1) may fail altogether if these files are also not in the new root
file system. It is your responsibility to ensure that all vital data files are
present in the new root file system and that the path names accessing such
files are changed as necessary.
EXAMPLES
1. To run a subshell with another file system as the root:
Processed November 8, 1990 CHROOT(8,C) 1
CHROOT(8,C) AIX Commands Reference CHROOT(8,C)
chroot /diskette0 /bin/sh
This makes the directory name / refer to "/diskette0" for the duration of
the command "/bin/sh" It also makes the original root file system
inaccessible. The file system on "/diskette0" must contain the standard
directories of a root file system. In particular, the shell looks for
commands in /bin and /usr/bin on the "/diskette0" file system.
Running the command /bin/sh creates a subshell, which runs as a separate
process from your original shell. Press the END OF FILE (Ctrl-D) key to
end the subshell and go back to where you were in 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:
chroot /diskette0 /bin/cc -E /u/bob/prog.c >prep.out
This command runs the "/bin/cc" command with / referring to "/diskette0".
It saves the output in the file "prep.out", which is in the original root
file system.
This command runs also the C language preprocessor ("/bin/cc -E") on the
file "/diskette0/u/bob/prog.c", reading #include files from
/diskette0/usr/include, and putting the preprocessed text in "prep.out" on
the primary root file system.
RELATED INFORMATION
See the following commands: "cc," "cpp," and "sh, Rsh."
See chdir and chroot system calls in AIX Operating System Technical Reference.
Processed November 8, 1990 CHROOT(8,C) 2