How small can you make Open Solaris - Part 1

来源:互联网 发布:北京太极计算机做java 编辑:程序博客网 时间:2024/05/22 12:18
Solarisstarted its life as operating system for workstations and thenprogressed to servers. It has always been an operating system dominatedby features, showing Sun's R&D capability. This is great if you areinstalling a server or a desktop, but has far too many features forbuilding an appliance. Luckily the installing comes with some reducedinstallation clusters which tries to bring the installation down to thebare minimum. Unfortunately the last time I looked the smallest installwas still several hundred megabytes. Linux on the other hand has had aproject going for while now called "Damn Small Linux",which strips Linux down to around 50 megabytes. This is a perfect baseto start building an appliance, build your own distro, or strip thekernel down further for an embedded device.

Can Solaris become as small as "Damn Small Linux".The answer is a resounding yes (and probably smaller). Lets investigatehow this can be done. The first thing to do is to state the goal, whichis to be able to successfully boot into a shell and execute a simplecommand such as 'ls'. The logical place to start is with the smallestrunning version of Solaris supplied by Sun. If you have a x86 grubversion of Solaris you will find a 52 megabyte file in your /bootdirectory called x86.miniroot-safe. This file is a gzipped UFS imagethat is booted when you select "Solaris failsafe" from the grub menu.Using it to boot to single user mode will mount the root filesystem andgive you a root shell. It also contains the code to start a Solarisinstallation.

Now we have found an ideal candidate, lets startripping it apart. The first step is to copy it (as you may need it ifyou break something), and setup new menu option in grub.

cd /boot
cp x86.miniroot-safe x86.microroot
cd /boot/grub

Edit the file menu.lst, copy the failsafe section and modify it to look something like this -

title Solaris Micro Root
kernel /boot/multiboot kernel/unix -s
module /boot/x86.microroot

Ifyou want you now can reboot and select "Solaris Micro Root" when thegrub menu comes up. It should boot into your copy of failsafe. Afteryou have finished testing, reboot into multiuser mode and mount thisimage so you can change it.

The file '/boot/x86.microroot' isactually a gzipped UFS filesystem image, which with a couple ofcommands can mounted and change. The following is the an example of theprocedure to make changes. I would suggest you create mount and unmountscripts to automate the process. (Note: You will need superuser privs for the following steps, the root user or atleast sys_mount, file_dac_read, file_dac_write)

Important - Make a backup before making changes, and document your changes

cp /boot/x86.microroot /boot/x86.microroot.bak

Unzip image to /tmp

gzcat /boot/x86.microroot > /tmp/microroot.img

Create a loopback device for this file. The environment variable 'dev' catches the device name for later use.

dev="`lofiadm -a /tmp/microroot.img`"

Finally mount the image using the loopback device.

mount -F ufs ${dev} /mnt

At this point your image is mounted and you can cd to /mnt and make your changes. Note: Be VERY VERY CAREFUL that you are changing or removing the file in /mnt and NOTin the root filesystem. It could get very ugly if you make thismistake. Take your time and be very careful. Once you have made thechanges DONT REBOOT. You willneed to follow the next steps and commit the changes before you reboot.Also rather than deleting a file or a directory, it is a betterpractice to move them to a backup directory and then test the changes.If the changes were good then you can delete the backup directorylater. If the changes caused problems you can simply move the files anddirectories back in your next editting session.

Umount the image and delete the loopback device.

cd /
umount /mnt
lofiadm -d /tmp/microroot.img

Copy/gzip the changes back to the /boot directory

gzip -c /tmp/microroot.img > /boot/x86.microroot

Youcan now reboot and test your changes. If the system hangs, just resetthe system and undo what you did and try something else. If the systemreboots too fast for you to read the kernel messages, a handy tip is toadd the "-kd" options in the grub menu (combined with or after the'-s'). This will put the kernel straight to debug mode. To continue theboot type ':c' at the prompt. If the kernel panics it should print a message and then wait for you to press a key before rebooting.

Usingthis method I reduced the entire image to around 42 megabytes(uncompressed) without touching the 32bit kernel. I then was able tocreate a 18 megabyte bootable Solaris. The next part I will list theareas you should remove or modify. Hopefully, in Part 3, I will havefinished a script which takes a Open Solaris build from the prototypedirectory and builds the microroot for you.

Note: This article is originally posted at

http://solaristhings.blogspot.com/2006/07/how-small-can-you-make-open-solaris.html

refer there for the latest update!
原创粉丝点击