How to install Milax 0.3 on a virtual disk in a Qemu Virtual Machine


Author: Bernd Schemmer (Bernd.Schemmer@gmx.de)
Last Update: v0.0.1 26.04.2008 12:00


Contents


  1. How to install Milax 0.3 on a virtual disk in a Qemu Virtual Machine
    1. Contents
    2. Introduction
      1. Prerequisites
      2. Notes
    3. Instructions
    4. Tips and Hints
      1. grub menu
      2. eeprom variables
      3. Adding a swap partition
      4. Allow ssh for root



Introduction


This documents describes the steps neccessary to install Milax 0.3 on a virtual disk in a Virtual Machine running in Qemu.

The environment used was Qemu 0.9.1 running on Ubuntu 7.10. But the instructions should also work with Qemu in any Operating System.



Prerequisites


Qemu is already installed

The ISO Image for Milax 0.3 is already downloaded




Notes


Commands with light blue background are to be executed on the host where Qemu is running , e.g.

$ uname -a
Linux tp61p 2.6.22-14-generic #1 SMP Tue Feb 12 02:46:46 UTC 2008 x86_64 GNU/Linux


Commands with light green background are to be executed in the Qemu Virtual Machine or in an ssh session to the Virtual Machine, e.g.

alex@milax ~ # uname -a
SunOS milax 5.11 MilaX_0.3 i86pc i386 i86pc
alex@milax ~ #


Note: Most commands in the Virtual Machine must be executed as user root



Instructions




1. Create a virtual disk for Milax using qemu-img.


$ qemu-img create -f qcow2 milax1.hdd 10G
Formatting 'milax1.hdd', fmt=qcow2, size=10485760 kB


Notes:

You should create the virtual disk with the format qcow2 to enable snapshots    

The virtual disk should be at least 512 MB in Size. If running qemu in Solaris or Linux you can create the virtual image with 10 GB or more without loosing space because Qemu only uses the space neccessary for the used sectors on the virtual disk.



2. Start the Milax  ISO image in Qemu:


$ /usr/local/bin/qemu -net user -net nic -usb -usbdevice tablet -L /usr/local/share/qemu -boot d \
   -m 512 -net nic,model=rtl8139 -redir tcp:1132::22 -name "Milax_ISO_image_(user_network)_(ssh_port:_1132)" \
   -hda /home/xtrnaw7/data/nobackup/qemu/harddisk/milax1.hdd \
   -cdrom /data/nobackup/iso/milax03.iso


Notes:

