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!
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
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
/devand 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.