Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, January 28, 2009

Howto: Xen Bridging with Static and DHCP NICs

I have been meaning to figure out how to put Xen virtual machines on different networks for over a year. Every once in a while I would start poking at it, but never could get it to work. Now a project I'm doing requires VMs on different networks, and to easily be able to switch them, so I finally took the time to learn. Notably it is more linux networking 101 than anything.

This would have been relatively easy if both NICs used static IPs, this tutorial would have worked more or less out of the box. It turns out that throwing dhcp in the mix really screws with routing and dns. Even worse the dhcp daemon running in the background keeps screwing it up unless you disable it.

-------------------------------------------------

Howto:

Note: This is on Ubuntu 8.04 and Xen 3.2. I want dom0 to access the internet via a static ip on eth0.

First create /etc/xen/scripts/multi-network-bridge then put the following in it:


#!/bin/sh
/etc/xen/scripts/network-bridge $@ vifnum=1 netdev=eth1 bridge=xenbr1
/etc/xen/scripts/network-bridge $@ vifnum=0 netdev=eth0 bridge=xenbr0

ifconfig xenbr1 up
ifconfig xenbr0 up
ip route flush table main
ip route add X.X.X.X/X dev xenbr0
ip route add default via X.X.X.X
cp /etc/resolv.conf.bak /etc/resolv.conf


Where X.X.X.X/X is your static network such as 192.168.1.0/24 and X.X.X.X is your static gateway (192.168.1.1). /etc/resolv.conf.bak is a copy of your static dns servers.

Now make the script executable and disable the dhcp daemon:


sudo chmod +x /etc/xen/scripts/multi-network-bridge
sudo update-rc.d -f dhcdbd remove


Finally, find the line in /etc/xen/xend-config.spx that has "(network-script network-bridge)" and change it to "(network-script multi-network-bridge)".

Now check to make sure that /etc/network/interfaces is configured properly, mine looks like:


auto lo
iface lo inet loopback

auto eth1
iface eth1 inet dhcp

auto eth0
iface eth0 inet static
address x.x.x.x
gateway x.x.x.x
netmask x.x.x.x



For DomUs to use the bridge you need to change the cfg file to look like:

vif = [ 'mac=xx:xx:xx:xx:xx:xx,ip=x.x.x.x,bridge=xenbr0' ]

For the static network, or:


dhcp = 'dhcp'
vif = [ 'mac=xx:xx:xx:xx:xx:xx,bridge=xenbr1' ]

For the dhcp network.


Reboot Dom0 to make sure that networking comes back right.

------------------------------------------------

If you don't specifically name the bridges, then they will automatically be named eth0 and eth1 (and you probably won't have to do the ifconfig xxxx up either). This makes the output of ifconfig look slightly more normal.

A couple other things I found out along the way:

1. The interfaces should already be up and configured properly (with ips) before the bridge script is run. This should happen automatically if /etc/network/interfaces is set up properly.

2. Dom0 connects to the bridge directly, which is why it has an ip assigned.

3. "ip route" and "brctl show" are your friends.

4. The tapX devices are from hardware virtual machines.


Note: Doing this can confuse firefox in to thinking it is offline. If you have issues with firefox make sure File->Work Offline is unchecked (sometimes checking it then unchecking it helps).


Update:

Here is my new multi-network-bridge script:


#!/bin/sh
/etc/xen/scripts/network-bridge $@ vifnum=1 netdev=eth1
/etc/xen/scripts/network-bridge $@ vifnum=0 netdev=eth0

ip route flush table main
ip route add X/X dev eth0
ip route add default via X
cp /etc/resolv.conf.bak /etc/resolv.conf


If you don't specify a bridge then it defaults to eth0.

Wednesday, December 17, 2008

Howto Ubuntu Intrepid Ibex 8.10 Xen Dom0

Intro

So... much to my dismay Ubuntu quit supporting Xen as a Dom0. The default kernel intrepid ships with is supposed to support being a domU, but that is just because of the addition of paravirt_ops into the standard linux kernel.

