Archive for the ‘Xen’ Category

proxy vm

Saturday, February 2nd, 2008

I am setting up an http proxy.

# cd /xen
# mkdir www1
# cd www1/
# tar xjvf ../debian-4.0-20070801.tar.bz2
debian-4.0.img
debian-4.0.xen3.cfg
debian.swap
# mv debian-4.0.xen3.cfg proxy.cfg
# dd if=/dev/zero of=debian.swap bs=1M count=256
# dd if=/dev/urandom bs=1 count=3 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | tr -d ' ' | tr '[a-f]' '[A-F]'
7E0E41
# vi proxy.cfg
kernel = "/boot/vmlinuz-2.6-xenU"
memory = 128
name = "proxy"
vif = [ 'bridge=xenbr0,mac=00:16:3e:7E:0E:41' ]
dhcp = "dhcp"
disk = ['file:/xen/debian/debian-4.0.img,sda1,w'
, 'file:/xen/debian/debian.swap,sda2,w'
]
root = "/dev/sda1 ro"
ramdisk = "/boot/initrd-2.6-xenU.img"
# xm create -c ./proxy.cfg
...
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 5
receive_packet failed on eth0: Network is down
DHCPOFFER from 192.168.0.36
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.0.36
bound to 192.168.0.215 -- renewal in 300 seconds.
done.
...
# ssh 192.168.0.215
Password: password
# vi /etc/hostname
proxy
# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
# apt-get update
...
# vi /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.0.52
netmask 255.255.255.0
gateway 192.168.0.1   

auto lo
iface lo inet loopback
# /etc/init.d/networking restart
...lost network connection...
# ssh 192.168.0.52
# apt-get install squid3
# apt-get dist-upgrade 

I will continue the configuration tomorrow. It will only allow local connections (192.168.0.x).

nano /etc/squid3/squid.conf
I searched for acl all to find the area and added two acls.

acl privnat src 192.168.0.0/255.255.255.0
acl dmz src 10.0.0.192/255.255.255.224

I searched a couple of times for “http_access all” and following the INSERT line, added my new rules:

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
http_access allow privnat
http_access allow dmz

Save and close the file, then restart squid.

/etc/init.d/squid3 restart

irked vm

Thursday, January 3rd, 2008

I setup a VM for psybnc and irssi.

# cd /xen
# mkdir irc
# cd irc
# tar xjvf ../debian-4.0-20070809.tar.bz2

Generate the last 3 bytes for the MAC

dd if=/dev/urandom bs=1 count=3 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | tr -d ' ' | tr '[a-f]' '[A-F]'

Create the config file /xen/irc/irc.cfg

kernel = "/boot/vmlinuz-2.6-xenU"
memory = 64
name = "tigger"
vif = [ 'bridge=xenbr0,mac=00:16:3e:97:29:51' ]
dhcp = "dhcp"
disk = ['file:/xen/irc/debian-4.0.img,sda1,w'
, 'file:/xen/irc/debian.swap,sda2,w'
]
root = "/dev/sda1 ro"
ramdisk = "/boot/initrd-2.6-xenU.img"

I linked the config so it will autostart when owl boots and I started the vm

ln -s /xen/irc/irc.cfg /etc/xen/auto/
xm create -c irc.cfg

Watch the boot, and ssh to the dhcp temp address

/etc/network/interfaces

auto eth0
iface eth0 inet static
        address x.y.z.202
        netmask 255.255.255.224
        gateway x.y.z.222

/etc/resolve.conf

search revantine.net
nameserver 192.168.0.36

reset the root password
change the ssh port
Set the hostname in /etc/hostname

irked.revantine.com

If you get “4gb seg fixup” errors, this will probably fix it.

apt-get update
apt-get install libc6-xen
echo "hwcap 0 nosegneg" > /etc/ld.so.conf.d/nosegneg.conf
ldconfig -v -p 2>&1 | grep libc.so
ldconfig

Permissions on /tmp are correct.
Maybe the permissions are only messed up if you have a seperate /tmp partition.

useradd charles
useradd psybnc

existing psybnc.sh to start psybnc:

#!/bin/bash
MATCHTEXT=[p]sybnc$

if ! ps -A|grep -e $MATCHTEXT >/dev/null
then
  date
  echo "Script starting..."
  exec su psybnc -c "cd /usr/local && ./psybnc"
