LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

chroot

Change the root directory for a command

TLDR

Run a command with a different root directory
$ sudo chroot [path/to/new_root] [command]
copy
Run an interactive shell in the new root
$ sudo chroot [path/to/new_root]
copy
Specify a custom shell to run
$ sudo chroot [path/to/new_root] /bin/bash
copy
Specify user and group for the command
$ sudo chroot --userspec=[user:group] [path/to/new_root] [command]
copy
Change to a specific directory after chrooting
$ sudo chroot [path/to/new_root] /bin/sh -c "cd /home && ls"
copy

SYNOPSIS

chroot [OPTION] NEWROOT [COMMAND [ARG]...]

DESCRIPTION

chroot changes the root directory of the calling process to the specified path and runs a command within that environment. All pathname lookups starting with / will be relative to the new root.If no command is specified, chroot runs the shell from the SHELL environment variable or defaults to /bin/sh.The new root directory must contain all necessary files, libraries, and device nodes required by the command being executed.

PARAMETERS

NEWROOT

The directory to use as the new root filesystem
COMMAND
Command to run in the chroot environment
ARG
Arguments to pass to the command
--userspec=USER:GROUP
Specify user and group (name or ID) to run as
--groups=GROUPS
Specify supplementary groups
--skip-chdir
Do not change working directory to /

INSTALL

sudo apt install coreutils
copy
sudo dnf install coreutils
copy
sudo pacman -S coreutils
copy
sudo apk add coreutils
copy
sudo zypper install coreutils
copy
brew install coreutils
copy
nix profile install nixpkgs#coreutils
copy

CAVEATS

Requires root privileges or CAP_SYS_CHROOT capability. Not designed for security sandboxing—privileged users can escape by creating directories and using relative paths. Open file descriptors may provide access outside the chroot.The new root must contain essential files: /bin/sh or the specified command, required shared libraries (check with ldd), and device nodes like /dev/null if needed.

HISTORY

The chroot system call originated in Version 7 Unix (1979) at Bell Labs. It was initially used for building and testing new system versions. The GNU coreutils version provides the standard command-line interface on Linux systems.

SEE ALSO

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid