Skip to content

Instantly share code, notes, and snippets.

@jedi4ever
Created January 23, 2013 18:12
Show Gist options
  • Save jedi4ever/4611165 to your computer and use it in GitHub Desktop.
Save jedi4ever/4611165 to your computer and use it in GitHub Desktop.
thoughts on veewee && openvz
# Export from an (vagrant) image
# http://wiki.openvz.org/Physical_to_container#Disable_old_network_interface
# Ubuntu - http://wiki.openvz.org/Ubuntu_Gutsy_template_creation
# Ubuntu guest networking - http://blog.hostonnet.com/openvz-ubuntu-guest-have-not-networking
#(ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 7222 -l vagrant 127.0.0.1 "sudo tar --numeric-owner -cjpf - -X /home/vagrant/excludes /" ) > u10.tgz
VID=123
VZ_DIR=/vz
IP=192.168.8.$VID
TGZ="/var/tmp/u10.tgz"
OSTEMPLATE="ubuntu-12.04-x86_64"
DNS="8.8.8.8"
vzctl stop $VID
vzctl destroy $VID
# Create the directories
mkdir -p $VZ_DIR/root/$VID
mkdir -p $VZ_DIR/private/$VID
# Set the sample settings
cat /etc/vz/conf/ve-basic.conf-sample > /etc/vz/conf/$VID.conf
# Need to set OSTEMPLATE VAR
echo "OSTEMPLATE=$OSTEMPLATE" >> /etc/vz/conf/$VID.conf
# Set the ip address
vzctl set $VID --ipadd $IP --save
vzctl set $VID --nameserver $DNS --save
# Set DNS
# Extract the tarball - maybe we can exclude here too!
cd $VZ_DIR/private/$VID
tar -xjvf $TGZ
# Cleanup files
rm -rf $VZ_DIR/private/$VID/boot/*
rm -rf $VZ_DIR/private/$VID/lib/modules/*
rm -rf $VZ_DIR/private/$VID/etc/blkid.*
rm -rf $VZ_DIR/private/$VID/etc/lvm/
rm -rf $VZ_DIR/private/$VID/etc/fstab
rm -rf $VZ_DIR/private/$VID/etc/udev/
rm -rf $VZ_DIR/private/$VID/var/cache/apt/archives/*.deb
rm -rf $VZ_DIR/private/$VID/vmlinuz*
rm -rf $VZ_DIR/private/$VID/initrd.img*
rm -rf $VZ_DIR/private/$VID/home/vagrant/VBoxGuestAdditions_4.2.6.iso
ln -s /proc/mounts $VZ_DIR/private/$VID/etc/mtab
# Creating devices
/sbin/MAKEDEV -d $VZ_DIR/private/$VID/dev ttyp ptyp
mknod --mode 666 $VZ_DIR/private/$VID/dev/ptmx c 5 2
mknod --mode 666 $VZ_DIR/private/$VID/dev/null c 1 3
mknod --mode 444 $VZ_DIR/private/$VID/dev/urandom c 1 9
mkdir $VZ_DIR/private/$VID/etc/udev/devices
/sbin/MAKEDEV -d /vz/private/123/dev {p,t}ty{a,p}{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} console core full kmem kmsg mem null port ptmx random urandom zero ram0
/sbin/MAKEDEV -d /vz/private/123/etc/udev/devices {p,t}ty{a,p}{0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} console core full kmem kmsg mem null port ptmx random urandom zero ram0
vzctl start $VID
sleep 3
# Ready for action
vzctl exec $VID /etc/init.d/networking start
vzctl exec $VID /etc/init.d/ssh start
vzctl exec $VID apt-get update
vzctl exec $VID apt-get install htop
- openvz templates are either created via chrooted install (fai, debconf) or using an existing vm
- the veewee sequence I'm thinking:
# Export (could be vbox, fusion, kvm)
$ veewee vbox tgz ubuntu-10 (does the tarball export , maybe some excludes)
# Import in openvz
$ veewee openvz define ubuntu-10
(define it to know what os type you're working on - this will use the correct script - like the script above is for ubuntu cleanup)
$ veewee openvz build ubuntu-10 --vid 123 --ip 192.168.8.123 --dns 8.8.8.8
(would build the openvz image in openvz container)
$ veewee openvz export ubuntu-10
(would create usuable template from it)
------
We could reuse the tarball creation mechanism maybe for EC2?:
- Spin up an ami + ebs
- format the disk
- extract the tarball
- chroot changes stuff if needed changes
- snapshot ami
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment