Preparing for an LVM based Xen Guest Domain & Cloning the Host OS on the Guest Root Partition
Intended Audience:
If you may need a minimal Linux installation for your guest OS but If the host system has graphical desktop environments, office productivity applications and other packages not needed by the guest OS then cloning the host environment may not be the best approach and the users are advised to skip at this point and if on the other hand, you are confident that everything on your host operating system will be of use in the guest system, or are unconcerned about disk space then this approach will work well for you.
Tested host Machine: 10.65.70.1 (Dell 1)
Guest cloned : host-cloned-xenguest (10.65.70.111)
Preparing for an LVM based Xen Guest Domain & Cloning the Host OS on the Guest Root Partition
We are using the following logical volumes /dev/sdc5 and /dev/sdc6 to hold the root file system of the operating system and /dev/sdc7 for the guest swap space.
Device used from the storage
/dev/sdc5 9487 10156 5381743+ 8e Linux LVM
/dev/sdc6 10157 10826 5381743+ 8e Linux LVM
/dev/sdc7 10827 11851 8233281 82 Linux swap / Solaris
1) Converting Physical Disks into Physical Volumes
pvcreate /dev/sdc5 /dev/sdc6
2) Information about physical volumes can be obtained by running the pvdisplay tool:
pvdisplay
3) Now that we have two physical volumes the next step is to create a volume group to contain them.
The following command creates a volume group called xenvolg and assigns the /dev/sdc5 physical volume to it.
vgcreate xenvolg /dev/sdc5
4) Next we need to add the second physical volume to xenvolg, again using the vgextend command:
vgextend xenvolg /dev/sdc6
5) Use the vgdisplay command to list information about the new volume group.
vgdisplay xenvolg
6) Next step is to create a logical volume comprising the two physical volumes in our volume group to use for the root filesystem of our Xen guest domain (domU).
lvcreate -L 5300M -n xenlogvol xenvolg
7) Information about the logical volume may be accessed using the lvdisplay command.
lvdisplay /dev/xenvolg/xenlogvol
8) Creating a Filesystem on the Logical Volume
mkfs.ext3 /dev/xenvolg/xenlogvol
The root filesystem is now ready to be mounted and populated with system files.
9) Configuring the Swap Partition for the Xen Guest System.The mkswap command is used to configure this partition as swap space:
mkswap /dev/sdc7
10) Mounting the Root Filesystem
The following commands create a directory named /xen and then mount the filesystem located on /dev/XenVolG/XenLogVol at this location:
mkdir /xen
mount /dev/xenvolg/xenlogvol /xen/
11) Cloning the Host OS on the Guest Root Partition
One of the easiest ways to install the necessary files on the guest OS root filesystem is to simply copy the files from the host operating system. Before doing so, however, it is important to keep in mind a few points.
12) Firstly, the following steps will copy a considerable amount of files from the host operating system to the guest root filesystem. This may well be much more than is actually necessary.
13) For example, you may need a minimal Linux installation for your guest OS. If the host system has graphical desktop environments, office productivity applications and other packages not needed by the guest OS then cloning the host environment may not be the best approach.
14) If, on the other hand, you are confident that everything on your host operating system will be of use in the guest system, or are unconcerned about disk space then this approach will work well for you.
15) The following steps assume that the root filesystem for the Xen guest has been mounted in /xen
16) Having created the mount point and mounted our root filesystem image the next step is to copy the relevant files from the host operating system to guest filesystem image. Execute the following command to copy the required directories and files to the root filesystem (be very careful to substitute the correct destination path if you mounted the filesystem somewhere other than /xen):
cp -ax /{bin,dev,etc,lib,root,sbin,usr,var} /xen
17) Once the copy process is completed a number of directories need to be created (once again the following example assumes the image has been mounted at /xen):
mkdir /xen/{home,proc,opt,sys,tmp}
18) The tmp directory created above must have read/write access for all users. To ensure this the chmod command needs to be run:
chmod 777 /xen/tmp
19) Creating a Xen Configuration File
Now that we have physical disk partitions for the root filesystem and the swap space, and have populated the root filesystem with the necessary system files the next step is to create a Xen configuration file.
In this file we need to specify the kernel and initial RAM Disk image files together with directives to map the disk partitions to devices within the guest OS.
For the purposes of this example we will load the initial RAM disk and kernel images from the host operating system. These are typically located in the /boot directory. The kernel file typically begins with the name vmlinuz and the initial RAM disk begins with initrd. These two images are defined in the Xen configuration file using the kernel = and ramdisk = directives. For example:
kernel = "/boot/vmlinuz-2.6.18-128.el5xen"
ramdisk = "/boot/initrd-2.6.18-128.el5xen.img"
Next, the amount of memory to be allocated to the guest system is defined using the memory = directive. The following assigns 512Mb to the guest:
memory = 256
Each guest domain needs to have a name by which it can be referenced when using the Xen management tools. This is assigned using name = :
name = "host-cloned-xenguest"
Now we specify network configuration options. The following lines indicate to Xen that the IP address of the system will be assigned using DHCP and the empty vif line instructs Xen to use the default values for the network interface configuration:
vif = [ '' ]
dhcp = "dhcp"
Finally the disk = directive is used to map the xenlogvol logical volume we have created with a guest operating system device. The following lines map the root logical volume (reported by lvdisplay as being located at /dev/xenvolg/xenlogvol) and swap partition to /dev/hda1 and /dev/hda2 respectively and define the root filesystem as /dev/hda1):
disk = ['phy:xenvolg/xenlogvol,hda1,w', 'phy:sdc7,hda2,w']
root = "/dev/xvda1 ro"
Note that these device mappings will be needed when the fstab file is configured later in this chapter.
Bringing all these configuration lines together should result in the following configuration file which we will name host-cloned-xenguest
cat host-cloned-xenguest
##################################################################
name = "host-cloned-xenguest"
maxmem = 256
memory = 256
vcpus = 1
kernel = "/boot/vmlinuz-2.6.18-128.el5xen"
#ramdisk = "/boot/initrd-2.6.18-128.el5xen.img"
####Newly created initrd initialization RAM Disk without SCSI
ramdisk = "/boot/initrd-2.6.18-128.el5xen-no-scsi.img"
root = "/dev/hda1 ro"
on_poweroff = "destroy"
on_reboot = "destroy"
on_crash = "destroy"
vfb = [ "type=vnc,vncdisplay=0,vncunused=0,keymap=en-us" ]
disk = [ "phy:/dev/xenvolg/xenlogvol,hda1,w", "phy:/dev/sdc7,hda2,w" ]
vif = [ "mac=00:16:3e:2a:e9:1e,bridge=xenbr0,script=vif-bridge", ]
####################################################################
20) Configuring System Files for the Guest Operating System
It is important to keep in mind that at this point in the process we have copied all of the system files from our host operating system onto the disk image for our guest operating system. It is vital at this point, therefore, that we change any system configuration files to meet the requirements of our guest domain. Typical settings that will need to be changed are:
/etc/fstab
/etc/passwd
/etc/group
/etc/hosts
/etc/sysconfig/network
/etc/exports
The guest OS copy of the fstab file needs to be modified to reflect the device mappings in the Xen configuration file created above (recall that the root filesystem was mapped to /dev/hda1 and swap to /dev/hda2). For example:
vi /xen/etc/fstab
/dev/hda1 / ext3 defaults 1 1
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/hda2 swap swap defaults 0 0
21) Booting the Guest OS
Now all that remains is to boot the guest operating system. Before booting the guest system it is important to first unmount the guest root filesystem:
umount /xen
22) With the set up and configuration complete we are now ready to start up the guest OS. This is achieved using the xm create command:
xm create host-cloned-xenguest -c
The -c flag above instructs Xen to attach a console to the guest system so that we see output as the system boots. The following output displays the initial phases of a successful boot:
xm create host-cloned-xenguest -c
Using config file "/etc/xen/host-cloned-xenguest".
Started domain host-cloned-xenguest
Linux version 2.6.18-128.el5xen (mockbuild@hs20-bc1-5.build.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)) #1 SMP Wed Dec 17 12:22:24 EST 2008
BIOS-provided physical RAM map:
Xen: 0000000000000000 - 0000000010800000 (usable)
0MB HIGHMEM available.
264MB LOWMEM available.
NX (Execute Disable) protection: active
ACPI in unprivileged domain disabled
Built 1 zonelists. Total pages: 67584
Kernel command line: root=/dev/hda1 ro
Enabling fast FPU save and restore... done.
Enabling unmasked SIMD FPU exception support... done.
Initializing CPU#0
CPU 0 irqstacks, hard=c0744000 soft=c0724000
PID hash table entries: 2048 (order: 11, 8192 bytes)
Xen reported: 3192.204 MHz processor.
Console: colour dummy device 80x25
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Software IO TLB disabled
vmalloc area: d1000000-f4ffe000, maxmem 2d7fe000
Memory: 248960k/270336k available (2124k kernel code, 12848k reserved, 877k data, 176k init, 0k highmem)
Checking if this processor honours the WP bit even in supervisor mode... Ok.
Calibrating delay using timer specific routine.. 7984.97 BogoMIPS (lpj=15969949)
Security Framework v1.0.0 initialized
SELinux: Initializing.
selinux_register_security: Registering secondary module capability
Capability LSM initialized as secondary
Mount-cache hash table entries: 512
CPU: Trace cache: 12K uops, L1 D cache: 16K
CPU: L2 cache: 1024K
Checking 'hlt' instruction... OK.
SMP alternatives: switching to UP code
Freeing SMP alternatives: 13k freed
Brought up 1 CPUs
checking if image is initramfs... it is
Freeing initrd memory: 5528k freed
Grant table initialized
NET: Registered protocol family 16
ACPI Exception (utmutex-0262): AE_BAD_PARAMETER, Thread C06F2AA0 could not acquire Mutex [2] [20060707]
No dock devices found.
ACPI Exception (utmutex-0262): AE_BAD_PARAMETER, Thread C06F2AA0 could not acquire Mutex [2] [20060707]
Brought up 1 CPUs
PCI: setting up Xen PCI frontend stub
ACPI: Interpreter disabled.
Linux Plug and Play Support v0.97 (c) Adam Belay
pnp: PnP ACPI: disabled
xen_mem: Initialising balloon driver.
usbcore: registered new driver usbfs
usbcore: registered new driver hub
PCI: System does not support PCI
PCI: System does not support PCI
NetLabel: Initializing
NetLabel: domain hash size = 128
NetLabel: protocols = UNLABELED CIPSOv4
NetLabel: unlabeled traffic allowed by default
NET: Registered protocol family 2
IP route cache hash table entries: 4096 (order: 2, 16384 bytes)
TCP established hash table entries: 16384 (order: 5, 131072 bytes)
TCP bind hash table entries: 8192 (order: 4, 65536 bytes)
TCP: Hash tables configured (established 16384 bind 8192)
TCP reno registered
audit: initializing netlink socket (disabled)
type=2000 audit(1239887579.855:1): initialized
VFS: Disk quotas dquot_6.5.1
Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
Initializing Cryptographic API
alg: No test for crc32c (crc32c-generic)
ksign: Installing public key data
Loading keyring
- Added public key 31B497468CDD12CF
- User ID: Red Hat, Inc. (Kernel Module GPG key)
io scheduler noop registered
io scheduler anticipatory registered
io scheduler deadline registered
io scheduler cfq registered (default)
pci_hotplug: PCI Hot Plug PCI Core version: 0.5
rtc: IRQ 8 is not free.
Non-volatile memory driver v1.2
Linux agpgart interface v0.101 (c) Dave Jones
RAMDISK driver initialized: 16 RAM disks of 16384K size 4096 blocksize
Xen virtual console successfully installed as xvc0
Event-channel device installed.
Console: switching to colour frame buffer device 100x37
input: Xen Virtual Keyboard/Mouse as /class/input/input0
Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
ide-floppy driver 0.99.newide
usbcore: registered new driver hiddev
usbcore: registered new driver usbhid
drivers/usb/input/hid-core.c: v2.6:USB HID core driver
PNP: No PS/2 controller found. Probing ports directly.
i8042.c: No controller found.
mice: PS/2 mouse device common for all mice
md: md driver 0.90.3 MAX_MD_DEVS=256, MD_SB_DISKS=27
md: bitmap version 4.39
TCP bic registered
Initializing IPsec netlink socket
NET: Registered protocol family 1
NET: Registered protocol family 17
Using IPI No-Shortcut mode
XENBUS: Device with no driver: device/vbd/769
XENBUS: Device with no driver: device/vbd/770
XENBUS: Device with no driver: device/vif/0
Freeing unused kernel memory: 176k freed
Write protecting the kernel read-only data: 383k
Registering block device major 3
USB Universal Host Controller Interface driver v3.0
megaraid cmm: 2.20.2.7 (Release Date: Sun Jul 16 00:01:03 EST 2006)
SCSI subsystem initialized
megaraid: 2.20.5.1 (Release Date: Thu Nov 16 15:32:35 EST 2006)
device-mapper: uevent: version 1.0.3
device-mapper: ioctl: 4.11.5-ioctl (2007-12-12) initialised: dm-devel@redhat.com
device-mapper: dm-raid45: initialized v0.2429
netfront: Initialising virtual ethernet driver.
netfront: device eth0 has flipping receive path.
kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
Bridge firewalling registered
virbr0: Dropping NETIF_F_UFO since no NETIF_F_HW_CSUM feature.
Red Hat Enterprise Linux Server release 5.3 (Tikanga)
Kernel 2.6.18-128.el5xen on an i686
vhost1-cloned.redhat.com login:root
Password:
Troubleshooting
Note that using the default host system initial RAM disk can cause problems on some Linux distributions. If the system fails to boot it may be necessary to generate an initial RAM disk without SCSI modules.
The typical full output from this type of Xen Guest OS boot failure is as follows:
Mounting root filesystem.
mount: could not find filesystem '/dev/root'
Setting up other filesystems.
Setting up new root fs
setuproot: moving /dev failed: No such file or directory
no fstab.sys, mounting internal defaults
setuproot: error mounting /proc: No such file or directory
setuproot: error mounting /sys: No such file or directory
Switching to new root and running init.
unmounting old /dev
unmounting old /proc
unmounting old /sys
switchroot: mount failed: No such file or directory
Booting has failed.
The most common cause of this problem is a conflict of SCSI modules. In order to resolve this it is necessary to create a new initrd initialization RAM Disk without SCSI modules, and then use this to boot the guest Linux operating system. This can be achieved using the following command:
mkinitrd --omit-scsi-modules --with=xennet --with=xenblk --preload=xenblk initrd-$(uname -r)-no-scsi.img $(uname -r)
Once the new initrd image file has been generated simply refer to it in the "ramdisk" line of the Xen configuration file, for example:
#ramdisk = "/boot/initrd-2.6.18-128.el5xen.img"
ramdisk = "/boot/initrd-2.6.18-128.el5xen-no-scsi.img"
Happy cloning.............
No comments:
Post a Comment