TvE 2100 » At 2100 feet above Santa Barbara
Bosque del Apache National Wildlife Refuge, Feb 2004, ©2004 Thorsten von Eicken 

Creating a Debian Xen virtual machine

Posted: September 17th, by tve
Tags: #

This is brief note on how to create a Debian Sarge Xen VM on a Gentoo box. I’m using file-based disk images because it’s so flexible. I don’t believe the partition based ones are actually significantly faster. Inspiration for some of this came from this wiki page.

First I created a 30G LVM volume to hold disk images, created an XFS file system, and mounted it. Then I created a 4GB root image for Debian using XFS as well. I like XFS because it allows me to shrink and expand the filesystem and it also allows me to take snapshots.

hydra xen # lvcreate -L 30G vg1 -n images
 Logical volume "images" created
hydra xen # mkdir /etc/xen/images
hydra xen # cat >>/dev/fstab
/dev/vg1/images  /etc/xen/images xfs  noauto,noatime  0 2
<ctrl-D>
hydra xen # mkfs.xfs /dev/vg1/images 
meta-data=/dev/vg1/images        isize=256    agcount=16, agsize=491520 blks
         =                       sectsz=512   attr=0
data     =                       bsize=4096   blocks=7864320, imaxpct=25
         =                       sunit=0      swidth=0 blks, unwritten=1
naming   =version 2              bsize=4096  
log      =internal log           bsize=4096   blocks=3840, version=1
         =                       sectsz=512   sunit=0 blks
realtime =none                   extsz=65536  blocks=0, rtextents=0
hydra xen # mount /dev/vg1/images
hydra xen # df -h /dev/vg1/images
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg1-images
                       30G   13G   18G  41% /etc/xen/images
hydra ~ # dd if=/dev/zero of=/etc/xen/images/debian.root bs=1024k count=4096
4096+0 records in
4096+0 records out
4294967296 bytes (4.3 GB) copied, 129.508 seconds, 33.2 MB/s
hydra xen # mkdir /mnt/xen/debian.root
hydra xen # mkfs.xfs /xen/xen/images/debian.root 
meta-data=/big/xen/debian.root   isize=256    agcount=8, agsize=131072 blks
         =                       sectsz=512   attr=0
data     =                       bsize=4096   blocks=1048576, imaxpct=25
         =                       sunit=0      swidth=0 blks, unwritten=1
naming   =version 2              bsize=4096  
log      =internal log           bsize=4096   blocks=2560, version=1
         =                       sectsz=512   sunit=0 blks
realtime =none                   extsz=65536  blocks=0, rtextents=0
hydra xen # mount -o loop /etc/xen/images/debian.root /mnt/xen/debian.root
hydra xen #

Now we’re ready to install Debian Sarge:

hydra xen # emerge debootstrap
Calculating dependencies ...done!
>>> emerge (1 of 2) app-arch/dpkg-1.10.28 to /
...
>>> emerge (2 of 2) dev-util/debootstrap-0.2.45-r1 to /
...
hydra xen # debootstrap --arch i386 sarge /mnt/xen/debian.root http://ftp.us.debian.org/debian
I: Retrieving debootstrap.invalid_dists_sarge_Release
I: Validating debootstrap.invalid_dists_sarge_Release
I: Retrieving debootstrap.invalid_dists_sarge_main_binary-i386_Packages
I: Validating debootstrap.invalid_dists_sarge_main_binary-i386_Packages
I: Checking adduser...
...
I: Base system installed successfully.
umount: /mnt/xen/debian.root/dev/pts: not mounted
umount: /mnt/xen/debian.root/dev/shm: not mounted
umount: /mnt/xen/debian.root/proc/bus/usb: not mounted
hydra xen # 

Now we configure the new system:

hydra xen # chroot /mnt/xen/debian.root/
hydra:/# cd /etc
hydra:/etc# cat >fstab
/dev/sda1     /     ext3     defaults     0     1
/dev/sda2     none  swap     sw                    0     0
proc          /proc proc     defaults              0     0
hydra:/etc# mv /lib/tls /lib/tls.disabled
hydra:/etc# exit

Here’s my Xen config file, note that I have a DHCP server with static leases based on the mac address, that’s why I specify it carefully.:

hydra xen # cat debian 
kernel = "/boot/vmlinuz-2.6.16-r1-xenU" 
memory = 128
name = "debian" 
vif = [ 'mac=00:16:3E:00:00:24' ]
disk = ['file:/etc/xen/images/debian.root,sda1,w', 'file:/etc/xen/images/debian.swap,sda2,w']
root = "/dev/sda1 ro" 
hydra xen # 

Let’s start the virtual machine!

hydra xen # umount /mnt/xen/debian.root/

Installing Ruby on Rails on a Rimuhosting Fedora Core machine

Posted: August 7th, by tve
Tags: #

Here I go for my second Ruby on Rails install. This time it’s on a “virtual private server” at Rimuhosting

Installing a whole bunch of ruby stuff:

yum install ruby ruby-libs ruby-mode ruby-rdoc ruby-irb ruby-devel ruby-docs

Installing gems (check for latest version on RubyForge)
wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
tar zxvf rubygems-0.9.0.tgz
cd rubygems-0.9.0
ruby setup.rb

I installed rails:

gem install rails --include-dependencies

Now mySQL, which was installed but needed a bit of config:

chkconfig --add mysqld
chkconfig --level 3 mysqld on
/etc/init.d/mysqld start
/usr/bin/mysqladmin -u root password 'somethingsmart'
/usr/bin/mysqladmin -u root -h graphs.voneicken.com password 'somethingsmart'

Now we’re ready for the ruby mysql interface. First install the mysql-devel package (Rimu uses apt on FC5, not yum):

apt-get install mysql-client

and then the ruby interface itself:

gem install mysql -- --with-mysql-dir=/usr/lib/mysql --with-mysql-config=/usr/bin/mysql_config

Now we’re ready for mongrel!

gem install mongrel

did it’s job without complaining. What a relief!

Clone a Xen virtual machine

Posted: June 7th, by tve
Tags: #

This is the set of instructions I use to clone one of my virtual machines. First I prepare two logical volumes (partitions): one for the / filesystem and one for swap. Here we go:

hydra xen # lvdisplay -C
  LV       VG   Attr   LSize Origin Snap%  Move Log Copy%
  dom1     vg1  -wi-a- 4.00G                              
  dom1swap vg1  -wi-a- 1.00G                              
  dom2     vg1  -wi-ao 4.00G                              
  dom2swap vg1  -wi-ao 1.00G

Here I want to clone dom2 into a new dom3 (and I’m going to be lazy and not shut dom2 down, just pause it):

hydra xen # lvcreate -L 4G vg1 -n dom3
  Logical volume "dom3" created
hydra xen # lvcreate -L 1G vg1 -n dom3swap
  Logical volume "dom3swap" created
hydra xen # lvdisplay -C
  LV       VG   Attr   LSize Origin Snap%  Move Log Copy% 
  dom1     vg1  -wi-a- 4.00G                              
  dom1swap vg1  -wi-a- 1.00G                              
  dom2     vg1  -wi-ao 4.00G                              
  dom2swap vg1  -wi-ao 1.00G                              
  dom3     vg1  -wi-a- 4.00G                              
  dom3swap vg1  -wi-a- 1.00G                              
hydra xen # xm pause blog.fc5  # that's the machine running in dom2
hydra xen # dd if=/dev/vg1/dom2 of=/dev/vg1/dom3 bs=30M

BTW, it’s possible to check on the progress of the dd using kill -USR1 <pid>

hydra xen # xm unpause blog.fc5
hydra xen # mkswap /dev/vg1/dom3swap

Now create the xen config file for the new machine and change:

  • the name
  • the mac address
  • the disks
This looks as follows:

kernel = "/boot/vmlinuz-2.6.16-r1-xenU" 
#kernel = "/boot/vmlinuz-2.6.16-1.2080_FC5xenU" 
memory = 128&lt;br /&gt;name = "trac.fc5" 
vif = [ 'mac=00:16:3E:00:00:23' ]
disk = ['phy:vg1/dom3,sda1,w', 'phy:vg1/dom3swap,sda3,w']
root = "/dev/sda1 ro" 

Now mount the new filesystem and fix a few things:

hydra xen # mkdir /mnt/xen/dom3
hydra xen # mount /dev/vg1/dom3 /mnt/xen/dom3
hydra xen # cd /mnt/xen/dom3/etc/sysconfig
hydra sysconfig # vi network  # fix hostname

Start the machine, holding on to the console:

hydra sysconfig # cd
hydra ~ # umount /mnt/xen/dom3
hydra ~ # xm create-c trac.fc5
hydra ~ # xm create -c auto/trac.fc5

Other things to do:

  • add the hostname to DNS
  • generate new SSH keys
  • ...