Choose the entry for Qemu (Milax 0.3 (32 bit, For Qemu) in the Grub Menu

The default network adapter (= NIC) used by Qemu is not supported by Milax yet; therefore you must change the type of the emulated NIC to rtl8139

The parameter "-redir tcp:1132::22" enables a ssh connections to the Virtual Machine from the host where Qemu is running. To open an ssh connection to the Virtual Machine after it's booted use:


$ ssh -l alex -p 1132 localhost

(see the Qemu documentation for details)



3. Open a terminal session in the Virtual Machine

After Milax is booted from CDROM you can either start the X server within Qemu using


(alex@milax)$ startx


or connect to the Virtual Machine using ssh:


$ ssh -l alex -p 1132 localhost



4. Become root user in the Milax session


(alex@milax)$ su -
Password:
Sun Microsystems Inc.   SunOS 5.11      MilaX_03        April 2008
(alex@milax)#


Note that the prompt does not change after switching to the root user! use "id"  to ensure that you're root user:

(alex@milax)# id
uid=0(root) gid=0(root)
(alex@milax)#





5. Create a Solaris partition on the virtual disk


(alex@milax)# fdisk /dev/rdsk/c3d0p0
No fdisk table exists. The default partition for the disk is:

  a 100% "SOLARIS System" partition

Type "y" to accept the default partition,  otherwise type "n" to edit the
 partition table.
y





6. Create a slice for the root filesystem and a optional slice for swap on the virtual disk for Milax:


(alex@milax)# format
Searching for disks...done


AVAILABLE DISK SELECTIONS:
       0. c3d0 <DEFAULT cyl 1302 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@1,1/ide@0/cmdk@0,0
Specify disk (enter its number): 0
selecting c3d0
Controller working list found
[disk formatted, defect list found]


FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        fdisk      - run the fdisk program
        repair     - repair a defective sector
        show       - translate a disk address
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        volname    - set 8-character volume name
        !<cmd>     - execute <cmd>, then return
        quit
format> p


PARTITION MENU:
        0      - change `0' partition
        1      - change `1' partition
        2      - change `2' partition
        3      - change `3' partition
        4      - change `4' partition
        5      - change `5' partition
        6      - change `6' partition
        7      - change `7' partition
        select - select a predefined table
        modify - modify a predefined partition table
        name   - name the current table
        print  - display the current table
        label  - write partition map and label to the disk
        !<cmd> - execute <cmd>, then return
        quit
partition> p
Current partition table (original):
Total disk cylinders available: 1302 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       0               0         (0/0/0)           0
  1 unassigned    wm       0               0         (0/0/0)           0
  2     backup    wu       0 - 1301        9.97GB    (1302/0/0) 20916630
  3 unassigned    wm       0               0         (0/0/0)           0
  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

partition> 0
Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       0               0         (0/0/0)           0

Enter partition id tag[unassigned]:
Enter partition permission flags[wm]:
Enter new starting cyl[0]: 3
Enter partition size[0b, 0c, 3e, 0.00mb, 0.00gb]: 2gb
partition> p
Current partition table (unnamed):
Total disk cylinders available: 1302 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       3 -  264        2.01GB    (262/0/0)   4209030
  1 unassigned    wm       0               0         (0/0/0)           0
  2     backup    wu       0 - 1301        9.97GB    (1302/0/0) 20916630
  3 unassigned    wm       0               0         (0/0/0)           0
  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

partition> 1
Part      Tag    Flag     Cylinders        Size            Blocks
  1 unassigned    wm       0               0         (0/0/0)           0

Enter partition id tag[unassigned]:
Enter partition permission flags[wm]:
Enter new starting cyl[0]:
Enter partition size[0b, 0c, 0e, 0.00mb, 0.00gb]:
partition> 1
Part      Tag    Flag     Cylinders        Size            Blocks
  1 unassigned    wm       0               0         (0/0/0)           0

Enter partition id tag[unassigned]: swap
Enter partition permission flags[wm]:
Enter new starting cyl[3]: 265
Enter partition size[0b, 0c, 265e, 0.00mb, 0.00gb]: 1gb
partition> p
Current partition table (unnamed):
Total disk cylinders available: 1302 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       3 -  264        2.01GB    (262/0/0)   4209030
  1       swap    wm     265 -  395        1.00GB    (131/0/0)   2104515
  2     backup    wu       0 - 1301        9.97GB    (1302/0/0) 20916630
  3 unassigned    wm       0               0         (0/0/0)           0
  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

partition> label
Ready to label disk, continue? yes

partition> quit


FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        fdisk      - run the fdisk program
        repair     - repair a defective sector
        show       - translate a disk address
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        volname    - set 8-character volume name
        !<cmd>     - execute <cmd>, then return
        quit
format> quit
(alex@milax)#





7. Install Milax on the virtual disk using zfsinstall:


(alex@milax)# zfsinstall c3d0s0
Starting to copy data from UFS root to /zfsroot - this may take some time.
a devices/ 0K
a devices/pseudo/ 0K
a devices/pseudo/clone@0/ 0K
a devices/pseudo/lofi@0/ 0K
a devices/pseudo/consms@0/ 0K
....

x dev/poolctl symbolic link to ../devices/pseudo/pool@0:poolctl
x dev/pool symbolic link to ../devices/pseudo/pool@0:pool
x dev/ipscan symbolic link to ../devices/pseudo/ipf@0:ipscan
x dev/nsmb symbolic link to ../devices/pseudo/nsmb@0:nsmb
x dev/fb symbolic link to /devices/pci@0,0/display@2:text-0
tar: ./dev/.devfsadm_synch_door is not a file. Not dumped
tar: ./dev/.devname_lookup_door is not a file. Not dumped
tar: ./svc/volatile/repository_door is not a file. Not dumped
tar: ./sysevent/devfsadm_event_channel/1 is not a file. Not dumped
tar: ./sysevent/devfsadm_event_channel/reg_door is not a file. Not dumped
tar: ./sysevent/syseventconfd_event_channel/reg_door is not a file. Not dumped
tar: ./sysevent/sysevent_door is not a file. Not dumped
tar: ./.dlmgmt_door is not a file. Not dumped
Updating vfstab
Creating boot_archive, don't worry about amd64 errors...
/zfsroot/platform/i86pc/amd64/boot_archive-new: No such file or directory
/zfsroot//boot/solaris/bin/create_ramdisk[32]: test: argument expected
mv: cannot access /zfsroot/platform/i86pc/amd64/boot_archive-new
Installing grub on /dev/rdsk/c3d0s0
stage1 written to partition 0 sector 0 (abs 16065)
stage2 written to partition 0, 260 sectors starting at 50 (abs 16115)
Milax now installed on zfs.



Notes:

Ignore the errors and warnings from the script.



8. Correct the grub menu entry for Milax on the virtual disk:


(alex@milax)# vi /tank/boot/grub/menu.lst


Remove the variable $ISADIR from the grub menu entry - it is not neccessary because there's only a 32 Bit version of Solaris on the virtual disk.

This step is optional for a Virtual Machine emulating a 32-Bit CPU but mandatory for a Virtual Machine emulating a 64-Bit CPU.

So in the end the lines

        kernel$ /platform/i86pc/kernel/$ISADIR/unix -B $ZFS-BOOTFS,console=text
        module$ /platform/i86pc/$ISADIR/boot_archive


should be changed to

        kernel$ /platform/i86pc/kernel/unix -B $ZFS-BOOTFS,console=text
        module$ /platform/i86pc/boot_archive





9. Correct the keyboard layout for the console


(alex@milax)# vi /zfsroot/boot/solaris/bootenv.rc

Change the value "unkown" in the line

setprop keyboard-layout Unknown

to the approbiate value, e.g. for German keyboard layouts it should look like

setprop keyboard-layout "German"


Next disable DMA for the virtual CDROM of the Qemu Virtual Machine:

Change the value 1 in the line

setprop atapi-cd-dma-enabled 1

to 0 so that it looks like:

setprop atapi-cd-dma-enabled 0



10. Correct the keyboard layout for the X Server

Add a work around to change the keyboard layout in the X server session if neccessary (in the default the keyboard layout of the X Server is either US english or Russian).

To do this add the following code to the file .bashrc for the users alex and/or root.

The . bashrc file for the user alex on the virtual disk is /zfsroot/alex/.bashrc while booted from CDROM; the .bashrc for the user root is /zfsroot/root/.bashrc while booted from CDROM. After booting from the virtual disk the files are /alex/.bashrc and /root/.bashrc.


if [ "${TERM}"x = "xterm"x -a "${DISPLAY}"x = ":0.0"x \
-a "${SSH_CONNECTION}"x = ""x ] ; then
SEMFILE="/tmp/keyboard_layout_changed"
NEW_KB_LAYOUT="de"
if [ ! -f "${SEMFILE}" ] ; then
echo "Changing the keyboard layout to \"${NEW_KB_LAYOUT}\" ..."
setxkbmap ${NEW_KB_LAYOUT}
xkbd
echo ${NEW_KB_LAYOUT} >"${SEMFILE}"
fi
fi


Note:

Change "de" in the line
  NEW_KB_LAYOUT="de"
to the approbiate keyboard layout.


To execute X programs as user root add also the following code to the start of the .profile of the user root:

if [ "${DISPLAY}"x = ""x ] ; then
  DISPLAY=:0.0
  export DISPLAY
fi




11. Shutdown the Virtual Machine:


(alex@milax)# init 0
(alex@milax)#


Close the Qemu Window after the message "Press any key to reboot"



12. Start the Qemu Virtual Machine from the virtual disk

Now you can start the Qemu Virtual Machine from the virtual disk:


$ /usr/local/bin/qemu -net user -net nic -usb -usbdevice tablet -L /usr/local/share/qemu -boot c \
   -m 512 -net nic,model=rtl8139 -redir tcp:1132::22 -name "Milax_ISO_image_(user_network)_(ssh_port:_1132)" \
   -hda /home/xtrnaw7/data/nobackup/qemu/harddisk/milax1.hdd




13. Milax is now booted from a zfs volume on the virtual disk:

Sun Microsystems Inc.   SunOS 5.11      MilaX_03        April 2008
(alex@milax)$ bash
(alex@milax)$ uname -a
SunOS milax 5.11 MilaX_0.3 i86pc i386 i86pc
(alex@milax)$ mount
/ on tank/rootfs read/write/setuid/devices/nonbmand/exec/xattr/atime/dev=2d90002 on Sat Apr 26 00:36:14 2008
/devices on /devices read/write/setuid/devices/dev=4b80000 on Sat Apr 26 00:35:38 2008
/dev on /dev read/write/setuid/devices/dev=4bc0000 on Sat Apr 26 00:35:38 2008
/system/contract on ctfs read/write/setuid/devices/dev=4c40001 on Sat Apr 26 00:35:38 2008
/proc on proc read/write/setuid/devices/dev=4c80000 on Sat Apr 26 00:35:38 2008
/etc/mnttab on mnttab read/write/setuid/devices/dev=4cc0001 on Sat Apr 26 00:35:38 2008
/etc/svc/volatile on swap read/write/setuid/devices/xattr/dev=4d00001 on Sat Apr 26 00:35:38 2008
/system/object on objfs read/write/setuid/devices/dev=4d40001 on Sat Apr 26 00:35:38 2008
/etc/dfs/sharetab on sharefs read/write/setuid/devices/dev=4d80001 on Sat Apr 26 00:35:38 2008
/lib/libc.so.1 on /usr/lib/libc/libc_hwcap3.so.1 read/write/setuid/devices/dev=2d90002 on Sat Apr 26 00:36:00 2008
/dev/fd on fd read/write/setuid/devices/dev=4ec0001 on Sat Apr 26 00:36:14 2008
/tmp on swap read/write/setuid/devices/xattr/dev=4d00002 on Sat Apr 26 00:36:18 2008
/var/run on swap read/write/setuid/devices/xattr/dev=4d00003 on Sat Apr 26 00:36:18 2008
/tank on tank read/write/setuid/devices/nonbmand/exec/xattr/atime/dev=2d90003 on Sat Apr 26 00:36:35 2008
(alex@milax)$



Notes

Note that the ZFS volume only uses one slice on the virtual disk. Therefore you can install additional Solaris versions on the virtual disk.



Tips and Hints



grub menu

To change the grub menu after booting from the virtual disk edit the file

/tank/boot/grub/menu.lst

Note that in the Solaris release used for Milax 0.3  bootadm does not yet know the location of the file menu.lst on ZFS root filesystems.That means that you can not use bootadm to check or change the grub menu.


eeprom variables


To change the eeprom settings manaul after booting from the virtual disk edit the file

/boot/solaris/bootenv.rc



Adding a swap partition


To add a swap partition for the current session execute as root user

root@milax ~ # swap -a /dev/dsk/c3d0s1
operating system crash dump was previously disabled --
invoking dumpadm(1M) -d swap to select new dump device

# check the results:
#
root@milax ~ # swap -l
swapfile             dev    swaplo   blocks     free
/dev/dsk/c3d0s1     102,1         8  2104504  2104504

 root@milax ~ # dumpadm
      Dump content: kernel pages
       Dump device: /dev/dsk/c3d0s1 (swap)
Savecore directory: /var/crash/milax
  Savecore enabled: yes


To add the swap partition permanent execute as root user

root@milax ~ # echo "/dev/dsk/c3d0s1 -       -       swap    -       no      -">>/etc/vfstab

These instructions assume that you created the swap partition while partitioning the virtual disk



Allow ssh for root

To allow ssh connections for root edit the file

/etc/ssh/sshd_config

and change the line

PermitRootLogin no

to

PermitRootLogin yes

After the change execute as root:


root@milax ~ # svcadm refresh ssh