Create a Ubuntu 14.04 OpenVZ Template for Proxmox

Create a Ubuntu 14.04 OpenVZ Template for Proxmox

Get Social!

proxmox logo gradThe latest Ubuntu long term support is now available, called Ubuntu 14.04.

There isn’t currently a template available over on OpenVZ however I’m sure that will be shortly rectified. In the meantime, however, you can use the below steps to create a 14.04 Ubuntu template for OpenVZ/ Proxmox. This template has only been lightly tested so please report any errors as you find them.

This template is BETA, please report any problems in the comments.

Vistit Downloads Page

 

You can download a pre-created VM from here directly, or you can create your own using the below notes.

 

Before continuing, this guide assumes that you already have an installation of Ubuntu up and running which you can SSH to. This could be either a KVM or physical machine.

We will use debootstrap to create the template so make sure it’s installed and install it if you haven’t already.

apt-get install -y debootstrap

Use debootstrap to download and configure all the required packages to a temporary directory. For this example, we’ll use /tmp/deb.

debootstrap --arch amd64 trusty /tmp/deb ftp://ftp.ubuntu.com/ubuntu

Copy the below script into the tmp directory of the template root which has just been created. For this example you’ll need to copy the text into this path:

vi /tmp/deb/tmp/client.sh
#!/bin/bash

echo "root:password" | chpasswd

apt-get update

apt-get purge -y console-setup ntpdate whiptail eject ureadahead sudo vim-tiny rsync
apt-get install -y vim openssh-server

find / -name *ondemand -exec rm -rf {} \;
rm -f /etc/init/console* /etc/init/tty*

sed -i -e 's/^\$ModLoad imklog/#\$ModLoad imklog/g' /etc/rsyslog.conf
sed -i -e 's@\(space:\)\(/var/log/\)@\1-\2@' /etc/rsyslog.d/*.conf
sed -i -e 's/^\#cron./cron./g' /etc/rsyslog.d/50-default.conf

sed -i -e 's/^\console output/#console output/g' /etc/init/rc.conf
sed -i -e 's/^\env INIT_VERBOSE/#env INIT_VERBOSE/g' /etc/init/rc.conf

locale-gen en_US.UTF-8
locale-gen en_GB.UTF-8
dpkg-reconfigure locales

cp /usr/share/zoneinfo/Europe/London /etc/localtime

cat <<EOF > /etc/init/tty1.conf
# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]

stop on runlevel [!2345]

respawn
exec /sbin/getty -8 38400 tty1
EOF

rm -f /etc/ssh/ssh_host_*

cat << EOF > /etc/init.d/generate_ssh_keys
#!/bin/bash
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ''
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N ''
rm -f \$0
EOF

chmod a+x /etc/init.d/generate_ssh_keys
update-rc.d generate_ssh_keys defaults

apt-get clean
find /var/ -name *.log -exec rm -rf {} \;
rm -rf /boot /dev /media /opt /run /srv /tmp /root/.bash_history /root/.viminfo /etc/ssh/ssh_host_*
mkdir /dev /run /tmp
touch /dev/null

exit

Make the script runnable which chmod.

chmod +x /tmp/deb/tmp/client.sh

Run the above script using the chroot command to set up the template.

chroot /tmp/deb /tmp/client.sh

The script will now run and set up the template using /tmp/deb/ as the templates root.

Once completed, create an archive of the template root device and install it on your OpenVZ/ Proxmox server.

cd /tmp/deb
tar -czpf /tmp/ubuntu-14.04-x86_64-initial1.tar.gz .

Copy the /tmp/ubuntu-14.04-x86_64-initial1.tar.gz file to your cache directory of your Proxmox install and create your first Ubuntu 14.04 container!

proxmox-ubuntu-1404-template


10 Comments

Paul

26-Apr-2014 at 10:20 pm

You need to symlink /sbin/iptables-save over to /bin/true

During the live migration process of a VZ container it executes iptables-save in order to try and save iptables rules. Since iptables isn’t installed and iptables-save is missing from this image, it fails with the following error:

Apr 26 18:16:02 dump container state
Apr 26 18:16:03 # vzctl –skiplock chkpnt 100 –dump –dumpfile /mnt/pve/proxvol/dump/dump.100
Apr 26 18:16:02 Setting up checkpoint…
Apr 26 18:16:02 join context..
Apr 26 18:16:02 dump…
Apr 26 18:16:03 Can not dump container: Invalid argument
Apr 26 18:16:03 Error: iptables-save exited with 255
Apr 26 18:16:03 ERROR: Failed to dump container state: Checkpointing failed

By “ln -s /bin/true /sbin/iptables-save” it will fix it. I’ve made the changes to the image I created and it’s able to live migrate now.

Josef

12-May-2014 at 2:33 pm

Thank you!

denis

29-May-2014 at 1:11 pm

login and password for u templ?

    james.coyle

    30-May-2014 at 12:42 pm

    You set that with the vzctl command.

Axel

6-Jul-2014 at 6:24 am

The procedure is working but after, each time, I start the VZ, I have this error message:
resolvconf: Error: /run/resolvconf/interface either does not exist or is not a directory
and at the creation of the VZ from the ubuntu-14.04-x86_64-initial1.tar.gz template, I had this error message:
touch: cannot touch `/var/lib/vz/root/105/etc/resolv.conf’: No such file or directory

    james.coyle

    8-Jul-2014 at 2:14 pm

    It’s because that file does not exist. Have you set the DNS entries in the Proxmox web GUI?

      Axel

      8-Jul-2014 at 9:51 pm

      Yes why ?

        james.coyle

        8-Jul-2014 at 10:18 pm

        I’m guessing it’s because the file does not exist – are you able to manually create it and does the error go away?

        I’ll update the image at the weekend.

gkoufoud

6-Aug-2014 at 11:11 am

Good job,
I’d like to mention some things…
1. /tmp permissions should be 777 (otherwise you may experience problems e.g. mysql installation etc) -> chmod 777 /tmp (inside client.sh script)
2. If you want to allow ssh root login add this to the client.sh : sed -i -e ‘s/^PermitRootLogin without-password/PermitRootLogin yes/g’ /etc/ssh/sshd_config

3. To avoid /etc/init.d/generate_ssh_keys startup script you can add the following to the client.sh script ->
sed -i ‘s/exit/#exit/g’ /etc/rc.local
echo “if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then” >> /etc/rc.local
echo ” ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ”” >> /etc/rc.local
echo “fi” >> /etc/rc.local
echo “if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then” >> /etc/rc.local
echo ” ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N ”” >> /etc/rc.local
echo “fi” >> /etc/rc.local
echo “exit 0” >> /etc/rc.local

Thanks.

    james.coyle

    6-Aug-2014 at 1:37 pm

    Thanks, great suggestions!

Leave a Reply

Visit our advertisers

Quick Poll

Which type of virtualisation do you use?
  • Add your answer

Visit our advertisers