In my last article about FOSDEM 2011 I wrote about visiting the Debian GNU/kFreeBSD presentation. What I was interested in - if it is possible to run this inside a FreeBSD jail or at least in a chroot. My results have been positive, so in this article I am providing a tutorial how to easily set up a Debian GNU/kFreeBSD jail on FreeBSD. Remember that the functionality may be limited.
Requirements: FreeBSD 8.1+ i386 or amd64, experience with FreeBSD and jail(8)
Saturday, 26. February 2011
Steps to reproduce:
- Become root
# su -
- Update your FreeBSD ports tree (if you don't yet have sysutils/debootstrap)
freebsd# portsnap fetch update
- Install the sysutils/debootstrap port
freebsd# cd /usr/ports/sysutils/debootstrap
freebsd# make install clean
- Create a directory for the jail, you may create this as a ZFS dataset, too.
freebsd# mkdir -p /jail/debian
- Load necessary kernel modules:
freebsd# kldload fdescfs linprocfs linsysfs tmpfs
NOTE: Add these to /boot/loader.conf to run the jail on startup
- Create a Debian (squeeze) distribution in the directory using debootstrap
freebsd# debootstrap squeeze /jail/debian http://cdn.debian.net/debian
- Unmount filesystems mounted by debootstrap:
freebsd# umount /jail/debian/sys
freebsd# umount /jail/debian/dev/fd /jail/debian/dev
freebsd# umount /jail/debian/proc
- Mount necessary filesystems:
freebsd# mount -t linprocfs linprocfs /jail/debian/proc
freebsd# mount -t linsysfs linsysfs /jail/debian/sys
freebsd# mount -t tmpfs tmpfs /jail/debian/lib/init/rw
NOTE: Add the filesystems to /etc/fstab to run the jail on startup, see "man fstab"
- Configure the jail in your /etc/rc.conf, you may follow this example:
jail_debian_flags="-l -u root"
Replace 127.0.0.1 with an IP address on your system and debian.home with your desired jail hostname.
- Edit /jail/debian/etc/resolv.conf or you may use your system resolv.conf, if you want:
freebsd# cp /etc/resolv.conf /jail/debian/etc/resolv.conf
- Run your new jail (the /etc/rc.jail script starts rsyslog, cron and sshd inside the jail)
freebsd# /etc/rc.d/jail start debian
- Use jls(8) to get the JID of your jail and jexec(8) to run /bin/bash inside:
JID IP Address Hostname Path
1 127.0.0.1 debian.home /jail/debian
freebsd# jexec 1 /bin/bash
- Verify that you are under debian now:
- Adjust your debian mirror in /etc/apt/sources.list (base system /jail/debian/etc/apt/sources.list)
- Have fun with Debian GNU/kFreeBSD in a FreeBSD jail! (functionality may be limited)
Display comments as (Linear | Threaded)
Wow, this is an excellent idea! If it can be automated as a port it would be a highlight for FreeBSD advocacy
You can probably do this with debootstrap instead of a prepared tarball. debootstrap fetches packages from official Debian archive and builds a directory structure with Debian userland. It doesn't depend on Debian-specific tools, so you should be able to run it on FreeBSD with relative ease.
#2 Robert Millan on 2011-02-26 20:04
Thank you for your idea, I have just added debootstrap to FreeBSD ports
Nice tutorial! I added link to http://wiki.freebsd.org/Jails Maybe it would be nice to have this article on FreeBSD Wiki site in similar way to "Running CentOS 5.5 in a Jail" http://wiki.freebsd.org/Image/Linux/CentOS55
#3 Miroslav Lachman on 2011-03-07 16:45
Since linuxulator isn't 64bit friendly, perhaps we should always force deboostrap to pull kFreeBSD-i386 regardless of the hw.machine_arch sysctl?
Debian GNU/kFreeBSD is not Linux, it uses FreeBSD, so we are running amd64 and i386 ...
Instead of placing the jail mounts in /etc/fstab, you can also create separate fstab for it and set jail_JAILNAME_fstab="/path/to/debian.fstab" which will get mounted whenever the jails started (and unmounted when stopped).
The author does not allow comments to this entry