Home arrow Latest Tutorials arrow Creating a FreeBSD Jail
Creating a FreeBSD Jail PDF
Saturday, 20 March 2010

FreeBSD have a neat and very useful feature of separating different 'virtual-like' machines with Jail. In fact those machines are not emulated in any virtualized solution, but are FreeBSD files and directories organized separately like different machines, on the same machine, sharing the same CPU and memory.

This tutorial is work in progress...

 We will use a small script that will build our files for the jail (an entire FreeBSD minimal system):

  #!/bin/sh
  D=/home/virtual/machine1
  cd /usr/src
  mkdir -p $D
  make world DESTDIR=$D
  make distribution DESTDIR=$D
  mount -t devfs devfs $D/dev

In this example /home/virtual/machine1 is the path where the system for machine1 jail will be installed.

Add in rc.conf the following lines:

  # add to /etc/rc.conf
jail_enable="YES"
jail_list="machine1"             #list of machines separated by space

jail_machine1_rootdir="/usr/home/virtual/machine1"
jail_machine1_hostname="machine.example.com"
jail_machine1_ip="10.0.0.10"
jail_machine1_devfs_enable="YES"
jail_machine1_devfs_ruleset="machine1_ruleset"



Tips
-------

To list jails use:   jls
To connect to a jail:   jexec 2 /bin/csh      # (where 2 is second jail. Use jls to list jails and found jail ID):
Start a jail: /etc/rc.d/jail start machine1       # (machine1 is configured in rc.conf)

Mount /usr/ports to a jail in order to install ports:
mkdir /home/virtual/machine1/usr/ports
mount_nullfs /usr/ports/ /home/virtual/machine1/usr/ports



Last Updated ( Wednesday, 27 April 2011 )
 
< Prev   Next >

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?