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)
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
freebsd# rehash - 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_enable=”YES”
jail_list=”debian”
jail_debian_rootdir=”/jail/debian”
jail_debian_hostname=”debian.home”
jail_debian_ip=”127.0.0.1″
jail_debian_devfs_enable=”YES”
jail_debian_exec_start=”/etc/init.d/rc 3″
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:
freebsd# jls
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:
root@debian:/# uname
GNU/kFreeBSD - 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)