Project

General

Profile

Feature #809

Updated by Daniel Curtis almost 8 years ago

This is a guide on how I setup CentOS 6 in a jail on FreeBSD 10.2. 

 h2. Prepare the Environment 

 * Make sure the system is up to date: 
 <pre> 
 pkg update && pkg upgrade 
 </pre> 

 * Load the necessary kernel modules: 
 <pre> 
 kldload linux fdescfs linprocfs linsysfs tmpfs 
 </pre> 

 * Set the linux version compatibility: 
 <pre> 
 echo "compat.linux.osrelease=2.6.18" >> /etc/sysctl.conf 
 sysctl compat.linux.osrelease=2.6.18 
 </pre> 

 * Install the centos linux base: 
 <pre> 
 pkg install linux_base-c6 
 </pre> 

 h2. Create the CentOS Jail 

 * Download the precreated centos filesystem: 
 <pre> 
 fetch http://download.openvz.org/template/precreated/centos-6-x86.tar.gz 
 </pre> 

 * Create the centos jail directory: 
 <pre> 
 mkdir /usr/jails/centos6.example.com 
 </pre> 

 * Unpack the centos filesystem into the centos6.example.com jail folder: 
 <pre> 
 tar xf centos-6-x86.tar.gz -C /usr/jails/centos6.example.com 
 </pre> 

 * Mount the necessary virtual file systems into the jail’s root directory: 
 <pre> 
 mount -t linprocfs /usr/jails/centos6.example.com/linprocfs /usr/jails/centos6.example.com/proc 
 mount -t linsysfs /usr/jails/centos6.example.com/linsysfs /usr/jails/centos6.example.com/sys   
 mount -t devfs /usr/jails/centos6.example.com/devfs /usr/jails/centos6.example.com/dev 
 </pre> 

 * Configure the jail in /etc/jail.conf: /etc/rc.conf: 
 <pre> 
 vi /etc/jail.conf /etc/rc.conf 
 </pre> 
 #* And add the following to the end of the file: 
 <pre> 
 centos6 { 
   path     = /usr/jails/centos6.example.com; 
   mount.devfs; 
   mount.fdescfs; 
   mount.procfs; 
   host.hostname = centos6.example.com; 
   ip4.addr = 192.168.1.202; 
   interface = em0; 
   exec.start = "/bin/sh /etc/rc.d/rc 3"; 
   exec.stop = "/bin/sh /etc/rc.d/rc 0"; 
   mount.fstab = "/usr/jails/fstab_centos6"; jail_enable="YES" 
 } jail_list="centos6" 

 #cloned_interfaces="lo2" 
 #jail_centos6_interface="lo2" 

 jail_centos6_interface="em0" 
 jail_centos6_ip="127.0.2.1" 
 jail_centos6_hostname="centos6.example.com" 
 jail_centos6_set_hostname_allow="YES" 

 jail_centos6_devfs_enable="YES" 
 jail_centos6_fdescfs_enable="YES" 
 jail_centos6_procfs_enable="YES" 
 jail_centos6_rootdir="/usr/jails/centos6.example.com" 
 jail_centos6_exec_start="/etc/init.d/rc 3" 
 jail_centos6_flags="-l -u root" 

 jail_centos6_fstab="/usr/jails/fstab_centos6" 
 </pre> 

 * Write some basic CentOS configuration files: 
 <pre> 
 cp /etc/resolv.conf /usr/jails/centos6.example.com/etc/resolv.conf 
 echo "NETWORKING=yes" >> etc/sysconfig/network 
 echo "linproc /usr/jails/centos6.example.com/proc /jails/centos6.example.com/proc linprocfs rw 0 0" >> /usr/jails/fstab_centos6 
 echo "192.168.6.6 localhost localhost.localdomain localhost4 localhost4.localdomain4 centos6 centos6.example.com" >> /usr/jails/centos6.example.com/etc/hosts 
 </pre> 

 * Create the password database for the jail: 
 <pre> 
 cd /usr/jails/centos6.example.com/etc  
 echo "root::0:0::0:0:Charlie &:/root:/bin/bash" > master.passwd 
 pwd_mkdb -d ./ -p master.passwd 
 </pre> 

 * Chroot into the centos6.examepl.com jail directory: 
 <pre> 
 chroot /usr/jails/centos6.example.com /bin/bash 
 </pre> 
 #* And prepare the environment: 
 <pre> 
 cd /etc 
 pwconv 
 grpconv 
 passwd 
 touch /etc/fstab 
 touch /etc/mtab 
 cd /sbin 
 mv consoletype consoletype.orig 
 ln -s /bin/true consoletype 
 cd /bin 
 mv umount umount.prev 
 ln -s /bin/true umount 
 chkconfig httpd off 
 chkconfig ip6tables off 
 exit  
 </pre> 

 * Enable jails to start at boot: 
 <pre> 
 echo 'jail_enable="YES"' >> /etc/rc.conf 
 </pre> 

 * And start the jail 
 <pre> 
 service jail start centos6.example.com 
 </pre> 

 * Check that the jail is running: 
 <pre> 
 jls 
 </pre> 

 h2. Resources 

 * https://bluehatrecord.wordpress.com/2015/09/19/the-midnight-oil-jailing-centos6-in-freebsd-10-2/ 
 * https://www.freebsd.org/doc/handbook/linuxemu-lbc-install.html

Back