else
#  echo "Script is already running."
  exit 1
fi

I add this to /etc/rc.local to start psybnc:
su phybnc -c “cd /usr/local && ./psybnc” &>/dev/null &

My new ~/.screenrc

hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c:%s %{g}]'

screen -t shell1        0
screen -t shell2        1
#screen -t shell3       2
#screen -t shell4       3       ssh hostname.domain.com

tigger reborn

Saturday, December 15th, 2007

We lost power last Monday (Dec 10) and got power back Thursday (Dec 13). I didn’t shutdown the Xen server does properly and the web server was corrupted. I built a new web server vm and connected the old data drives. Breaking tradition, I named the new server www1 so I could more easily tell the difference between it and tigger (the corrupt web server).

www1 vm

Saturday, December 15th, 2007

unpacked my model…

# cd /xen
# mkdir www1
# cd www1/
# tar xjvf ../debian-4.0-20070801.tar.bz2
debian-4.0.img
debian-4.0.xen3.cfg
debian.swap

I created LVMs and formatted them. This will be the new partition layout.

lvcreate -L1G -n www1-usr VolGroup00 && \
lvcreate -L512M -n www1-tmp VolGroup00 && \
lvcreate -L2G -n www1-var VolGroup00
mkfs -t ext3 /dev/VolGroup00/www1-usr
mkfs -t ext3 /dev/VolGroup00/www1-tmp
mkfs -t ext3 /dev/VolGroup00/www1-var
dd if=/dev/urandom bs=1 count=3 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | tr -d ' ' | tr '[a-f]' '[A-F]'
kernel = "/boot/vmlinuz-2.6-xenU"
memory = 512
name = "www1"
vif = [ 'bridge=xenbr0,mac=00:16:3e:A1:00:5C' ]
dhcp = "dhcp"
disk = ['file:/xen/www1/debian-4.0.img,sda1,w'
, 'file:/xen/www1/debian.swap,sda2,w'
, 'phy:VolGroup00/www1-usr,sda3,w'
, 'phy:VolGroup00/tigger-home,sda4,w'
, 'phy:VolGroup00/www1-tmp,sda5,w'
, 'phy:VolGroup00/www1-var,sda6,w'
, 'phy:VolGroup00/tigger-var-www,sda7,w'
, 'phy:VolGroup00/tigger-swap,sda8,w'
]
root = "/dev/sda1 ro"
ramdisk = "/boot/initrd-2.6-xenU.img"
ln -s /xen/tigger/tigger.cfg /etc/xen/auto/
./flip sda3 usr
./flip sda6 var
mount /dev/sda5 /tmp

on owl:

mkdir /mnt/xen
mount -o loop /xen/tigger/debian-4.0.img /mnt/xen
mount /dev/VolGroup00/tigger-var /mnt/xen/var
export IP='192.168.0.1'

