Tuesday, September 13, 2011

Dual booting RHEL6 and Citrix Xenserver 6 beta

If you have limited hardware resources available and you want to test multiple virtualization solution then dual boot comes to the rescue. Citrix Xenserver claims the whole disk for itself, so we need at least two disks. If you have raid card in the server, just create 2 or more logical disks. Otherwise you need at least 2 physical disks.
Install Xenserver 6 beta on the first disk (sda in my case). After that install RHEL 6 (or centos6 or scientific linux 6 or ..) on the second disk (sdb in my case) and install grub on the first disk (sda). Don't modify the grub during RHEL install, we will do that later. After the install boot in RHEL6 (Well xenserver is out of the questions since our grub for now only can boot rhel6).
Mount the root disk of the xenserver in rhel6 /mnt and get the boot params:
[root@host1 ~]# mount /dev/sda1 /mnt
[root@host1 ~]# cat /mnt/boot/extlinux.conf
# location mbr
serial 0 115200
default xe
prompt 1
timeout 50

label xe
  # XenServer
  kernel mboot.c32
  append /boot/xen.gz dom0_mem=752M lowmem_emergency_pool=1M crashkernel=64M@32M console= vga=mode-0x0311 --- /boot/vmlinuz-2.6-xen root=LABEL=root-bhsbdzef ro xencons=hvc console=hvc0 console=tty0 quiet vga=785 splash --- /boot/initrd-2.6-xen.img

label xe-serial
  # XenServer (Serial)
  kernel mboot.c32
  append /boot/xen.gz com1=115200,8n1 console=com1,vga dom0_mem=752M lowmem_emergency_pool=1M crashkernel=64M@32M --- /boot/vmlinuz-2.6-xen root=LABEL=root-bhsbdzef ro console=tty0 xencons=hvc console=hvc0 --- /boot/initrd-2.6-xen.img

label safe
  # XenServer in Safe Mode
  kernel mboot.c32
  append /boot/xen.gz nosmp noreboot noirqbalance acpi=off noapic dom0_mem=752M com1=115200,8n1 console=com1,vga --- /boot/vmlinuz-2.6-xen nousb root=LABEL=root-bhsbdzef ro console=tty0 xencons=hvc console=hvc0 --- /boot/initrd-2.6-xen.img

label fallback
  # XenServer (Xen 4.1.1 / Linux 2.6.32.12-0.7.1.xs5.9.960.497.170655xen)
  kernel mboot.c32
  append /boot/xen-4.1.1.gz dom0_mem=752M lowmem_emergency_pool=1M crashkernel=64M@32M --- /boot/vmlinuz-2.6.32.12-0.7.1.xs5.9.960.497.170655xen root=LABEL=root-bhsbdzef ro xencons=hvc console=hvc0 console=tty0 --- /boot/initrd-2.6.32.12-0.7.1.xs5.9.960.497.170655xen.img

label fallback-serial
  # XenServer (Serial, Xen 4.1.1 / Linux 2.6.32.12-0.7.1.xs5.9.960.497.170655xen)
  kernel mboot.c32
  append /boot/xen-4.1.1.gz com1=115200,8n1 console=com1,vga dom0_mem=752M lowmem_emergency_pool=1M crashkernel=64M@32M --- /boot/vmlinuz-2.6.32.12-0.7.1.xs5.9.960.497.170655xen root=LABEL=root-bhsbdzef ro console=tty0 xencons=hvc console=hvc0 --- /boot/initrd-2.6.32.12-0.7.1.xs5.9.960.497.170655xen.img

We have serveral boot labels, but I'm only interested in the first one. If you want more, you can add as many as you like.
Now we update our grub.conf with the info from the append line. Just after the append we find the kernel info, just until the first ---. After that we have the first module info and after the second --- we have the second module info. So my /etc/grub.conf (which is a link to /boot/grub/grub.conf) looks like:
default=0
timeout=25

title Red Hat Enterprise Linux (2.6.32-131.0.15.el6.x86_64)
	root (hd1,0)
	kernel /vmlinuz-2.6.32-131.0.15.el6.x86_64 ro root=/dev/mapper/vg_kvmtest1-root rd_LVM_LV=vg_kvmtest1/root rd_LVM_LV=vg_kvmtest1/swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet
	initrd /initramfs-2.6.32-131.0.15.el6.x86_64.img

title Citrix Xenserver 6.beta
	root (hd0,0)
	kernel /boot/xen.gz dom0_mem=752M lowmem_emergency_pool=1M crashkernel=64M@32M console= vga=mode-0x0311
	module /boot/vmlinuz-2.6-xen root=LABEL=root-bhsbdzef ro xencons=hvc console=hvc0 console=tty0 quiet vga=785 splash
	module /boot/initrd-2.6-xen.img
If you use ssh to connect to your servers (who doesnt?) and you use the same ip for rhel6 as xenserver, it can be handy to set both host keys the same (otherwise you will be constantly editing your know_hosts file). With still /mnt mounted you can:
[root@host1 ~]# \cp /mnt/etc/ssh/ssh_host* /etc/ssh/
[root@host1 ~]# /etc/jnit.d/sshd restart

Tuesday, August 30, 2011

Using mrepo on rhel6

Mrepo is a very handy tool written by Dag Wieers (@dagwieers) to download all rhn updates. Unfortunately, some things broke on rhel6 (dropped pkgs, versions, ..). The current mrepo el6 rpm therefore is not directly usable. Follow these steps if you want a working mrepo on rhel without patching. This howto is also useful for people in how to setup mrepo for rhn updates download in general. Please make sure you have the needed rhn subscriptions for your systems.

1. download latest mrepo from Github since these have already the needed patches:
https://github.com/dagwieers/mrepo

2. Download rhpl from one of dag repo mirrors. rhpl was dropped in rhel6. Dag has made a feature request to mrepo on Aug 1st 2011 to remove rhpl from mrepo so that the extra pkg would no longer be needed. But until then you still need the rhpl
ftp://ftp.univie.ac.at/systems/linux/dag/redhat/el6/en/x86_64/dag/RPMS/rhpl-0.221-2.el6.rf.x86_64.rpm

3. Untar / unzip the latest mrepo and install it (you can also first build an rpm of it by running make rpm. But then you will need the necessary build rpms installed)
# tar xzf dagwieers-mrepo-736c07a.tar.gz

# cd dagwieers-mrepo-736c07a
# make install
install -Dp -m0755 gensystemid /usr/bin/gensystemid
install -Dp -m0755 mrepo /usr/bin/mrepo
...
install -Dp -m0644 config/mrepo.logrotate /etc/logrotate.d/mrepo
#


4. Generate the /etc/sysconfig/rhn/up2date-uuid file if you don't have one yet
# UUID=$(uuidgen)

# /bin/echo -e "uuid[comment]=Universally Unique ID for this server\nrhnuuid=$UUID" > /etc/sysconfig/rhn/up2date-uuid


5. Edit the /etc/mrepo file for your needs. Mine looks like this:
# cat /etc/mrepo.conf

[main]
srcdir = /export/mrepo
wwwdir = /export/mrepo
confdir = /etc/mrepo.conf.d
arch = x86_64
mailto = xxxxxxx
smtp-server = localhost
rhnlogin = xxx:xxx


6. Create a conf file for each rhel version you want to download in /etc/mrepo.conf.d/. I only need the rhel6 x86_64 updates. So this is how mine looks:
# cat /etc/mrepo.conf.d/rhel6-x86_64.conf 

[rhel6-x86_64]
name = Red Hat Server ($arch)
release = 6
arch = x86_64
metadata = repomd yum repoview

updates = rhns:///rhel-$arch-server-$release
#fastrack = rhns:///rhel-$arch-server-fastrack-$release
#rhn-tools = rhns:///rhn-tools-rhel-$arch-server-$release
#optional = rhns:///rhel-$arch-server-optional-$release
supplementary = rhns:///rhel-$arch-server-supplementary-$release


7. Remember that for each repo you download, you need a systemid file in the mrepo folder for that repo. So my mrepo dir is /export/mrepo (mrepo.conf) and the server config is rhel6-x68_64 (rhel6-x86_64.conf). So the systemid file should go into the folder /export/mrepo/rhel6-x68_64.
# cp /etc/sysconfig/rhn/systemid /export/mrepo/rhel6-x86_64/


8. My system has a systemid file because it was already registered with rhn. If you want to download other version / arch repo's on the same system, you can use gensystemid to create one
# gensystemid -r 6Server -a i386 /export/mrepo/rhel6-i386


9. All done. Now run mrepo
# mrepo -uvv

Verbosity set to level 2
Using configfile /etc/mrepo.conf
Setting option confdir in section [main] to: /etc/mrepo.conf.d
Setting option srcdir in section [main] to: /export/mrepo
Setting option wwwdir in section [main] to: /export/mrepo
Setting option mailto in section [main] to: xxxxxx
Setting option smtp-server in section [main] to: localhost
Setting option arch in section [main] to: x86_64
Setting option rhnlogin in section [main] to: xxx:xxx
rhel6-x86_64: Updating Red Hat Server (x86_64)
rhel6-x86_64: Mirror packages from rhns:///rhel-x86_64-server-supplementary-6 to /export/mrepo/rhel6-x86_64/supplementary
rhel6-x86_64: Repository supplementary changed (new: 28, removed: 1)
rhel6-x86_64: Mirror packages from rhns:///rhel-x86_64-server-6 to /export/mrepo/rhel6-x86_64/updates
...


10. mrepo has of course more useful options then just to download the updates from rhn. Have a look at the documentataion if you want for example want to include iso files or want run createrepo after the repos have been downloaded or if you want to download other repos then those from rhn.

I hope this quick how-to helps in getting you started with mrepo on rhel6.