Updated Tutorial: Debian GNU/kFreeBSD in a FreeBSD jail

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:

  1. Become root
    # su –
  2. Update your FreeBSD ports tree (if you don’t yet have sysutils/debootstrap)
    freebsd# portsnap fetch update
  3. Install the sysutils/debootstrap port
    freebsd# cd /usr/ports/sysutils/debootstrap
    freebsd# make install clean
    freebsd# rehash
  4. Create a directory for the jail, you may create this as a ZFS dataset, too.
    freebsd# mkdir -p /jail/debian
  5. Load necessary kernel modules:
    freebsd# kldload fdescfs linprocfs linsysfs tmpfs
    NOTE: Add these to /boot/loader.conf to run the jail on startup
  6. Create a Debian (squeeze) distribution in the directory using debootstrap
    freebsd# debootstrap squeeze /jail/debian http://cdn.debian.net/debian
  7. Unmount filesystems mounted by debootstrap:
    freebsd# umount /jail/debian/sys
    freebsd# umount /jail/debian/dev/fd /jail/debian/dev
    freebsd# umount /jail/debian/proc
  8. 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”
  9. 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.
  10. 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
  11. Run your new jail (the /etc/rc.jail script starts rsyslog, cron and sshd inside the jail)
    freebsd# /etc/rc.d/jail start debian
  12. 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
  13. Verify that you are under debian now:
    root@debian:/# uname
    GNU/kFreeBSD
  14. Adjust your debian mirror in /etc/apt/sources.list (base system /jail/debian/etc/apt/sources.list)
  15. Have fun with Debian GNU/kFreeBSD in a FreeBSD jail! (functionality may be limited)

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=""> <s> <strike> <strong>