cp /etc/mtab ~/etc/ && \
cp /etc/init.d/makedev ~/etc/init.d/ && \
rsync -e ssh -avz root@$IP:/mnt/xen/etc/* /etc/ && \
cp -R ~/etc/* /etc/
rsync -e ssh -avz $IP:/mnt/xen/var/lib/mysql /var/lib/
rsync -e ssh -avz $IP:/mnt/xen/lib/mysql /var/lib/

owl:

scp dpkg-verify  tigger.revantine.com:~/
scp .ssh/authorized_keys tigger.revantine.com:~/.ssh/
scp selections.dpkg tigger.revantine.com:~/

back to www1

apt-get update && \
dpkg --set-selections  < ~/selections.dpkg && \
apt-get dselect-upgrade

apt-get install libc6-xen
echo "hwcap 0 nosegneg" > /etc/ld.so.conf.d/nosegneg.conf
ldconfig -v -p 2>&1 | grep libc.so
ldconfig

/tmp loses its permissions

chmod 1777 /tmp
Starting apache-ssl 1.3 web server...PHP Warning:  Unknown(): Unable to load dynamic library '/usr/lib/php4/20050606+lfs/php_ming.so' - /usr/lib/php4/20050606+lfs/php_ming.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  Unknown(): Unable to load dynamic library '/usr/lib/php4/20050606+lfs/ming.so' - /usr/lib/php4/20050606+lfs/ming.so: cannot open shared object file: No such file or directory in Unknown on line 0
.
apt-get remove exim libming
apt-get install libming0 php4-ming

RoundCube webmail doesn’t work. Oh well, it is a good time to upgrade from beta to 0.01-rc2 I guess.
(Success)

I forwarded the old webmail address to the new webmail address.
This is a great site for different 301 redirects http://www.stevenhargrove.com/redirect-web-pages/

CentOS 5 Xen

Friday, September 14th, 2007

This server will run a CentOS 5 host operating system. It will have Debian guest systems virtualized through Xen. I chose CentOS because it has good install support for software raid and lvm and the Red Hat product it derives from seems to have mature virtualization technology (vt). Debian is running on the existing servers I am migrating from physical to virtual. Debian has excellent long term maintainability and I will use my existing disaster recovery plan for the migration.

I installed CentOS. I chose server-gui and virtualization on install. When I setup LVM I created an LVM that mounts to /xen and left 150+G in the Volume Group but unallocated. I will use the space to additional guest vm partitions.

I downloaded the Debian 3.1 xen virtual machine (vm) package from http://jailtime.org . I chose this since I was able to make it work on another machine I was playing with previously. To keep the system as close to the model vm as possible, I have made some additional links.

  • Note: The http://jailtime.org package unpacked to the current directory. It expects to be in /xen/debian so you might as well create the sub-folder and cd there before un-taring.

Setup
I have found the system would kernel panic previously. In part this is because the xenblk module is not loaded. You also need xennet either by including it in the ramdisk or by using modules.conf/modprobe.conf. I chose to include it in the ramdisk.

# uname -r
2.6.18-8.el5xen
# mkinitrd --preload=xenblk --with=xennet /boot/initrd-`uname -r`U.img `uname -r`
# ln -fs /boot/initrd-`uname -r`U.img /boot/initrd-2.6-xenU.img

I linked vmlinuz-2.6-xenU -> vmlinuz-2.6.18-8.el5xen because many of the prebuilt vms expect this to exist.

ln -fs /boot/vmlinuz-`uname -r` /boot/vmlinuz-2.6-xenU

Because the jailtime.org images expect /xen to contain the images, I have linked it to /vserver

ln -s /vserver /xen

Kernel Panic
At this point when I tried to start the vm, it kernel panic’d. This command creates (starts) the vm, and the -c option takes the console you are viewing for the new vm’s console. This lets you view the boot and errors.

xm create -c /xen/debian/debian.3-1.xen3.cfg

The last of the output:

XENBUS: Device with no driver: device/vbd/2049
XENBUS: Device with no driver: device/vbd/2050
XENBUS: Device with no driver: device/vif/0
md: Autodetecting RAID arrays.
md: autorun ...
md: ... autorun DONE.
VFS: Cannot open root device "sda1" or unknown-block(0,0)
Please append a correct "root=" boot option
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

Troubleshooting and the fix
You can mount the image with a loop device and look at the files in the vm image. You cannot do this while the vm is running, and you cannot start the vm while it is mounted like this. Keep this in mind for later; you don’t need to do this right now.

cd /mnt
mkdir vm
mount -o loop /vserver/debian/debian.3-1.img /mnt/vm

I added this to the bottom of /xen/debian/debian.3-1.xen3.cfg

ramdisk = "/boot/initrd-2.6-xenU.img"

Running, almost…
Now I start it, and it boots completely. You can leave the console with Ctrl+]

xm create -c /xen/debian/debian.3-1.xen3.cfg

And the catch? No way to interact.

$ nmap 192.168.0.202

Starting Nmap 4.20 ( http://insecure.org ) at 2007-07-29 23:14 CDT
All 1697 scanned ports on 192.168.0.202 are closed

Nmap finished: 1 IP address (1 host up) scanned in 1.832 seconds

Shutting down
I am shutting down the vm now. I will probably need to mount the image in a loopback and use chroot to add ssh. I will pursue this more tomorrow.

# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     3920     2 r-----    510.5
debian.3-1                                 5      127     1 r-----   5255.2
# xm shutdown debian.3-1
# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     3920     2 r-----    512.0

Configuration
I need to add ssh for it to be usable as a base system.


I found the root cause of this problem. Skip to the double lines for the fix.

The error trying to start ssh:

Starting OpenBSD Secure Shell server: sshd
PRNG is not seeded

The error is caused by no /dev/urandom being present. Mount the disk image in loop.

nano /etc/init.d/local

and add this

#!/bin/bash
cd /dev
./MAKEDEV mem
./MAKEDEV urandom
/etc/init.d/ssh start

Make it executable and link it to start on boot. This assumes you are in the folder where you mounted to.

chmod +x etc/init.d/local
ln -s etc/iniit.d/local etc/rc3.d/local


Edit etc/init.d/makedev. In the “start)” section, after the “test” statement, add this line. This creates devices and corrects some permissions. Most importantly it lets openssh start, and prevents odd problems.

cd /dev && ./MAKEDEV zero

Change the permission of /tmp

chmod 1777 tmp

As long as you have it mounted, change the ssh setting so you can login as root.

mv etc/ssh/sshd_config{,~} && sed 's/PermitRootLogin no/PermitRootLogin yes/' etc/ssh/sshd_config~ >etc/ssh/sshd_config

Now a few additions to make the deployment easier.
Copy the edited makedev to root/etc. This will become a directory to hold /etc files that should be retained when we rsync /etc

mkdir root/etc/init.d
cp etc/init.d/makedev ~/etc/init.d/

I also put the “flip” script in root since I am using this everytime. vm flip filesystems

Now boot the vm.

Running
The first thing you should do is change the root passwd. The default password of the jailtime.org images is password.

I changed the virtual interface so that it will use the same MAC address everytime.

vif = [ 'bridge=xenbr0,mac=00:16:3e:xx:xx:xx' ]

00:16:3e is the MAC vendor code for Xen. The last 3 bytes should be unique, especially on your network. You can use this to generate 3 unique hex bytes.

dd if=/dev/urandom bs=1 count=3 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | tr -d ' ' | tr '[a-f]' '[A-F]'

I booted the vm and edited /etc/apt/sources.list. I changed “sarge” to “stable” to upgrade to etch. I then ran:

apt-get update
apt-get dist-upgrade
...
Do you want to upgrade glibc now? [Y/n] Y
Do you wish to restart services? [Y/n] Y

Started getting this error:

4gb seg fixup, process dpkg (pid 1292), cs:ip 73:4003ede1

Because this requires changes in /etc and I rsync that directory, I will save the fix for the vms.

I renamed the img and config to debian.3-1 to debian.4-0 to reflect the new version, and changed the config to correctly load the image.
Error during boot

Setting hostname to 'debian_pristine'...hostname: the specified hostname is invalid

I do not plan on fixing this since I will be changing the hostname on deployment.

tar’ing the image as the deployment model.

Automatically starting domains
link to article

If you would like a domain to start automatically when the (dom0) system is started, move the domain configuration to the /etc/xen/auto directory. For instance:

ln -s /xen/debian/debian/cfg /etc/xen/auto/

I will likely try linking to that directory.

LVM
link to article
Create a logical volume of size 4GB named `myvmdisk1′:

# lvcreate -L4096M -n myvmdisk1 vg

You should now see that you have a /dev/vg/myvmdisk1 Make a filesystem, mount it and populate it, e.g.:

# mkfs -t ext3 /dev/vg/myvmdisk1
# mount /dev/vg/myvmdisk1 /mnt
# cp -ax / /mnt
# umount /mnt

Now configure your VM with the following disk configuration:

disk = [ 'phy:vg/myvmdisk1,sda1,w' ]

I am going to name my LVMs after the host and mount point so I can identify them. I use Pooh characters for my servers, so my first will be /dev/VolGroup00/kanga-var and kanga-tmp
kanga vm


Links:
CentOS 5 with Debian 3.1 and 4.0 guests:
http://juanjosec.blogspot.com/2007/06/migrating-xen-installation-from-fc5-to.html
Xen and LVM VBD (Virtual Block Devices)
http://www.linuxtopia.org/online_books/linux_virtualization/xen_3.0_user_guide/linux_virualization_xen_user_44.html
Installing a Xen DomU on CentOS 5
http://wiki.centos.org/HowTos/Xen/InstallingCentOSDomU

Migrated the web server to xen

Sunday, August 12th, 2007

Early in the morning…
I started migrating tigger tonight. tigger vm It is moving about 8G of data and so I am going to sleep and will pickup tomorrow. This has definately been smoother with all the things I have learned from the first two. It will also be the last full server migration as everything remaining needs to be moved as services rather than servers.

And later…
tigger, the web server went the smoothest of all the servers. I am really pleased with the process. The only hitch I had was that while rotating the filesystem /tmp permissions changed. It caused an error but was easy to fix.

tigger vm

Sunday, August 12th, 2007

Tigger is a web server with php, perl, mysql, etc.

I unpacked my model…

# cd /xen
# mkdir gopher
# cd gopher/
# tar xjvf ../debian-4.0-20070801.tar.bz2
debian-4.0.img
debian-4.0.xen3.cfg
debian.swap

The original partition layout:

/dev/hda2 on / type ext3 (rw,errors=remount-ro)
/dev/hda1 on /boot type ext3 (rw)
/dev/hdb1 on /home type ext3 (rw,errors=remount-ro)

Filesystem            Size  Used Avail Use% Mounted on
/dev/hda2             2.4G  1.2G  1.2G  51% /
/dev/hda1              45M  9.4M   33M  23% /boot
/dev/hdb1              29G  8.1G   19G  31% /home

I created LVMs and formatted them. This will be the new partition layout.

lvcreate -L1G -n tigger-usr VolGroup00 && \
lvcreate -L10G -n tigger-home VolGroup00 && \
lvcreate -L512M -n tigger-tmp VolGroup00 && \
lvcreate -L2G -n tigger-var VolGroup00 && \
lvcreate -L20G -n tigger-var-www VolGroup00
mkfs -t ext3 /dev/VolGroup00/tigger-usr
mkfs -t ext3 /dev/VolGroup00/tigger-home
mkfs -t ext3 /dev/VolGroup00/tigger-tmp
mkfs -t ext3 /dev/VolGroup00/tigger-var
mkfs -t ext3 /dev/VolGroup00/tigger-var-www

Although right now I have http in /home, I want to move it to /var/www so I will create a partition there large enough to accomodate it. First I will migrate the whole system. After everything works then I will move files around and change configuration. That way I only have one variable at a time.

This is the config file I will use. I just renamed the model and filled in the fields. I used the command from previous to generate a random MAC, leaving the first 3 bytes as the Xen vendor.

dd if=/dev/urandom bs=1 count=3 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | tr -d ' ' | tr '[a-f]' '[A-F]'

/xen/tigger/tigger.cfg

kernel = "/boot/vmlinuz-2.6-xenU"
memory = 512
name = "tigger"
vif = [ 'bridge=xenbr0,mac=00:16:3e:51:9A:81' ]
dhcp = "dhcp"
disk = ['file:/xen/tigger/debian-4.0.img,sda1,w'
, 'file:/xen/tigger/debian.swap,sda2,w'
, 'phy:VolGroup00/tigger-usr,sda3,w'
, 'phy:VolGroup00/tigger-home,sda4,w'
, 'phy:VolGroup00/tigger-tmp,sda5,w'
, 'phy:VolGroup00/tigger-var,sda6,w'
, 'phy:VolGroup00/tigger-var-www,sda7,w'
]
root = "/dev/sda1 ro"
ramdisk = "/boot/initrd-2.6-xenU.img"

I linked the config so it will autostart when owl boots.

ln -s /xen/tigger/tigger.cfg /etc/xen/auto/

And I started the vm

xm create -c tigger.cfg

192.168.0.211

I used the flip script to move the files to the partitions.

./flip sda3 usr
./flip sda6 var

and mounted the empty directories by hand…

mount /dev/sda4 /home
mount /dev/sda5 /tmp
mount /dev/sda7 /var/www
chown www-data:www-data /var/www

Set the IP variable, imported /etc.

export IP='192.168.0.1'
# mkdir ~/etc
cp /etc/mtab ~/etc/ && \
cp /etc/init.d/makedev ~/etc/init.d/ && \
rsync -e ssh -avz root@$IP:/etc/* /etc/ && \
cp -R ~/etc/* /etc/

I remarked out mkdir because I have already created ~/etc in the model vm.

nano /etc/network/interfaces && mkdir -p ~/etc/network && cp /etc/network/interfaces ~/etc/network/

mkdir -p /var/www
rsync -e ssh -avz root@$IP:/var/www/* /var/www/
rsync -e ssh -avz root@$IP:/home/* /home/

To migrate MySQL, I stopped MySQL on the live server and ran

rsync -e ssh -avz $IP:/var/lib/mysql /var/lib/

I will reference my notes here I am sure kanga: Migrating MySQL

Next we are getting the package list from the running server and applying it to this one. In general, take the defaults to NOT change settings.

ssh $IP 'dpkg --get-selections' >~/selections.dpkg && \
apt-get update && \
dpkg --set-selections  < ~/selections.dpkg && \
apt-get dselect-upgrade

I started screen, then ran apt-get dselect-upgrade to start the process. Then I used Ctrl+a d to detach the screen. I can do other things, and disconnect from ssh. When I return I will screen -r to reattach and continue.

If you get “4gb seg fixup” errors, this will probably fix it.

apt-get install libc6-xen
echo "hwcap 0 nosegneg" > /etc/ld.so.conf.d/nosegneg.conf
ldconfig -v -p 2>&1 | grep libc.so
ldconfig

Everything works…
Except Drupal on www.guildplace.org
Ahh, ha! An error about /tmp. I thought I fixed this in the model, but it would appear I did not, or during the filesystem rotation it got broken.

chmod 1777 tmp

gopher vm

Thursday, August 9th, 2007

This server provides smtp, pop3 and imap. It also provides the ssl versions of these protocols. The old server provided squirrelmail on apache, but I’m not going to impliment that on this server.

The physical server is still running sarge. The vm is running etch. With gopher that jump worked, but this is a much more complex host. I tried deploying gopher across versions and ran in to problems, so I upgraded the physical server and made sure everything works first. I will do it this way in the future as well.

After a PAINFUL experience because a courier directive changed…
LDAP_SERVER changed to LDAP_URL
This is a great URL for troubleshooting http://www.courier-mta.org/authlib/README.authdebug.html

# cd /xen
# mkdir gopher
# cd gopher/
# tar xjvf ../debian-4.0-20070801.tar.bz2
debian-4.0.img
debian-4.0.xen3.cfg
debian.swap

The sizes were 500M, 20M and 200M and they rounded up by lvcreate.

lvcreate -L512M -n gopher-usr VolGroup00 && \
lvcreate -L32M -n gopher-home VolGroup00 && \
lvcreate -L224M -n gopher-tmp VolGroup00 && \
lvcreate -L5G -n gopher-var VolGroup00
mkfs -t ext3 /dev/VolGroup00/gopher-usr
mkfs -t ext3 /dev/VolGroup00/gopher-var
mkfs -t ext3 /dev/VolGroup00/gopher-tmp
mkfs -t ext3 /dev/VolGroup00/gopher-home

Make the last 3 bytes of the MAC:

dd if=/dev/urandom bs=1 count=3 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | tr -d ' ' | tr '[a-f]' '[A-F]'

/vserver/gopher/gopher.cfg

kernel = "/boot/vmlinuz-2.6-xenU"
memory = 384
name = "gopher"
vif = [ 'bridge=xenbr0,mac=00:16:3e:CF:AA:21' ]
dhcp = "dhcp"
disk = ['file:/xen/gopher/debian-4.0.img,sda1,w'
, 'file:/xen/gopher/debian.swap,sda2,w'
, 'phy:VolGroup00/gopher-usr,sda5,w'
, 'phy:VolGroup00/gopher-home,sda6,w'
, 'phy:VolGroup00/gopher-tmp,sda7,w'
, 'phy:VolGroup00/gopher-var,sda8,w'
]
root = "/dev/sda1 ro"
ramdisk = "/boot/initrd-2.6-xenU.img"

I linked the config and restarted the server to test.

ln -s /xen/gopher/gopher.cfg /etc/xen/auto/gopher.cfg

xm create -c gopher.cfg
192.168.0.218
ssh’d to the VM, default password of “password”

Created flip script. vm flip filesystems

~/flip sda5 usr
mount /dev/sda6 /home
# ~/flip sda6 home
# home is empty so it just gives an error. just umount and then mount it to /home
# maybe I will fix this... or not.
~/flip sda7 tmp
~/flip sda8 var

Set the IP variable, imported /etc.

export IP='192.168.0.1'
mkdir ~/etc
cp /etc/mtab ~/etc/ && \
cp /etc/init.d/makedev ~/etc/init.d/ && \
rsync -e ssh -avz root@$IP:/etc/* /etc/ && \
cp -R ~/etc/* /etc/

Change hd? to sd?. Used nano and remarked out cd and floppy. Made note of swap, sda9.
I started a ~/etc/ so that if we need to resync etc we just copy it back to /etc.

mv /etc/fstab{,~} && sed 's#/hd#/sd#' /etc/fstab~ >/etc/fstab
nano /etc/fstab && cp /etc/fstab ~/etc/

I changed the IP to a temp address during the initial reboot. This can cause a little trouble, but less than having 2 machines with the same IP.

nano /etc/network/interfaces && cp /etc/network/interfaces ~/etc/network/

grep -i documentroot /etc/apache-ssl/httpd.conf
DocumentRoot /var/www/ssl

mkdir -p /var/spool
rsync -e ssh -avz root@$IP:/var/spool/* /var/spool/
mkdir -p /var/www
rsync -e ssh -avz root@$IP:/var/www/* /var/www/
mkdir -p /var/mail
rsync -e ssh -avz root@$IP:/var/mail/* /var/mail/

Fixed in the model, this is no longer needed.


As you may remember, I had to create a script to create /dev/urandom and start ssh. Debian 4.0 added rc.local and broke the link I made before.
There is an exit 0 that is required, but it needs to be at the bottom of the file. I started nano to remove exit 0 from the middle of the file and put it at the end.

cat /etc/init.d/local >>/etc/rc.local && nano /etc/rc.local


Next we are getting the package list from the running server and applying it to this one. In general, take the defaults to NOT change settings.

ssh $IP 'dpkg --get-selections' >~/selections.dpkg && \
dpkg --set-selections  < ~/selections.dpkg && \
apt-get update && \
apt-get dselect-upgrade

If you get “4gb seg fixup” errors, this will probably fix it.

apt-get install libc6-xen
echo "hwcap 0 nosegneg" > /etc/ld.so.conf.d/nosegneg.conf
ldconfig -v -p 2>&1 | grep libc.so
ldconfig

I stopped postfix and ran this until there was nothing left to update.

rsync -e ssh -avz --delete root@$IP:/var/mail/* /var/mail/

restarted

restarting: shutdown -r now

kanga vm

Monday, August 6th, 2007

The steps I took while deploying kanga.

I made a new directory for kanga and unpacked the tar of Debian 4.0 I created in CentOS 5 Xen

mkdir /vserver/kanga
cd /vserver/kanga
tar xjvf ../debian-4.0-20070801.tar.bz2
lvcreate -L250M -n kanga-usr VolGroup00
lvcreate -L250M -n kanga-var VolGroup00
lvcreate -L50M -n kanga-tmp VolGroup00
lvcreate -L20M -n kanga-home VolGroup00
mkfs -t ext3 /dev/VolGroup00/kanga-usr
mkfs -t ext3 /dev/VolGroup00/kanga-var
mkfs -t ext3 /dev/VolGroup00/kanga-tmp
mkfs -t ext3 /dev/VolGroup00/kanga-home

I changed the config file. I have decided to leave the img filename the same and use a unique directory and config name for each vm. I will name the startup link based on the host as well.
/vserver/kanga/kanga.cfg

kernel = "/boot/vmlinuz-2.6-xenU"
memory = 64
name = "kanga"
vif = [ 'bridge=xenbr0,mac=00:16:3e:D4:5D:6A' ]
dhcp = "dhcp"
disk = ['file:/xen/kanga/debian-4.0.img,sda1,w', 'file:/xen/kanga/debian.swap,sda2,w', 'phy:VolGroup00/kanga-usr,sda5,w', 'phy:VolGroup00/kanga-var,sda6,w', 'phy:VolGroup00/kanga-tmp,sda7,w', 'phy:VolGroup00/kanga-home,sda8,w']
root = "/dev/sda1 ro"
ramdisk = "/boot/initrd-2.6-xenU.img"

I linked the config and restarted the server to test.

ln -s /vserver/kanga/kanga.cfg /etc/xen/auto/kanga.cfg

ran “xm console kanga” to get the DHCP address
192.168.0.197

To rotate the base filesystems to the partitions, I wrote a small script. Why ride your bike when a phone call could accomplish the same thing?
vm flip filesystems
I created the file ~/flip and made it executable. To use it I run:

~/flip sda5 usr

And it moves /usr to /dev/sda5, cleans up and then mounts

I had to rebuild the model image, and at that time I add rsync.


You don’t have to assign a variable. I am for 2 reasons: It is shorter, and I don’t trust you with all my IP layout.
/etc/mtab is a record of what is mounted, and so you don’t really want the one from the physical server right now. It really causes confusion.
Since the physical machine was running ide and the vms will be sd, we change fstab accordingly.
Remark out the cd-rom and floppy drivers.

export IP='192.168.0.1'
cp /etc/mtab /root/mtab && rsync -e ssh -avz root@$IP:/etc/* /etc/ && cp /root/mtab /etc/mtab
mv /etc/fstab{,~} && sed 's#/hd#/sd#' /etc/fstab~ >/etc/fstab
nano /etc/fstab

I changed the IP to a temp address during the initial reboot. This can cause a little trouble, but less than having 2 machines with the same IP.

nano /etc/network/interfaces

I’m going to migrate /var/spool and /var/www. /var/spool is where cron jobs are kept, and /var/www are the web files.

mkdir -p /var/spool
rsync -e ssh -avz root@$IP:/var/spool/* /var/spool/
mkdir -p /var/www
rsync -e ssh -avz root@$IP:/var/www/* /var/www/

As you may remember, I had to create a script to create /dev/urandom and start ssh. Debian 4.0 added rc.local and broke the link I made before.
There is an exit 0 that is required, but it needs to be at the bottom of the file. I started nano to remove exit 0 from the middle of the file and put it at the end.

cat /etc/init.d/local >>/etc/rc.local && nano /etc/rc.local

I’m not sure why I ran this again, maybe I’ll remember later. nano /etc/network/interfaces

Next we are getting the package list from the running server and applying it to this one. In general, take the defaults to NOT change settings.

ssh $IP 'dpkg --get-selections' >~/selections.dpkg && \
dpkg --set-selections  < selections.dpkg && \
apt-get update && \
apt-get dselect-upgrade

If you get “4gb seg fixup” errors, this will probably fix it.

apt-get install libc6-xen
echo "hwcap 0 nosegneg" > /etc/ld.conf.so.d/nosegneg.conf
ldconfig -v -p 2>&1 | grep libc.so
ldconfig

restarting: shutdown -r now

Migrating MySQL is on a seperate blog, kanga: Migrating MySQL

owl partitions

Sunday, August 5th, 2007
# lvscan
  ACTIVE            '/dev/VolGroup00/LogVol03' [1.00 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol02' [3.91 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol04' [3.91 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol00' [3.91 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol01' [3.91 GB] inherit
  ACTIVE            '/dev/VolGroup00/LogVolStore01' [97.66 GB] inherit
  ACTIVE            '/dev/VolGroup00/kanga-var' [256.00 MB] inherit
  ACTIVE            '/dev/VolGroup00/kanga-tmp' [64.00 MB] inherit
  ACTIVE            '/dev/VolGroup00/kanga-usr' [512.00 MB] inherit
  ACTIVE            '/dev/VolGroup00/kanga-home' [64.00 MB] inherit
  ACTIVE            '/dev/VolGroup00/gopher-usr' [512.00 MB] inherit
  ACTIVE            '/dev/VolGroup00/gopher-home' [32.00 MB] inherit
  ACTIVE            '/dev/VolGroup00/gopher-tmp' [224.00 MB] inherit
  ACTIVE            '/dev/VolGroup00/gopher-var' [5.00 GB] inherit
# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
/dev/sdb2 on /boot-spare type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/mapper/VolGroup00-LogVol03 on /home type ext3 (rw)
/dev/mapper/VolGroup00-LogVol02 on /tmp type ext3 (rw)
/dev/mapper/VolGroup00-LogVol01 on /var type ext3 (rw)
/dev/mapper/VolGroup00-LogVolStore01 on /vserver type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)