by Bernd Schemmer, November 2008
Homepage: http://www.bnsmb.de/
Last Update: 17.04.2012/bs
- Links checked and corrected
Table of Contents
This article describes how to add xVM DomU support to a Solaris Live CD distribution (Note: xVM is Xen for Solaris). Due to the fact that CDROMs are read-only this can only be done after installing the distribution to a harddisk.
For this example we use the OpenSolaris distribution MilaX 0.3.2
but the instructions should also work for other OpenSolaris
distributions (like for example Belenix).
Update 17.04.2012:
Oracle does not support xVM (Xen) in Solaris anymore.
This article simply describes how to add xVM DomU support; it does not discuss the concepts of xVM or Xen in general.
The following tools and files are used
MilaX Homepage | http://www.milax.org |
MilaX Download page | http://www.milax.org/?page_id=9 |
Xen Homepage |
http://www.xen.org |
Sun xVM Homepage |
n/a |
Xen/xVM at OpenSolaris | http://www.opensolaris.org/os/community/xen |
QEMU Homegepage | http://wiki.qemu.org/Index.html |
QEMU Project at OpenSolaris | http://www.opensolaris.org/os/project/qemu/ |
kvm wiki | http://kvm.qumranet.com/kvmwiki |
VirtualBox Homepage |
https://www.virtualbox.org/ |
Belenix Homepage |
http://www.belenix.org |
The current releases of the existing Solaris Live CDs contain a script called zfsinstall to install the Solaris distribution from the Live CD on a local harddisk. These scripts install Solaris on a zfsroot. They do work in virtualization products like QEMU (or VirtualBox) and the virtual harddisks created with the scripts can be booted in the QEMU virtual machine. But unfortunately these installations do not boot in a Solaris xVM DomU yet. Therefore, the first step is to install the distribution on a virtual harddisk formated with UFS.
So the first step is to create an image file for the harddisk of the virtual machine
xtrnaw7@t61p:/data/nobackup/qemu/harddisk$ qemu-img create -f raw milax_with_xen.hdd 20G Formatting 'milax_with_xen.hdd', fmt=raw, size=20971520 kB
Note: You must use a diskimage format that is known by QEMU and xVM.
Next start a QEMU (or kvm) virtual machine from the MilaX 0.3.2 Live CD ISO image
xtrnaw7@t61p:~$ /usr/bin/kvm -net user -net nic -usb -usbdevice tablet -L /usr/share/qemu -usb \ -boot d -m 512 -net nic,model=rtl8139 -redir tcp:1181::22 \ -name 'Milax_from_harddisk_ssh_port:_1181' \ -hda /home/xtrnaw7/data/nobackup/qemu/harddisk/milax_with_xen.hdd \ -cdrom /home/xtrnaw7/data/nobackup/iso/milax032.iso \ -vnc :1 -k de &
And connect to the virtual machine either via VNC
xtrnaw7@t61p:~$ vncviewer :1 &
or via ssh
xtrnaw7@t61p:~$ ssh -x -l alex -p 1181 localhost
Note: All steps must be done as user root.
First step is to partition the virtual harddisk and create the necessary slices for Solaris using the Solaris command format.
For this example I used the following slice configuration:
Part Tag Flag Cylinders Size Blocks 0 root wm 3 - 1308 10.00GB (1306/0/0) 20980890 1 swap wm 1309 - 1570 2.01GB (262/0/0) 4209030 2 backup wu 0 - 2606 19.97GB (2607/0/0) 41881455 3 unassigned wm 1571 - 2606 7.94GB (1036/0/0) 16643340 4 unassigned wm 0 0 (0/0/0) 0 5 unassigned wm 0 0 (0/0/0) 0 6 unassigned wm 0 0 (0/0/0) 0 7 unassigned wm 0 0 (0/0/0) 0 8 boot wu 0 - 0 7.84MB (1/0/0) 16065 9 alternates wm 1 - 2 15.69MB (2/0/0) 32130
The slice 0 is used for the rootfs and the slice 1 is used for swap.
The next step is to create an UFS file system on the slice for the rootfs on the harddisk:
(root@milax)# newfs /dev/rdsk/c4d0s0 newfs: construct a new file system /dev/rdsk/c4d0s0: (y/n)? y Warning: 870 sector(s) in last cylinder unallocated /dev/rdsk/c4d0s0: 20980890 sectors in 3415 cylinders of 48 tracks, 128 sectors 10244.6MB in 214 cyl groups (16 c/g, 48.00MB/g, 5824 i/g) super-block backups (for fsck -F ufs -o b=#) at: 32, 98464, 196896, 295328, 393760, 492192, 590624, 689056, 787488, 885920, 20055584, 20154016, 20252448, 20350880, 20449312, 20547744, 20646176, 20744608, 20843040, 20941472
Because the virtual hardware in a xVM DomU is different from the virtual hardware in a QEMU virtual machine we must unmount the hardware specific libc before continuing:
(root@milax)# umount /lib/libc.so.1
Now mount the root slice on the virtual harddisk for MilaX to /a
(root@milax)# mkdir /a (root@milax)# mount /dev/dsk/c4d0s0 /a
And then copy the necessary files to the root slice
Note: The instructions below are copied from the zfsinstall script which is part of MilaX.
Just copy the commands to a script in the virtual machine and execute the script as user root:
cd / find . -xdev -depth -print | cpio -pvdm /a 2>&1 > /dev/null # libc! cp -rP /lib/libc.so* /a/lib 2>&1 > /dev/null mkdir -p /a/alex cd /alex find . -xdev -depth -print | cpio -pvdm /a/alex 2>&1 > /dev/null mkdir -p /a/root cd /root find . -xdev -depth -print | cpio -pvdm /a/root 2>&1 > /dev/null mkdir -p /a/usr cd /usr find . -xdev -depth -print | cpio -pvdm /a/usr 2>&1 > /dev/null mkdir -p /a/system/object mkdir -p /a/system/contract mkdir -p /a/tmp mkdir -p /a/proc mkdir -p /a/var/run mkdir -p /a/dev/fd touch /a/etc/mnttab touch /a/etc/dfs/sharetab chmod 555 /a/system/object chmod 555 /a/system/contract chmod 555 /a/proc chmod 777 /a/tmp chmod 755 /a/etc/svc/volatile chmod 755 /a/var/run chmod 555 /a/dev/fd chmod 444 /a/etc/mnttab chmod 755 /a/usr chmod 755 /a/alex chmod 755 /a/root chown -R alex:adm /a/alex chown root /a/system/object chown root /a/system/contract chown root /a/proc chown root /a/tmp chown root /a/etc/svc/volatile chown root /a/var/run chown root /a/dev/fd chown root /a/etc/mnttab chgrp root /a/system/object chgrp root /a/system/contract chgrp sys /a/tmp chgrp root /a/proc chgrp sys /a/etc/svc/volatile chgrp sys /a/var/run chgrp root /a/dev/fd chgrp root /a/etc/mnttab mkdir -p /a-tmp.$$ mount -F lofs -o nosub / /a-tmp.$$ (cd /a-tmp.$$; tar cf - devices dev ) | (cd /a; tar xfp -) 2>&1 > /dev/null cd / umount /a-tmp.$$ rm -rf /a-tmp.$$ # copy last etc cd /etc tar cf - . | (cd /a/etc ; tar xfp -) 2>&1 > /dev/null # rebuild svc at first boot rm -f /a/var/svc/manifest/system/filesystem/live-root-fs.xml rm -f /a/var/svc/manifest/system/dss-sysidtool.xml rm -f /a/var/svc/manifest/system/live-sysidtool.xml cp /usr/dss/share/hdinstall/misc/root-fs.xml /a/var/svc/manifest/system/filesystem/ cp /usr/dss/share/hdinstall/misc/sysidtool.xml /a/var/svc/manifest/system/ cp /lib/svc/seed/global.db /a/etc/svc/repository.db # copy vfstab cp /usr/dss/share/hdinstall/misc/vfstab /a/etc/vfstab # and add entries for the root fs and swap to the file /etc/vfstab cat <<EOF>>/a/etc/vfstab /dev/dsk/c4d0s0 /dev/rdsk/c4d0s0 / ufs - no logging /dev/dsk/c4d0s1 - - swap - no - EOF
Next change the keyboard layout for the console if necessary. This can be done by changing the value for the keyword keyboard-layout in the file /boot/solaris/bootenv.rc to the approbate value (e.g. German for german keyboards):
(root@milax)# vi /a/boot/solaris/bootenv.rc
And to change the keyboard layout for the X server change the value for the keyword XKBD in the file /etc/sysconfigd/xkbd to the approbate value (e.g de for german keyboards):
(root@milax)# vi /a/etc/sysconfig/xkbd
Then add the bootpath variable to the file /boot/solaris/bootenv.rc:
(root@milax)# echo "setprop bootpath /pci@0,0/pci-ide@1,1/ide@0/cmdk@0,0:a" >>/a/boot/solaris/bootenv.rc
And add a workaround for an error with the SMF service boot-archive.
The service boot-archive always fails in this
configuration (I don't know why yet); so you should disable it by
adding an exit command to the beginning of the script /a/lib/svc/method/boot-archive
so that it looks like:
. /lib/svc/share/fs_include.sh # new line follows: exit $SMF_EXIT_OK ERRORFILE=/etc/svc/volatile/boot_archive_error ...
Note: Disabling the service boot svc:/system/boot-archive:default is not an option because the service is a prerequisite for the multi-user mode
Now create a SMF profile in /a/var/svc/profile/site.xml with the following contents
<?xml version='1.0'?> <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'> <service_bundle type='profile' name='site' xmlns:xi='http://www.w3.org/2003/XInclude' > <service name='system/boot-archive-update' type='service' version='0'> <instance name='default' enabled='true'/> </service> <service name='system/boot-archive' type='service' version='0'> <instance name='default' enabled='true'/> </service> <service name='network/physical' type='service' version='0'> <instance name='default' enabled='false'/> <instance name='nwam' enabled='true'/> </service> </service_bundle>
Next step is to update the boot-archive on the root slice (ignore the errors for the amd64 boot-archive)
(root@milax)# bootadm update-archive -R /a Creating boot_archive for /a updating /a/platform/i86pc/boot_archive updating /a/platform/i86pc/amd64/boot_archive /a//boot/solaris/bin/create_ramdisk52: /a/platform/i86pc/amd64/boot_archive-new: cannot create /a/platform/i86pc/amd64/boot_archive-new: No such file or directory /a//boot/solaris/bin/create_ramdisk32: test: argument expected mv: cannot access /a/platform/i86pc/amd64/boot_archive-new
Then install the Grub bootloader in the master boot sector on the disk:
(root@milax)# installgrub -m /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c4d0s0 Updating master boot sector destroys existing boot managers (if any). continue (y/n)?y stage1 written to partition 0 sector 0 (abs 16065) stage2 written to partition 0, 266 sectors starting at 50 (abs 16115) stage1 written to master boot sector
create the signature file for Grub:
(root@milax)# mkdir /a/boot/grub/bootsign (root@milax)# touch /a/boot/grub/bootsign/milax_ufs
and add the Grub menu entries to the file /boot/grub/menu.lst so that it looks like
(root@milax)# cat /a/boot/grub/menu.lst # #pragma ident "@(#)install_menu 1.1 05/04/15 SMI" # default=0 timeout=20 splashimage=/boot/grub/splash.xpm.gz foreground=ffffff background=444444 title MilaX Note (0.3.2) (32 bit, For Qemu) findroot (milax_ufs,0,a) kernel /platform/i86pc/kernel/unix -B atapi-cd-dma-enabled=0,atapi-other-dma-enabled=0 module /platform/i86pc/boot_archive title MilaX Note (0.3.2) (32 bit) findroot (milax_ufs,0,a) kernel /platform/i86pc/kernel/unix module /platform/i86pc/boot_archive title MilaX Note (0.3.2) (32 bit) text console findroot (milax_ufs,0,a) kernel /platform/i86pc/kernel/unix -B livemode=text module /platform/i86pc/boot_archive title MilaX Note (0.3.2) (32 bit, No ACPI) findroot (milax_ufs,0,a) kernel /platform/i86pc/kernel/unix -B acpi-user-options=2 module /platform/i86pc/boot_archive title MilaX Note (0.3.2) (32 bit, No ACPI, Verbose, Debug) findroot (milax_ufs,0,a) kernel /platform/i86pc/kernel/unix -B acpi-user-options=2 -kv -m verbose module /platform/i86pc/boot_archive
Now MilaX is installed on an UFS slice in the virtual machine.
To check the installation reboot the virtual machine from the virtual harddisk using the Solaris command reboot
(root@milax)# reboot
Note: Choose the menu entry "Boot from Hard Disk" in the 1st Grub Menu and then "MilaX Note (0.3.2) (32 bit, For Qemu)" in the 2nd Grub Menu.
If everything is fine and the virtual machine boots without problems from the virtual harddisk you can add the xVM support.
Note: It's recommended to shutdown the virtual machine now and create a backup of the diskimage file for the virtual machine.
Note: After these changes the virtual harddisk will NOT boot in QEMU/kvm anymore!
The first step is to add the necessary packages for xVM DomU support:
Copy the Solaris packages SUNWcakr.i and SUNWcakrx.i to the virtual machine and install them as root via pkgadd:
(root@milax)# pkgadd -d . SUNWcakr.i SUNWcakrx.i ... Installation of <SUNWcakr> was successful. ... Installation of <SUNWcakrx> was successful.
Note: For MilaX 0.3.2 you need the packages from Solaris Release snv_95.
Then add a new menu entry for the DomU to the Grub Menu
(root@milax)# cat <<EOT >>/boot/grub/menu.lst title MilaX 0.3.2 (32 bit, For Xen) root (hd0,0,a) kernel$ /platform/i86xpv/kernel/unix -B console=text,livemode=text module$ /platform/i86pc/boot_archive EOT
Now cleanup the device tree
(root@milax)# devfsadm -C
After the devfsadm -C command there should only exist c4* and c5* entries in /dev/rdsk and /dev/dsk, e.g.:
(root@milax)# ls /dev/dsk c4d0p0 c4d0p4 c4d0s11 c4d0s15 c4d0s5 c4d0s9 c5t0d0p3 c5t0d0s10 c5t0d0s14 c5t0d0s4 c5t0d0s8 c4d0p1 c4d0s0 c4d0s12 c4d0s2 c4d0s6 c5t0d0p0 c5t0d0p4 c5t0d0s11 c5t0d0s15 c5t0d0s5 c5t0d0s9 c4d0p2 c4d0s1 c4d0s13 c4d0s3 c4d0s7 c5t0d0p1 c5t0d0s0 c5t0d0s12 c5t0d0s2 c5t0d0s6 c4d0p3 c4d0s10 c4d0s14 c4d0s4 c4d0s8 c5t0d0p2 c5t0d0s1 c5t0d0s13 c5t0d0s3 c5t0d0s7
Now create the disk device links for xVM in /dev/dsk and /dev/rdsk using this little script:
#!/usr/bin/ksh j=0 for i in a b c d e f g h i j k l m n o p ; do ln -s "../../devices/xpvd/xdf@0:${i}" /dev/dsk/c0d0s${j} ln -s "../../devices/xpvd/xdf@0:${i},raw" /dev/rdsk/c0d0s${j} let j=$j+1 done j=0 for i in q r s t u ; do ln -s "../../devices/xpvd/xdf@0:${i}" /dev/dsk/c0d0p${j} ln -s "../../devices/xpvd/xdf@0:${i},raw" /dev/rdsk/c0d0p${j} let j=$j+1 done
Then correct the file /etc/vfstab
(root@milax)# cp /etc/vfstab /etc/vfstab.qemu
(root@milax)# sed "s/c4/c0/g" /etc/vfstab >/etc/vfstab.xen
(root@milax)# cp /etc/vfstab.xen /etc/vfstab
and the path to the boot device in the file /boot/solaris/bootenv.rc:
(root@milax)# cp /boot/solaris/bootenv.rc /boot/solaris/bootenv.rc.qemu
(root@milax)# sed "s/setprop bootpath.*/setprop bootpath \/xpvd\/xdf@0:a/" /boot/solaris/bootenv.rc >/boot/solaris/bootenv.rc.xen
(root@milax)# cp /boot/solaris/bootenv.rc.xen /boot/solaris/bootenv.rc
At last initiate a reconfigure reboot
(root@milax)# touch /reconfigure
and update the boot archive
(root@milax)# bootadm update-archive updating /platform/i86pc/boot_archive updating /platform/i86pc/amd64/boot_archive
Now the virtual machine is ready to boot in xVM DomU
Depending of the type of the Dom0 you're using the files boot_archive and kernel are required in the Dom0.
Therefore, you should copy them to the machine running the xVM (or Xen) Dom0 now:
(root@milax)# scp /platform/i86pc/boot_archive root@192.168.1.162:/xen/boot_archive_ufs boot_archive 100% |*******************************************************************| 90333 KB 00:09 (root@milax)# scp /platform/i86xpv/kernel/unix root@192.168.1.162:/xen/unix unix 100% |*******************************************************************| 1350 KB 00:00
Now you can shutdown the virtual machine and copy the imagefile to the machine running the Dom0.
Note: use tar (in Solaris: gtar) with the parameter --sparse to copy the imagefile otherwise you'll lose the sparse functionality of the file.
First create the config file for the DomU.
In a Solaris xVM Dom0 booted in 32Bit mode the config file should look like this:
(solaris-32bit-dom0) # cat milax_on_ufs.cfg name = "Milax" memory = "512" vcpus = "1" disk = [ 'file:/pool/xen/milax_with_xen.hdd,0,w' ] vif = [ '' ] on_shutdown = 'destroy' on_reboot = 'restart' on_crash = 'destroy'
(Tested with Solaris snv_89)
In a Solaris xVM Dom0 booted in 64Bit mode the config file should look like
(solaris-64bit-dom0) # cat milax_on_ufs.cfg name = "Milax" memory = "512" vcpus = "1" disk = [ 'file:/xen/milax_with_xen.hdd,0,w' ] vif = [ '' ] on_shutdown = 'destroy' on_reboot = 'restart' on_crash = 'destroy' kernel = "/xen/unix" ramdisk = "/xen/boot_archive_ufs" extra = "/platform/i86xpv/kernel/unix -r -B console=text,livemode=text"
(Tested with Solaris snv_101)
In a Linux Dom0 booted in 32Bit mode the config file should look like:
(linux-dom0) # cat milax_on_ufs.cfg name = "Milax" memory = "512" vcpus = "1" vif = [ '' ] disk = [ 'tap:aio:/pool/xen/milax_with_xen.hdd,0,w' ] on_shutdown = 'destroy' on_reboot = 'restart' on_crash = 'destroy'
(Tested with Xen 3.2 running under Ubuntu Hardy Heron 8.04.01 in 32Bit Mode; for Xen 3.1 you must use "file:" instead of "tap:aio:")
To start the DomU use
bash-3.2# xm create -c milax_on_ufs.cfg Using config file "./milax_on_ufs.cfg". Started domain Milax v3.1.4-xvm chgset 'Mon Oct 13 22:14:51 2008 -0700 15904:94bd0a643efe' SunOS Release 5.11 Version snv_95 32-bit Copyright 1983-2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Configuring devices. Hostname: milax Mounting local partitions/cdroms Using physical swap on hdd (/dev/dsk/c0d0s1) Reading ZFS config: done. Starting X11 Desktop Wait for the Desktop screen before logging in milax console login:
To get the Graphical Desktop of the DomU either use the framebuffer functionality of xVM or install a VNC server in the DomU, for example the VNC server from the Solaris companion CD:
root@milax)# mount 192.168.1.8:/export/install/software_companion_sparc_sol10u6 /mnt (root@milax)# pkgadd -d /mnt/Solaris_Software_Companion/Solaris_i386/Packages/ SFWvnc
A script to start the VNC server in the DomU might look like:
#!/bin/bash [ $# -eq 2 ] && VNC_DISPLAY="$2" || VNC_DISPLAY=":1" case $1 in start ) echo "Starting the VNC Server on the display ${VNC_DISPLAY} ..." if [ ! -x /usr/bin/xauth ] ; then # create a dummy xauth executable echo "exit 0">/usr/bin/xauth chmod 755 /usr/bin/xauth fi vncserver ${NVC_DISPLAY} export DISPLAY=${VNC_DISPLAY} /usr/dss/bin/xinitrc & ;; stop ) echo "Stopping the VNC Server on the display ${VNC_DISPLAY} ..." vncserver -kill ${VNC_DISPLAY} ;; * ) echo "Usage: $0 [start|stop] {displaynumber}" ;; esac
If the virtual disk does not boot in a DomU you should boot MilaX again from the ISO image in QEMU using the commands
xtrnaw7@t61p:~$ qemu -net user -net nic -usb -usbdevice tablet -L /usr/share/qemu -boot d -m 512 \ -redir tcp:1181::22 -name 'Milax_from_harddisk_ssh_port:_1181' -hda /data/temp/milax_with_xen.hdd \ -cdrom /home/xtrnaw7/data/nobackup/iso/milax032.iso -vnc :1 -k de & xtrnaw7@t61p:~$ vncviewer :1 &
to correct the errors on the virtual harddisk.
Note: MilaX will automatically mount the slice 0 of the virtual harddisk to the directory /mnt/solaris0 in this case.
Problem
Solaris boots in the DomU but crashes with these error messages:
Using config file "./milax.cfg". Started domain Milax v3.1.4-xvm chgset 'Mon Oct 13 22:14:51 2008 -0700 15904:94bd0a643efe' SunOS Release 5.11 Version snv_95 32-bit Copyright 1983-2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. panic[cpu0]/thread=f5028220: Cannot find /devices f50523ec genunix:vfs_mountdevices+192 (0, 1, f5027990, 0, ) f5052410 genunix:vfs_mountroot+1ea (f4c00010, f504e238,) f5052420 genunix:main+b9 () syncing file systems... done skipping system dump - no dump device configured rebooting...
Reason
The entry for the bootpath is missing or invalid in the file /boot/solaris/bootenv.rc on the virtual harddisk. The entry should be:
setprop bootpath /xpvd/xdf@0:a
Solution
Add the line
extra = "/platform/i86xpv/kernel/unix -r -B console=text,livemode=text,bootpath=/xpvd/xdf@0:a"
to the DomU config file and start the DomU again. After the DomU is running add the line
setprop bootpath /xpvd/xdf@0:a
to the file /boot/solaris/bootenv.rc.
After this is done the "extra" line from the DomU config file can
be removed.
Problem:
The virtual disk boots in a DomU but after the kernel is loaded it prints the error message
WARNING: init(1M) exited on fatal signal 9: restarting automatically
indefinitely
Reason:
You did not umount /lib/libc.so.1 before copying the files to the virtual harddisk.
Solution
Either reboot the virtual machine from the CDROM in QEMU and replace the file /lib/libc.so.1 with the libc from the CDROM or recreate the virtual harddisk from scratch.
Problem
The virtual disk boots but Solaris goes into maintenance mode because the service svc:/system/filesystem/usr:default failed.
Reason
Solaris can not mount the root file system.
Solution
Check the entry for the root filesystem in the file /etc/vfstab on the virtual harddisk. It should look like:
/dev/dsk/c0d0s0 /dev/rdsk/c0d0s0 / ufs - no logging
If the entry for the root filesystem in the file /etc/vfstab is correct check the device entries for the rootdisk in /dev/dsk and /dev/rdsk. They should look like
(root@milax)# ls -l /dev/*dsk/c0d0s0 lrwxrwxrwx 1 root root 26 Nov 10 12:37 /dev/dsk/c0d0s0 -> ../../devices/xpvd/xdf@0:a lrwxrwxrwx 1 root root 30 Nov 10 12:37 /dev/rdsk/c0d0s0 -> ../../devices/xpvd/xdf@0:a,raw
If the file /etc/vfstab and the device entries are okay check the log file of the service svc:/system/filesystem/usr:default.
Problem
MilaX boots in a DomU but there is no network adapter configured.
Solution
Either create the necessary files for the default network configuration SMF service (e.g. /etc/hostname.; /etc/dhcp., /etc/resolv.conf, /etc/defaultrouter, etc) or ensure that the SMF service mwam is online:
(alex@milax)$ svcs svc:/network/physical:nwam STATE STIME FMRI online 15:55:03 svc:/network/physical:nwam
If there is still no network connection after enabling the nwam
service ensure that the DomU is configured with a network adapter:
There should be a line beginnig with "vif =" in the config file
for the DomU.