A chroot gives you a separate root filesystem that you can enter from an existing openSUSE or SLES host without booting another machine. It is useful when you need a clean SUSE userland for package work, recovery tasks, or quick testing while keeping the host installation unchanged.

For a brand-new chroot directory, use

zypper --installroot

instead of plain

zypper --root

. The

--installroot

mode installs packages into the target directory while reusing the host's configured repositories, which makes it the practical way to bootstrap a fresh SUSE chroot.

After the base system is in place, mount proc, dev, and sys, copy the host repository and DNS settings if you want package management inside the chroot, and enter it with chroot. When you finish, unmount the bind mounts so the host does not keep stale references to the chroot tree.

Steps to build a chroot environment in openSUSE and SLES:

  1. Refresh the host repositories and confirm the minimal_base pattern is available.
    $ sudo zypper refresh
    $ zypper search -t pattern minimal_base
    Loading repository data...
    Reading installed packages...
    
    S  | Name         | Summary                | Type
    ---+--------------+------------------------+--------
       | minimal_base | Minimal Appliance Base | pattern

    On SLES, the host must already be registered and have the required modules enabled because

    --installroot

    reuses the host repository configuration.

  2. Create the directory that will hold the new root filesystem.
    $ sudo mkdir -p /mnt/chroot
  3. Install a minimal SUSE userland into the new directory.
    $ sudo zypper -n --gpg-auto-import-keys --installroot /mnt/chroot in --no-recommends pattern:minimal_base zypper
    Loading repository data...
    Reading installed packages...
    Resolving package dependencies...
    
    The following NEW packages are going to be installed:
      bash filesystem glibc patterns-base-minimal_base zypper ...
    
    The following NEW pattern is going to be installed:
      minimal_base
    
    ...
    Running post-transaction scripts [...done]

    This installs zypper into the chroot as well, so you can manage packages after entering it. If you only need file access or recovery work, you can omit zypper from this command.

  4. Mount the proc filesystem inside the chroot.
    $ sudo mount -t proc proc /mnt/chroot/proc
  5. Bind the host dev tree into the chroot.
    $ sudo mount --rbind /dev /mnt/chroot/dev
  6. Bind the host sys tree into the chroot.
    $ sudo mount --rbind /sys /mnt/chroot/sys
  7. Copy the host repository definitions into the chroot if you want to use zypper inside it.
    $ sudo mkdir -p /mnt/chroot/etc/zypp/repos.d
    $ sudo cp -a /etc/zypp/repos.d/. /mnt/chroot/etc/zypp/repos.d/
    --installroot

    uses the host repositories during bootstrap, but it does not populate repos.d inside the new root.

  8. Copy the host DNS resolver configuration if the chroot needs network access.
    $ sudo cp -L /etc/resolv.conf /mnt/chroot/etc/resolv.conf

    Skip this step if the chroot will stay offline or if you manage resolv.conf another way inside the chroot.

  9. Enter the chroot and initialize the shell environment.
    $ sudo chroot /mnt/chroot /bin/bash
    # source /etc/profile
    # export PS1="(chroot) ${PS1}"
  10. Confirm that package management is available inside the chroot.
    # zypper lr
    Repository priorities are without effect. All enabled repositories share the same priority.
    
    # | Alias   | Name   | Enabled | GPG Check | Refresh
    --+---------+--------+---------+-----------+--------
    1 | ...     | ...    | Yes     | ( p) Yes  | Yes

    The running kernel is still the host kernel. chroot isolates the root filesystem, not the kernel.

  11. Install or test the packages you need inside the chroot.
    # zypper in gcc make
  12. Leave the chroot when your work is complete.
    # exit
  13. Unmount the sys bind tree.
    $ sudo umount -R /mnt/chroot/sys
  14. Unmount the dev bind tree.
    $ sudo umount -R /mnt/chroot/dev
  15. Unmount the proc filesystem.
    $ sudo umount /mnt/chroot/proc