How to Setup an openSUSE chroot
chroots provide an extremely useful way of running multiple Linux distros on a single computer without having to run them within a full virtual machine environment. Why would this be an advantage? Well, in my case, I’m performing builds of hundreds of packages for the Yocto Project, and I want to maximize performance by avoiding having to go through a virtualization layer to access my hard disks.
My goal was to create a minimal environment which closely matched what we’re running on some of our autobuilders, which happens to be openSUSE 11.2. It’s easy to set up Debian-based distributions within a chroot by using the debootstrap command, but openSUSE doesn’t have anything analagous to this AFAIK.
It turns out it’s pretty simple to use zypper, openSUSE’s command-line package management utility, to bootstrap an installation into an arbitrary sysroot that you can then use to pull in additional packages over the network. The only caveat is you have to create your initial chroot on an existing openSUSE machine where you have root privileges. Here’s how.
The first thing you’ll need to do is set up the most basic openSUSE package repository config within your sysroot. To create this in the /data/opensuse-11.2 directory, you’d do the following:
mkdir /data/opensuse-11.2
zypper --root /data/opensuse-11.2/ ar http://ftp.osuosl.org/pub/opensuse/distribution/11.2/repo/oss/ repo-oss
Next, you’ll need a /dev/zero device file within your sysroot, since some packages have post-install scripts which make use of it. You can create it manually, but I prefer to simply copy it from /dev:
sudo mkdir /data/opensuse-11.2/dev
sudo cp -a /dev/zero /data/opensuse-11.2/dev/
Presumably you’ll want to move this chroot onto another computer as soon as possible, so here I only install a few needed packages to get started (rpm, zypper, wget, and vim). An editor can be handy in case you need to edit a configuration file (in my case, to configure system-wide proxy settings in /etc/sysconfig/proxy):
sudo zypper --root /data/opensuse-11.2/ install rpm zypper wget vim
At this point you can now tar up the chroot and copy it over to your destination machine of choice. Keep in mind you’ll still need root privileges to tar it up properly:
cd /data
sudo tar cvjf opensuse-11.2.tar.bz2 opensuse-11.2
I use schroot to manage my chroots and highly recommend this little-known utility. It allows you to work within a chroot’ed environment but still have access to your home directory (or any other directory, if you configure it as a bind mount).
After having moved my chroot to its final destination, I added additional zypper repositories and followed the Yocto Project Quick Start Guide to install required build dependencies.
zypper ar http://download.opensuse.org/update/11.2 repo-update
zypper ar http://download.opensuse.org/repositories/security/openSUSE_11.2/ security
zypper ar http://download.opensuse.org/repositories/openSUSE:/Tools:/1.7/openSUSE_11.2/ tools
zypper refresh
zypper install python m4 make ...
From that point on, I could fire up a schroot session anytime I needed to perform builds within a minimal openSUSE 11.2 envrionment with no need to deal with virtualization environments or reboot into another OS.
April 7th, 2011 at 1:18 pm
Hello, some clarification/verification pls. This looks to me like an interesting way to create multi-boot (one OS at a time), each instance sharing the same kernel but otherwise completely different. Would like to verify this is different from products like Linux-VServer, and OpenVZ and FreeVPS which permit simultaneous running instances by sharing the kernel but virtualizing everything else.
May 10th, 2011 at 8:26 am
It is the same concept but with no kernel support to enforce any kind of security: http://en.wikipedia.org/wiki/Operating_system-level_virtualization
February 5th, 2016 at 6:52 pm
thanks for this, it still works with Tumbleweed snapshot from Jan 2016.
I wanted to try and run Skype in a chroot jail.
April 13th, 2017 at 6:00 pm
[…] found this handy guide on creating a OpenSuSE […]
December 11th, 2017 at 12:20 pm
Hi! thanks for the info. I used this as a starting point to install opensuse leap 42.3 with latest kde support. the scenario was installing an up-to-date opensuse in my ubuntu lts office machine. i need chroot because as this is a production workstation, i cant put it offline for any fraction of working hours. just a few comments to complete the scheme:
1) I installed latest 42.3 repos from opensuse repos list , https://en.opensuse.org/SDB:KDE_repositories
2) kernels had to be installed,
(chroot jail)$zypper install kernel-default kernel-desktop
3) initrd image had to be created manually,
(chroot jail)$mkinitrd
4) /etc/fstab had to be populated,
5)network had to be properly configured
these steps will give a working opensuse, with ttys only. Lots of configs are yet to be made but its basically a working system.