GNU/Linux Manually changing root in a directory


Example

  1. Ensure you met all requirements, as per Requirements

  2. Mount the temporary API filesystems:

    cd /location/of/new/root
    mount -t proc proc proc/
    mount --rbind /sys sys/
    mount --rbind /dev dev/
    mount --rbind /run run/ (optionally)
    
  1. If you need to use an internet connection in the chroot environment, copy over the DNS details:

    cp /etc/resolv.conf etc/resolv.conf
    
  2. Change root into /location/of/new/root, specifying the shell (/bin/bash in this example):

    chroot /location/of/new/root /bin/bash
    
  3. After chrooting it may be necessary to load the local bash configuration:

    source /etc/profile
    source ~/.bashrc
    
  4. Optionally, create a unique prompt to be able to differentiate your chroot environment:

    export PS1="(chroot) $PS1"
    
  5. When finished with the chroot, you can exit it via:

    exit
    
  6. Unmount the temporary file systems:

    cd /
    umount --recursive /location/of/new/root