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.
$ 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.
$ sudo mkdir -p /mnt/chroot
$ 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 ##### snipped ##### The following NEW pattern is going to be installed: minimal_base ##### snipped ##### 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.
$ sudo mount -t proc proc /mnt/chroot/proc
$ sudo mount --rbind /dev /mnt/chroot/dev
$ sudo mount --rbind /sys /mnt/chroot/sys
$ 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.
$ 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.
$ sudo chroot /mnt/chroot /bin/bash
# source /etc/profile
# export PS1="(chroot) ${PS1}"
# zypper lr # | Alias | Name | Enabled | GPG Check | Refresh --+----------+----------+---------+-----------+-------- 1 | repo-oss | repo-oss | Yes | (r ) Yes | Yes ##### snipped #####
The running kernel is still the host kernel. chroot isolates the root filesystem, not the kernel.
# zypper in gcc make
# exit
$ sudo umount -R /mnt/chroot/sys
$ sudo umount -R /mnt/chroot/dev
$ sudo umount /mnt/chroot/proc