Create XEN LXC DomU

DOMAIN_NAME=lxc
DOMAIN_MAC=00:00:00:ef:11:cc
DOMAIN_RAM=2Gb
DOMAIN_HDD=128Gb
 
xen-create-image \
    --hostname=${DOMAIN_NAME} \
    --dist=xenial  \
    --lvm=vg1 \
    --fs=ext4 \
    --dhcp \
    --pygrub \
    --mac=${DOMAIN_MAC} \
    --mirror=http://archive.ubuntu.com/ubuntu \
    --size=${DOMAIN_HDD} \
    --memory=${DOMAIN_RAM} \
    --swap=${DOMAIN_RAM} \
    --genpass=0 \
    --password=t00r \
    --vcpus $(cat /proc/cpuinfo | grep processor | wc -l)
 
mv /etc/xen/${DOMAIN_NAME}.cfg /etc/xen/${DOMAIN_NAME}
ln -s /etc/xen/${DOMAIN_NAME} /etc/xen/auto/12_lxc
 
mount /dev/vg1/${DOMAIN_NAME}-disk /mnt/
chroot /mnt/
mount /proc/
 
debconf-set-selections <<\EOF
grub-pc grub-pc/install_devices_empty select true
EOF
 
apt-get install -y linux-image-generic
 
cat <<EOF>> /boot/grub/menu.lst 
default         0
timeout         2
 
title           Ubuntu 16.04 LTS
root            (hd0,0)
kernel          /boot/vmlinuz-4.4.0-21-generic root=/dev/xvda2 ro 
initrd          /boot/initrd.img-4.4.0-21-generic
 
title           Ubuntu 16.04 LTS (Single-User)
root            (hd0,0)
kernel          /boot/vmlinuz-4.4.0-21-generic root=/dev/xvda2 ro single
initrd          /boot/initrd.img-4.4.0-21-generic
EOF
 
umount /proc/
exit
umount /mnt
 
xm create -c ${DOMAIN_NAME}