Ubuntu 14.04 and LXC containers
Ubuntu releases after 10.04 LTS do no longer provide unfs3. Unfs3 is useful when one want to setup a fog server in a container with OpenVZ or LXC. Nfs kernel server cannot run in these containers.
Here's how to setup a FOG server in a LXC container.
- A computer (physical or virtual) running Ubuntu 14.04 Server, may or may not using LVM, with available space in at least one volume group
Network setup on the LXC host
Setup a bridge on the computer, with at least one ethernet interface attached to it.
apt-get install bridge-utils
edit the file /etc/network/interfaces and add the following lines. Please ensure you're not using a SSH session, because you may lose your connection !
Add the following lines : auto br0 iface br0 inet static address 192.168.1.2 netmask 255.255.255.0 gateway 192.168.1.1 bridge_ports eth0 bridge_fd 0 bridge_maxwait 0
Reboot the computer and check network connectivity
LXC container creation
First, create a LXC container running Ubuntu. The version is the latest LTS version available at the moment of creating the container
lxc-create -n server-fog -t ubuntu -B lvm --vgname vg --lvname lv-server-fog --fssize=10G --fstype=ext4
This will create a logical volume lv-server-fog in the volume group vg0, with a 10GB ext4 filesystem. The container wil be named server-fog. At the end of the process, the system will give you a login and a password.
Edit the file /var/lib/lxc/server-fog/config and setup networking for the container :
lxc.network.link = br0 lxc.network.ipv4 = 192.168.1.3 lxc.network.gateway = 192.168.1.1
start your container
lxc-start -n server-fog -F
login with the credentials given earlier, and change the password ! If needed, you have to shutdown the container to go back to the host's console
sudo init 0
To run the container non interactively, use the following command
lxc-start -d -n server-fog
To use a terminal in the container :
lxc-console -n server-fog
You may exit the container at any time using the following keys (do not forget to logout first, because this will NOT logout any user in the container) :
In the container you have to download, compile and install unfs3 from sources.
- Download unfs3
- decompress the archive : tar zxf unfs3-0.9.22.tar.gz
- apt-get install build-essential make flex bison
- cd unfs3-0.9.22
- make install
- make install-init
- edit /etc/init.d/unfsd and replace the occurence of /usr/sbin/unfsd with /usr/local/sbin/unfsd
- /etc/init.d/unfsd start
- check unfsd is running : ps -ef | grep unfsd
- if it runs, then run update-rc.d unfsd defaults
Install and configure fog as usual.
If you want to setup a separate volume for your images :
- assuming you want to use a logical volume (LVM) /dev/vg0/lv with a ext3 filesystem :
- run your container and move all files located in /images into an other location (/root/images-bak), including the hidden file /images/.mntcheck
- from the lxc host, open /var/lib/your-container/fstab and add the following line : /dev/vg0/lv images ext3 defaults 0 0
- restart the container, and check the nex volume is available : run mount without any argument.
- If the LVM volume has been successfully mounted, move back the files backed up in /root/images-bak. Note there is no slash before images.
- chmod 777 /images
Once your setup is up and running, do not forget to enable autostart of your container :
edit /var/lib/lxc/server-fog/config :
lxc.start.auto = 1