Using osc build to make a jail on openSUSE

Before I start let me say that there may be easier or more direct ways to do this.  This has the advantage of being pretty easy for me to do.  I’m not going to discuss why you might want to do this, or what a jail is, etc..

You can get the most recent osc and build tools from the openSUSE:Tools repository.  You will also need an account on the build service.

Create an empty directory
mkdir jail/

Go into that directory and create a dummy RPM .spec file
cd jail/
vim jail.spec

Name:           jail
Version:        0
Release:        0
Summary:        Jail
License:        Jail
Group:          Jail
BuildRequires:  vim gdb glib2-devel zypper
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description

%prep

%build

%install

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root)

%changelog

The BuildRequires: tag is where you specify which packages you want installed in your jail, what I have listed there is just an example.

Also create an empty .osc directory (this prevents an ugly bug where the jail tries to delete itself)
mkdir .osc/

You’ll need to be logged in to OBS if you aren’t already
osc ls
Enter your credentials at the prompts

If for some reason that didn’t work you may need to put your password into your .oscrc file
vim ~/.oscrc
Toward the bottom…

[https://api.opensuse.org]
user=<YOUR USERNAME>
pass=<YOUR PASSWORD>

If your password changed you may need to delete any lines that say passx=<GARBAGE>, or manipulate your GNOME Keyring.

Now you should be ready to build a jail

osc build --local-package --root=</path/to/new/jail> --alternative-project=openSUSE:<VERSION> <ARCH>

<VERSION> is, for example, 11.2
<ARCH> is only needed if you want a different arch (i586 on an x86_64 machine)
</path/to/new/jail> is where you want the tool to put your jail (not the directory you’re in!), I use /var/tmp/jail
You may be prompted for your root password
When the jail is built (assuming it worked) it will fail complaining about an empty package, ignore that and get on with your life: you only wanted a jail, not a package.

At this point you can chroot into your jail
sudo chroot /path/to/new/jail
or if you are changing architectures…
sudo linux32 chroot /path/to/new/jail

Yay, you’re done!

4 thoughts on “Using osc build to make a jail on openSUSE

  1. That’s somehow suboptimal for 2 reasons:

    1. with osc you always get the minimal build env installed as well.

    2. it’s much easier with plain zypper:

    zypper -R /chail/postfix -D /etc/zypp/repos.d in postfix

    installs postfix & it’s deps into /chail/postfix. OTOH it still installs quite some stuff one doesn’t need.

    JFYI ;)

  2. I secretly hoped someone would chime in with an easier way. Thank you!

    Unfortunately the zypper approach seems to only work for very simple cases. For example it will not create any entries in /dev and this will cause a number of packages to fail to install. Also zypper doesn’t install things in the right order so users and groups are not created early and rpm re-owns files in packages if the owner / group can’t be found. You could script around these problems but eventually you’d realize that osc build already scripted around them for you.

  3. Wow I wonder if this is worth using as the quickest way to get an LXC container?

    For a container, we usually want an entire functioning system, minimal as possible, but not for example any kernel or modules or grub or udev, but do want at least a partly populated /dev.

    And of course in the case of LXC, containers that aren’t full systems but just specific apps or services are also part of the defined design goal. Perhaps this osc trick is very close to whats needed for those kinds of containers at least.

    For full system LXC containers, currently I use
    zypper -R $CR ar -f http://host/…/repo/oss/ oss
    zypper -R $CR in -lt pattern base

    Preceded and followed by several manual tweaks.
    (Which I wrote up at http://en.opensuse.org/LXC)

    It works but it’s a drag where several things must be done manually and remembered and gotten just right every time, manually… OpenVZ web site has template filesystem tars already hand crafted but that’s cheating, not solving the problem, merely making someone else (vs. a tool) do the work.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>