Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / All-Topics

Debian 7 Wheezy Installation in FreeBSD 10 Jail

0.00/5 (No votes)
9 Jun 2017CPOL1 min read 6.3K  
I decided to collapse the multiple systems I have running various flavours of Linux and BSD into a single system. … Continue reading →

I decided to collapse the multiple systems I have running various flavours of Linux and BSD into a single system. For a long time, I had been using Windows Small Business Server. Well, I don’t really want to spend the money to upgrade to 2016 and since it appears Microsoft has abandoned its purist Unix roots by trading the tight and tidy SFU (Interix) for the wildly fat Ubuntu and a Linux ABI. In the advent of this change, I figured I would flip back to FreeBSD, which in my not-so-humble opinion is still the closest thing to Unix you can get. In fact, it actually derives its original sources from none other than Research UNIX, and while it’s wildly more advanced, the distribution holds its origin close to its heart.

Either way, the task: Support the ever growing number of ‘Appliance’ installs on top of FreeBSD. In this first iteration, I have found several guides and worked through getting Debian 7 functional in a FreeBSD 10-STABLE Jail. No guarantees on stability, but I’ll update this if I come across any oddities. This task was performed on FreeBSD 10.3.

Load Linux Compat Kernel Modules…

root@host:/ # kldload fdescfs
root@host:/ # kldload linprocfs
root@host:/ # kldload linsysfs
root@host:/ # kldload tmpfs

Make this persistent upon reboot by appending the following to ‘/boot/loader.conf’ on the FreeBSD host.

# ENABLE LINUX KERNEL FUNCTIONALITY #
fdescfs_load = "YES"
linprocfs_load = "YES"
linsysfs_load = "YES"
tmpfs_load = "YES"

Install ‘debootstrap’ and ‘perl5’ packages:

root@host:/ # pkg install debootstrap perl5

Create ZFS volume and mountpoint:

root@host:/ # zfs create zpool/usr/jail/.debian-7

Stage the volume:

root@host:/ # debootstrap wheezy /usr/jail/.debian-7 http://cdn.debian.net/debian

Snapshot the Clean copy:

root@host:/ # zfs snapshot zpool/usr/jail/.debian-7@clean

Configure the Jail: ‘/etc/jail.conf':

# DEFAULT PARAMETERS
#
host.hostname = "$name";
path = "/usr/jail/$name";

mount.devfs;
mount.fstab = "/etc/fstab.$name";

allow.nomount;

exec.prestart = "";
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.poststop = "";
exec.clean;


#####################################
# TEMPLATE
#
debian-7 {

  path = "/usr/jail/.debian-7";
  mount.fstab = "/etc/fstab.debian-7";

  interface = "lo0";
  ip4.addr = 192.0.2.20;

  exec.start = "/etc/init.d/rc 3";
  exec.stop = "/etc/init.d/rc 0";

  allow.mount;
  mount.devfs;
}


#####################################
# PRODUCTION

# TEST DEBIAN JAIL
deb-test {

  interface = "lo0";
  ip4.addr = 192.0.2.201;

}

Then edit ‘/usr/jails/debian/etc/fstab.debian-7’:

sys         /usr/jail/.debian-7/sys       linsysfs   rw                 0 0
proc        /usr/jail/.debian-7/proc      linprocfs  rw                 0 0
tmpfs       /usr/jail/.debian-7/run       tmpfs      rw,noexec,nosuid   0 0

# ALLOWS SHARING OF THE SRC DIRECTORY FROM FREEBSD HOST.
/usr/src    /usr/jail/.debian-7/usr/src   nullfs     ro                 0 0

Create master.passwd file as FreeBSD doesn’t use shadow file and update ‘/etc/passwd in Jail’:

root:/ # cat /usr/jail/.debian-7/etc/passwd | 
sed -r 's/(:[x|*]:)([0-9]+:[0-9]+:)/:*:\2:0:0:/g' > 
/usr/jail/.debian-7/etc/master.passwd
root:/ # pwd_mkdb -p -d /usr/jail/.debian-7/etc /usr/jail/.debian-7/etc/master.passwd

Start the jail:

root:/ # service jail start debian

Show Jail Status:

root:/ # jls
   JID  IP Address      Hostname                      Path
    24  192.168.0.201   debian-7                      /usr/jail/.debian-7


root:/ # df -h
Filesystem                         Size    Used   Avail Capacity  Mounted on
zroot/ROOT/default                  39G    3.5G     36G     9%    /
devfs                              1.0K    1.0K      0B   100%    /dev
zroot/tmp                           36G     16M     36G     0%    /tmp
zroot/usr/ports                     37G    940M     36G     2%    /usr/ports
zroot/usr/src                       37G    547M     36G     1%    /usr/src
zroot/var/audit                     36G     96K     36G     0%    /var/audit
zroot/var/crash                     36G     96K     36G     0%    /var/crash
zroot/var/log                       36G    904K     36G     0%    /var/log
zroot/var/mail                      36G    180K     36G     0%    /var/mail
zroot/var/tmp                       36G    116K     36G     0%    /var/tmp
zpool/usr/home                     3.5T    312G    3.2T     9%    /usr/home
zpool/usr/jail                     3.2T     84M    3.2T     0%    /usr/jail
zpool/usr/jail/.debian-7           3.2T    146M    3.2T     0%    /usr/jail/.debian-7
linsysfs                           4.0K    4.0K      0B   100%    /usr/jail/.debian-7/sys
linprocfs                          4.0K    4.0K      0B   100%    /usr/jail/.debian-7/proc
tmpfs                               37G     16K     37G     0%    /usr/jail/.debian-7/run
devfs                              1.0K    1.0K      0B   100%    /usr/jail/.debian-7/dev

Note that the items displayed may be different depending on your system.
Configure our Debian/kFreeBSD

Enter the jail:

root@host:/ # jexec debian-7 /bin/bash
root@debian-7:/ #

Complete staging and set root password:

root@debian-7:/ # dpkg-reconfigure tzdata
root@debian-7:/ # apt-get update
root@debian-7:/ # apt-get install local
root@debian-7:/ # dpkg-reconfigure local
root@debian-7:/ # passwd
password:
Retype new UNIX password:
passwd: password updated successfully
root@debian-7:/ # exit
root@host:/ #

Take Snapshot of host and clone new Jail from snapshot:

root@host:/ # zfs snapshot zpool/usr/jail/.debian-7@p0
root@host:/ # zfs clone zpool/usr/jail/.debian-7@p0 zpool/usr/jail/deb-test
root@host:/ # cp /etc/fstab.debian-7 /etc/fstab.deb-test
root@host:/ # jexec deb-test /bin/bash
root@deb-test:/ # exit /bin/bash
root@host:/ #

Special thanks to the author of debian-gnukfreebsd-wheezy-in-a-freebsd-10-jail.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)