Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

chroot

Run a command (default: a shell) with another folder as the root / — the key step to repair an installed system from a rescue shell.

Niveau
RHCSA-examen
Groep
Systeeminformatie
Root nodig
Ja
Pakket
coreutils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

After chroot /mnt/sysroot, commands see /mnt/sysroot as /: they use the installed system's programs, config and package database. That is how you reset a password with rd.break, reinstall GRUB or rebuild the initramfs from a rescue disk. For tools like grub2-install or dracut, /proc, /sys, /dev and /run should be mounted inside first (the RHEL rescue mode does this for you).

chroot is not a security boundary; use containers for isolation.

Zo schrijf je het

chroot [OPTION]... NEWROOT [COMMAND [ARGUMENT]...]

Opties 6

Meest gebruikt

NEWROOT
The folder that becomes the new /.
--userspec=USER:GROUP
Run as this user and group.
--groups=G_LIST
Extra groups.
--skip-chdir
Do not change the working folder to /.
--help
Show help.
--version
Show the version.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Enter the installed system from rd.break

    mount -o remount,rw /sysroot
    chroot /sysroot

    Now passwd works on the real /etc/shadow.

  2. 2From the rescue disk

    chroot /mnt/sysroot

    The rescue mode mounted the system there.

  3. 3Mount the special file systems by hand

    for d in proc sys dev run; do mount --rbind /$d /mnt/sysroot/$d; done
    chroot /mnt/sysroot

    Needed when you mounted the root yourself.

  4. 4Run one command

    chroot /mnt/sysroot dracut -f --regenerate-all

    Without an interactive shell.

  5. 5Reinstall GRUB from rescue

    chroot /mnt/sysroot grub2-install /dev/vda

    BIOS systems.

  6. 6Check packages of the installed system

    chroot /mnt/sysroot rpm -qa | grep kernel

    The installed kernels, not those of the ISO.

  7. 7As another user

    chroot --userspec=lisa:lisa /mnt/sysroot /bin/bash

    Test user rights inside.

  8. 8Leave the chroot

    exit

    Back to the rescue shell.

  9. 9Is my shell in a chroot?

    ls -di /
    2 /

    An inode number other than 2 (or 128 on btrfs) often means a chroot.

  10. 10Do not use it for security

    podman run --rm -it registry.access.redhat.com/ubi10/ubi bash

    Containers isolate with namespaces and SELinux; chroot does not.

Exitcodes

125chroot itself failed.
126The command could not be run.
127The command was not found.
0Otherwise the exit status of the command.