OpenSolaris and Linux on One USB Stick for Dual UsageBernd Schemmer, May 2008 Contents:
1. IntroductionMy goal is to create a USB stick for rescue tasks in Linux and in the OpenSolaris Operating System for x86 platforms. Therefore, there must be a bootable OpenSolaris OS and a bootable Linux OS on the USB stick. In addition, because I do not want to reboot my PC every time for adding or changing something on the USB stick, the USB stick must also boot in a virtual PC environment. The virtual PC environment should be available on various operating systems. And the USB stick should also be usable in Microsoft Windows environments to save files on the stick. All components used must be open source or at least freeware. 2 Chosen EnvironmentAfter some tests, I haven chosen the following components to implement this solution:
Note: MilaX is based on OpenSolaris build 81. 3. Implementation Instructions3.1 Creating the Partitions on the USB stickTo have more than one OS on the USB stick and also an additional FAT partition for Microsoft Windows usage, the USB stick must be partitioned. Notes:
The first partition is a FAT-formated partition for the myDSL extension of DSL, the Microsoft Windows data, and the QEMU binaries. The second partition is for Linux boot (DSL), and the third partition is for OpenSolaris boot (MilaX). 3.2 Installing Linux (DSL) on the USB StickTo install DSL on the USB stick, either boot the PC from the DSL Live CD-ROM and attach the USB stick or use QEMU for this purpose. The example below uses QEMU to install DSL on the USB stick. Notes:
### start the DSL ISO image in a QEMU virtual machine # root@tp61p:/# /usr/local/bin/qemu -net user -usb \ -usbdevice tablet -L /usr/local/share/qemu -m 512 \ -net nic -redir tcp:1135::22 -name \ "DSL_ISO_image_(user_network)_(ssh_port:_1135)" \ -drive file=/dev/sdb,if=scsi,index=1 \ -cdrom /data/nobackup/iso/dsl-4.2.5.iso -boot d Notes:
The DSL script to install DSL on a USB stick repartitions the USB stick. Therefore, we must change that script before we can use it: ### create a writable copy of the script # root@box:~# cp /usr/sbin/pendrive_usbhdd.sh /tmp/ ### edit the writable copy # root@box:~# vi /tmp/pendrive_usbhdd.sh Search the function
partition(){
return 0
/sbin/sfdisk /dev/sda << EOF
.....
Next search for the line # dd if=/dev/zero of=/dev/sda bs=512 count=1 Now you can execute the corrected script to install DSL on the USB stick: The DSL partition on the USB stick works in a QEMU virtual machine without changes, so there is nothing more to do here. It's recommended to check the USB stick now. It should boot DSL on bare metal and in a QEMU virtual machine. To boot the USB stick in a QEMU virtual machine use this: root@tp61p:/# /usr/local/bin/qemu -net user -usb \ -usbdevice tablet -L /usr/local/share/qemu -m 512 \ -net nic -redir tcp:1135::22 -name \ "DSL_on_USBstick_(user_network)_(ssh_port:_1135)" \ -hda /dev/sdb -boot c 3.3 Installing OpenSolaris on the USB StickDownload the MilaX USB image from the MilaX homepage, and save it in a location that is also accessible after booting from the MilaX Live CD-ROM. The To install MilaX on the USB stick, boot from the MilaX CD-ROM and attach the USB stick to the PC. I recommend starting the X server after MilaX is up and running: (alex@milax) ~ # startx 3.3.1 Become Root UserThe first thing to do here is to become root user: (alex@milax)$ su - Password: Sun Microsystems Inc. SunOS 5.11 MilaX_03 April 2008 (alex@milax)# Note: Be aware that the prompt does not change after switching to the root user! In this example, I changed the prompt manually to reflect the user ID. Caution: The device name for the USB stick depends on the configuration of the machine used. Therefore,
you should check the device name for the USB stick by using
(alex@milax)$ rmformat
Looking for devices...
1. Logical Node: /dev/rdsk/c4t0d0p0
Physical Node: /pci@0,0/pci-ide@1f,1/ide@0/sd@0,0
Connected Device: HL-DT-ST DVDRAM GSA-U10N 1.05
Device Type: CD Reader
Bus: IDE
Size: 107.0 MB
Label: <None>
Access permissions: Medium is not write protected.
2. Logical Node: /dev/rdsk/c3t0d0p0
Physical Node: /pci@0,0/pci17aa,20ab@1d,7/storage@2/disk@0,0
Connected Device: Ut163 USB2FlashStorage 0.00
Device Type: Removable
Bus: USB
Size: 2.0 GB
Label: <None>
Access permissions: Medium is not write protected
In the following examples, 3.3.2 Create the Slices on the OpenSolaris PartitionThere will be three slices on the OpenSolaris partition: The first slice, 3.3.3 Create the File System on the Slice for DataThe next step is to create a file system on the slice for the data: (root@milax)# newfs /dev/rdsk/c3t0d0s3 newfs: construct a new file system /dev/rdsk/c3t0d0s3: (y/n)? y /dev/rdsk/c3t0d0s3: 1093632 sectors in 178 cylinders of 48 tracks, 128 sectors 534.0MB in 14 cyl groups (13 c/g, 39.00MB/g, 18624 i/g) super-block backups (for fsck -F ufs -o b=#) at: 32, 80032, 160032, 240032, 320032, 400032, 480032, 560032, 640032, 720032, 800032, 880032, 960032, 1040032 3.3.4 Install MilaXNext we copy the MilaX USB image to slice 0 of the OpenSolaris partition. Now get access to the MilaX USB image; in my tests, I copied the image to a partition on my hard disk, which I then mounted from within MilaX. 3.3.5 Customize the GRUB MenuThe next step is the customization of the GNU GRand Unified Bootloader (GRUB) menu. You should remove the string Next, add the entry for DSL to the end of the GRUB menu: 3.3.6 Customize the MilaX RamdiskNow we must customize the MilaX ramdisk on the USB stick. To do this, first uncompress and mount the MilaX ramdisk.
First, we configure the keyboard layout; this is done by editing the file (root@milax)# vi /mnt/milax_ramdisk/boot/solaris/bootenv.rc Change the string setprop keyboard-layout "German" Use the program (root@milax)# kbd -s USB keyboard 1. Albanian 22. Latvian 2. Belarusian 23. Macedonian 3. Belgian 24. Malta_UK 4. Bulgarian 25. Malta_US 5. Croatian 26. Norwegian 6. Czech 27. Polish 7. Danish 28. Portuguese 8. Dutch 29. Russian 9. Finnish 30. Serbia-And-Montenegro 10. French 31. Slovenian 11. French-Canadian 32. Slovakian 12. Hungarian 33. Spanish 13. German 34. Swedish 14. Greek 35. Swiss-French 15. Icelandic 36. Swiss-German 16. Italian 37. Taiwanese 17. Japanese-type6 38. TurkishQ 18. Japanese 39. TurkishF 19. Korean 40. UK-English 20. Latin-American 41. US-English 21. Lithuanian To select the keyboard layout, enter a number [default 41]: You can also change Now you can save and close the file. The next change is in the (root@milax)# vi /mnt/milax_ramdisk/lib/svc/method/live-fs-root Replace the line
CUR_KEYBOARD_LAYOUT=`eeprom keyboard-layout | cut -f 2 -d "=" `
if [ "${CUR_KEYBOARD_LAYOUT}"x = "unknown" ] ; then
kbd -s
else
kbd -s "${CUR_KEYBOARD_LAYOUT}"
fi
The next change in the file Search for the line QEMU_DISK_RAW="/devices/pci@0,0/pci-ide@1,1/ide@0/cmdk@0,0:a,raw" QEMU_DISK_BLOCK="/devices/pci@0,0/pci-ide@1,1/ide@0/cmdk@0,0:a" Now replace the line
lcmd="eval /sbin/listusb ; echo ${QEMU_DISK_BLOCK} ${QEMU_DISK_RAW} "
Now you can save and close the file. Make sure there is no syntax error in the file now (the warnings can be ignored): The next change is necessary to correct the rights of the files in the user home directories. Edit the file (root@milax)# vi \ /mnt/milax_ramdisk/lib/svc/method/live-sysidtool-system Search for the line chown -R root /root Search for the line chown -R root /alex Now you can save and close the file. The next change is necessary to get a correct prompt for the root user: (root@milax)# vi /mnt/milax_ramdisk/etc/skel/.bashrc Search for if [ `id -u` = 0 ] ; then u="root" else u=`who am i | cut -f1 -d" "` fi I personally like to have the working directory in the prompt. Therefore, I change the prompt in the You can also add some code here to set the correct keyboard layout for X server settings. To do that, add the following
lines at the end of the file Change the value of the variable Save the file and exit the editor. Check the file (root@milax)# bash -x -n /mnt/milax_ramdisk/etc/skel/.bashrc The last step is to copy some more utilities, which are useful if the mount of (root@milax)# cp /usr/bin/cat /mnt/milax_ramdisk/usr/bin/ (root@milax)# cp /usr/bin/tail /mnt/milax_ramdisk/usr/bin/ (root@milax)# cp /usr/bin/less /mnt/milax_ramdisk/usr/bin/ (root@milax)# cp /usr/bin/svc /mnt/milax_ramdisk/usr/bin/ (root@milax)# cp /usr/sbin/svcadm /mnt/milax_ramdisk/usr/sbin/ (root@milax)# cp /usr/bin/svcs /mnt/milax_ramdisk/usr/bin Now unmount the ramdisk image, compress it again, and copy it back to the USB stick: And umount the USB stick: (root@milax)# umount /mnt/usb 3.4 FinishingThat's it. Now the USB stick is ready to use. The only things missing are the binaries for QEMU. I leave it as an exercise for the reader to copy the QEMU binaries for Linux, Microsoft Windows, and OpenSolaris to the FAT partition of the USB stick. 4. Appendix4.1 The Final Grub Menu on the USB StickHere is the final GRUB menu on the USB stick: 4.2. Invocation Syntax for Booting the USB Stick in a QEMU Virtual Machine4.2.1. General HintsThe default network adapter emulated by QEMU is not supported by MilaX. Therefore, you must always specify the network adapter type if you are using QEMU to boot MilaX: -net nic,model=rtl8139 The QEMU parameter xtrnaw7@tp61p:~$ ssh -l alex -p 1135 localhost Note: 4.2.2 Booting the USB Stick From Within LinuxHere's a script for booting the USB stick from within Linux: 4.2.3 Booting the USB Stick From Within Microsoft WindowsHere's a script for booting the USB stick from within Microsoft Windows: Notes:
4.3 References
Discuss and comment on this resource in the BigAdmin Wiki
Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License. |
| ||||||||||