Anyway, they aren't supporting xen anymore because they are going with KVM as their server virtualization technology, and virtualbox as their destkop virt tech. Not that I am opposed to KVM, it just seems like this is a bit more complicated than xen-create-image... especially since I am not familiar with it.

As it so happens there are a couple branches of 2.6.27 linux xen kernels, and while they are not official, they seem to be working well. I think that the plan is to integrate dom0 functionality into the paravirt_ops, which basically means creating the backend drivers, but since that is not completed yet, we will need to use one of these unstable branches to get a functioning dom0 with a recent kernel (although they seem very stable to me -- the one I'm using is from Novell Suse).


Howto:

Install a fresh Ubuntu Server 8.10 AMD64. I opted for lvm, but that is certainly not necessary. Luckily Xen 3.3.0 is in the intrepid repos, unfortunately it doesn't have a compatible linux kernel, so we have to download, compile, and install one.

Note: MAKE SURE ITS AMD64, apparently there are build problems with 32bit. Besides there really is no point to have a 32bit dom0 -- it can't see more than like 3gb of ram, and you can always make 32bit domUs.


sudo apt-get install ubuntu-xen-server build-essential libncurses5-dev gawk mercurial
mkdir -p /home/#user#/build/linux-2.6.27-xen
cd /usr/src/
sudo hg clone http://xenbits.xensource.com/ext/linux-2.6.27-xen.hg
cd linux-2.6.27-xen.hg
make O=/home/#user#/build/linux-2.6.27-xen/ menuconfig
make O=/home/#user#/build/linux-2.6.27-xen/ -j12 #put number of cores X1.5 here#
sudo make O=/home/#user#/build/linux-2.6.27-xen/ modules_install install
sudo depmod 2.6.27.5
sudo mkinitramfs -o /boot/initrd-2.6.27.5.img 2.6.27.5


The most important part here is the menuconfig, by default none of the xen stuff is enabled. I had to disable 10000 Mbps ethernet (ixgbe), the slub allocator, and perfmon (or maybe I selected that and shouldn't have) because they wouldn't compile. You can either build two kernels, one with backend drivers (dom0), and the other with frontend drivers (domUs), or you can put both of them in one build and use the kernel for both dom0 and domUs. See this and this for various xen options. Pushing h in the menuconfig helps a lot

Now you have to edit your /boot/grub/menu.lst to boot to the new kernel under xen. It should look something like:


title Xen 3.3 / Ubuntu 8.10, kernel 2.6.27-xen
uuid 538bd858-c116-45e8-bbb5-93c073464889
kernel /xen-3.3.gz
module /vmlinuz-2.6.27.5 root=/dev/mapper/LVMVG-LV ro console=tty0
module /initrd-2.6.27.5.img


You should now be able to boot in to xen by simply rebooting. If your dom0 doesn't come up then simply reboot and change the grub selection to the non-xen and fix whatever it is you broke ;p.

Oddly the ubuntu-xen-server doesn't include hardy or intrepid configs for it's xen tools configs. This will fix that though:


sudo ln -s /usr/lib/xen-tools/edgy.d /usr/lib/xen-tools/hardy.d
sudo ln -s /usr/lib/xen-tools/edgy.d /usr/lib/xen-tools/intrepid.d


Now you can create an intrepid image using:


sudo xen-create-image --hostname=somehost.example.com --size=10Gb --swap=2Gb --ide --mac=00:00:00:00:00:00 --memory=2Gb --arch=amd64 --lvm=VolumeGroup --kernel=/boot/vmlinuz-2.6.27.5 --initrd=/boot/initrd-2.6.27.5.img --install-method=debootstrap --dist=intrepid --mirror=http://archive.ubuntu.com/ubuntu/ --passwd --accounts --dhcp

---------------------Cut---------------------------
You might be able to fix this somewhere in the default config, but you need to change the console both in the generated .cfg file and in the actual disk image it created:


sudo echo "console='xvc0'" >> /etc/xen/somehost.example.com.cfg
sudo mkdir /media/domudisk
sudo mount /dev/mapper/LVMVGroup--somehost.example.com--disk /media/domudisk
cd /media/domudisk/etc/event.d/
sudo nano tty1
cd ~
sudo umount /media/domudisk


On the last line change 'tty1' to 'xvc0'.
---------------------------------------------------
Update: You can fix this with a config:

sudo su
echo "console='xvc0'" >> /etc/xen-tools/xm.tmpl

(sudo echo doesn't work for me...)
Then add the line "sed -i "s/tty1/${serial_device}/" ${prefix}/etc/event.d/tty1" to /usr/lib/xen-tools/edgy.d/30-disable-gettys, so that last if section reads:

#
# Are we using an alternative serial device?
#
if [ ! -z "${serial_device}" ]; then

serial_device=`basename ${serial_device}`
echo "Setting DomU Serial Device to $serial_device"
# Let the user know.
logMessage "Replacing default serial device (tty1) with ${serial_device}"

# replace existing device.
sed -i "s/tty1/${serial_device}/" ${prefix}/etc/event.d/tty1
mv ${prefix}/etc/event.d/tty1 ${prefix}/etc/event.d/${serial_device}
sed -i -e s/tty1/${serial_device}/ ${prefix}/etc/inittab

# make sure that it is allowed to login.
echo $serial_device >> ${prefix}/etc/securetty
echo "Serial device set"
echo $serial_device
fi


and, finally, uncomment "serial_device = xvc0" and "disk_device = xvda" in /etc/xen-tools/xen-tools.conf

There are other goodies in /etc/xen-tools/xen-tools.conf (such as defaults for image creation) too.


The vanilla kernel that ships with Ubuntu as well as building a new kernel from kernel.org (if you enable the paravirt_ops and frontend drivers), will both run as domUs, you simply have to change the hda/sda references in the cfg file to xvda manually, or you can uncomment the "disk_device = xvda" in /etc/xen-tools/xen-tools.conf. MAKE SURE YOU COPY YOUR /lib/modules/2.6.27.whatever over to the domU drive!!! xen-tools will not do this for you (without more script mods at least -- a simple hack would be to replace what /usr/lib/xen-tools/edgy.d/80-install-modules does with cp -r /usr/lib/modules/* ${prefix}/usr/lib/modules).

To build the latest linux kernel:

mkdir -p /home/user/build/linux-2.6.27/
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-2.6.27.y.git
cd linux-2.6.27.y
make O=/home/#user#/build/linux-2.6.27-xen/ menuconfig
make O=/home/#user#/build/linux-2.6.27-xen/ -j12 #put number of cores X1.5 here#
sudo make O=/home/xepra/build/linux-2.6.27.y/ modules_install install
depmod 2.6.27.9
mkinitramfs -o /boot/initrd.img-2.6.27-9 2.6.27.9


Notes:

I will update with some more details... hopefully

On another note -- I actually did this with a gentoo install cd initially and booted directly to a xen kernel. It worked surprisingly well, especially since I am a gentoo neophyte, but there weren't any image creation tools. After manually creating a domU and getting it running I had all sorts of networking problems that I never had with Ubuntu... so I went back to Ubuntu.

I also went through this process on Debian lenny, but also had some problems; I think xen 3.3 wasn't in the repos so I had to compile it from scratch... I also was using grub2, which was a bit different, but not hard to figure out and get working.

Update: It looks like Boris Derzhavets used this entry and did a follow up with a lot more detail, screen shots, and output.

Saturday, October 4, 2008

Multiple Desktops in Linux (even Remote ones...)

Although I love the ability to control Linux PCs and servers remotely with ssh and X tunneling, I was never satisfied with VNC as a complete Remote Desktop solution. For starters it is insecure and to secure it you have to jump through a couple hoops. The biggest problem, however, is that you already have to have a session running on the remote computer in order to use VNC.

I wanted an easy to use, built-in, secure way to get a complete remote desktop on a Linux machine at any time, from anywhere.

Luckily I found one:

1) go to a new terminal via ctrl-alt-f2 and login.
2) type "xinit -- :1". This should pop up a new instance of x with a terminal running. I had to mouse over the terminal to type.
3) type "ssh -CX user@host" and login to the remote server (C is compression...)
4) now type "gnome-session" or "startkde" or whatever desktop you want to start.

Thats it. No special programs and it is already encrypted through an ssh tunnel =).

To close this desktop type "ctrl-alt-backspace".
To get back to your primary desktop type "ctrl-alt-f7".
To switch back to the remote desktop type "ctrl-alt-f9".

You can open another desktop if you would like even with these two open, just use "xinit -- :2" which will be on the f10 terminal... You can do as many as 5 or 6.


If you want another local, rather than remote, desktop you can just ignore the ssh step (3) and just start the new desktop locally. This will allow you to run kde, gnome, and xcfe side by side and switch between them with a single key combo.


Also, you may find it useful to know that many programs have a --desktop option that allows you to open programs on any desktop from any terminal. ie "firefox --desktop :1". If you have multiple monitors you can even do "firefox --desktop :1.1" to specify the second monitor.


If you want to do this from windows just use a program like Xming :). Although the beta xrdp project is kind of interesting, it still seems a bit rough around the edges. The only thing that this doesn't really allow you to do is resume already running sessions :/

Update: What I was looking for was Xephyr. Works like a charm: http://ubuntuforums.org/showthread.php?p=3816948#post3816948 (The whole terminal thing is still cool tho =p)

Friday, August 29, 2008

Darwin Streaming Server 6.0.3 on Linux

Quick tutorial for installing DSS on Ubuntu 8.04.1 64bit (x86_64).

Most of these details can be found here: http://dss.macosforge.org/trac/ticket/6

Hopefully they will integrate these patches in to the next release, but until then here are the build instructions for Ubuntu:

Download DSS 6.0.3: http://static.macosforge.org/dss/downloads/DarwinStreamingSrvr6.0.3-Source.tar

Download this patch: http://dss.macosforge.org/trac/raw-attachment/ticket/6/dss-6.0.3.patch (Thank you Sverker Abrahamsson!)

And this patch: http://dss.macosforge.org/trac/raw-attachment/ticket/6/dss-hh-20080728-1.patch

Finally get the modified Install script: http://dss.macosforge.org/trac/raw-attachment/ticket/6/Install

The basic process is:

1. Get the build dependencies from the repositories.
2. Set up the qtss user (this is because the Install script does it in a way that is incompatible with Ubuntu)
3. Extract the source code.
4. Apply both patches.
5. Replace the Install script and chmod +x it.
6. Compile.
7. Install.

Notably for ssl admin you need the openssl and libnet-ssleay-perl packages, unfortunately even with these packages I was unable to get ssl admin to work.

I created the modified Install script; you can do a diff with the original if you want to see what I changed. Mostly just the paths were broken, but I am guessing that some other modules and such will probably not work.

Here is the bash script I used to do everything (including automatically download everything):


#!/bin/bash

sudo apt-get install build-essential wget
sudo addgroup --system qtss
sudo adduser --system --no-create-home --ingroup qtss qtss

wget http://static.macosforge.org/dss/downloads/DarwinStreamingSrvr6.0.3-Source.tar
tar -xvf DarwinStreamingSrvr6.0.3-Source.tar
mv DarwinStreamingSrvr6.0.3-Source DarwinStreamingSrvr6.0.3-Source.orig
wget http://dss.macosforge.org/trac/raw-attachment/ticket/6/dss-6.0.3.patch
patch -p0 < dss-6.0.3.patch
mv DarwinStreamingSrvr6.0.3-Source.orig DarwinStreamingSrvr6.0.3-Source
wget http://dss.macosforge.org/trac/raw-attachment/ticket/6/dss-hh-20080728-1.patch
patch -p0 < dss-hh-20080728-1.patch
#need to answer n then y
cd DarwinStreamingSrvr6.0.3-Source
mv Install Install.orig
wget http://dss.macosforge.org/trac/raw-attachment/ticket/6/Install
chmod +x Install
./Buildit
sudo ./Install



Update 2/2/2009: I changed the links to all point to dss.macosforge.org, which is a much more reliable host. Everyone should also take a look at that thread, as there are a lot of updates, including a newer patch from Horace Hsieh. I haven't played with this in a while, but if I get a chance I will try to update this with the newer patch. Please let me know if there are any problems (I just turned comment notifications on :/).