OS Hacking and more.

8.30.2008

Automated Installer for OpenSolaris Live USB

It's here...
I've created a program that will convert a standard OpenSolaris Install to a portable ZFS-based OpenSolaris Live Install. It automates the steps described in my previous posts as to how to make an OpenSolaris Install live usb with ZFS, and can be applied to a generic OpenSolaris install on either USB or fixed disk.

Simply put, it creates the modified ramdisk image necessary to boot OpenSolaris regardless of its root device, and injects that image into the installation correctly.

The automated installer can be run in one of two ways:
When supplied only the modified /sbin/init script
, it will assemble the rest of the necessary components for live boot, and install them accordingly.


Usage


This program should be run from a OpenSolaris [Indiana] liveCD or DVD.
Your target disk must have more than 4gb of space. It may be a USB disk, or otherwise



0) Install OpenSolaris to the target disk using the installer, and boot from it for the first time. Do not move the drive to a different port or computer
[You may skip this step for an exisiting install.
1) Boot from the liveCD, Open a superuser shell and
2) Import the zfs pool that contains OpenSolaris: zpool import -f [poolname]
3) Prepare the autoinstaller:
a) Create the following directory structure (or extract it from the zip archive)--> ./convert
./convert/proto
./convert/proto/sbin
b) Place zfsconverter in ./convert and init(the script) in ./convert/proto/sbin/.
c) Fix the permissions: chmod 555 /sbin/init && chown root:sys /sbin/init.
also, chmod +x ./convert/zfsconverter
d) Check that the "protodir" in zfsconverter is set to /[path to .]/convert/proto
4) execute zfsconverter


Note that if you wish to customize your installation with special components: scripts, kernel modules, etc, you may place these files inside the protodir, from where they will be copied into the microroot image.


---
The Script


#!/bin/bash

#########################################################
# Author: Anand Gupta
# 8/29/2008 - Sun Microsystems Labs
# zfsconverter
#########################################################

PATH=/bin/:/sbin/:/usr/bin/:/usr/sbin/

##Target settings
bootfs=rpool/ROOT/opensolaris
ramdisk=/media/OpenSolaris-2008-05/boot
zfsroot=/rpool

##Options
tempdir=/rpool

protodir=/root/convert/proto

##populate generic protodir from LiveCD
popproto()
{
mkdir -p ${protodir}/kernel
mkdir -p ${protodir}/mnt2
mkdir -p ${protodir}/usr/lib/fs/cachefs
mkdir -p ${protodir}/usr/lib/fs/ctfs
mkdir -p ${protodir}/usr/lib/fs/fd
mkdir -p ${protodir}/usr/lib/fs/dev
mkdir -p ${protodir}/usr/lib/fs/lofs
mkdir -p ${protodir}/usr/lib/fs/mntfs
mkdir -p ${protodir}/usr/lib/fs/proc
mkdir -p ${protodir}/usr/lib/fs/sharefs
mkdir -p ${protodir}/usr/lib/fs/tmpfs
mkdir -p ${protodir}/usr/lib/fs/zfs

(cd /usr/kernel/ && tar -cf - .) | (cd ${protodir}/kernel/ && tar -xf -)

(cd /usr/lib/fs/cachefs && tar -cf - .) | (cd ${protodir}/usr/lib/fs/cachefs && tar -xf -)
(cd /usr/lib/fs/ctfs && tar -cf - .) | (cd ${protodir}/usr/lib/fs/ctfs && tar -xf -)
(cd /usr/lib/fs/fd && tar -cf - .) | (cd ${protodir}/usr/lib/fs/fd && tar -xf -)
(cd /usr/lib/fs/dev && tar -cf - .) | (cd ${protodir}/usr/lib/fs/dev && tar -xf -)
(cd /usr/lib/fs/lofs && tar -cf - .) | (cd ${protodir}/usr/lib/fs/lofs && tar -xf -)
(cd /usr/lib/fs/mntfs && tar -cf - .) | (cd ${protodir}/usr/lib/fs/mntfs && tar -xf -)
(cd /usr/lib/fs/proc && tar -cf - .) | (cd ${protodir}/usr/lib/fs/proc && tar -xf -)
(cd /usr/lib/fs/sharefs && tar -cf - .) | (cd ${protodir}/usr/lib/fs/sharefs && tar -xf -)
(cd /usr/lib/fs/tmpfs && tar -cf - .) | (cd ${protodir}/usr/lib/fs/tmpfs && tar -xf -)
(cd /usr/lib/fs/zfs && tar -cf - .) | (cd ${protodir}/usr/lib/fs/zfs && tar -xf -)

# sh ${protodir}/additions.sh
}

##Preparation of filesystems
preparemounts()
{
mkdir /mntzfs
mount -F zfs ${bootfs} /mntzfs
mkdir /mntram
gzip -dc ${ramdisk}/x86.microroot > ${tempdir}/microroot.img
mount `lofiadm -a ${tempdir}/microroot.img` /mntram
}

##Unmount filesystems
umountall()
{
umount /mntram
lofiadm -d ${tempdir}/microroot.img
gzip -c1 ${tempdir}/microroot.img > ${tempdir}/x86.microroot
rm -f /mntzfs/boot/x86.microroot
mv ${tempdir}/x86.microroot /mntzfs/boot/
umount /mntzfs
echo "scrub zpool...if any errors arise, fix them and rerun this program"
zpool status
echo "if there are no errors, the installation process has suceeded"
}

##Fix Menu.lst
fixmenulst(){
echo "####"
echo "title Opensolaris Portable" >> ${zfsroot}/boot/grub/menu.lst
echo "bootfs ${bootfs}" >> ${zfsroot}/boot/grub/menu.lst
echo "kernel$ /platform/i86pc/kernel/\$ISADIR/unix " >> ${zfsroot}/boot/grub/menu.lst
echo "module /boot/x86.microroot " >> ${zfsroot}/boot/grub/menu.lst
echo "####"
}

echo Initializing installation, ensure that all prerequisites are fulfilled
echo "mounting filesystems"
preparemounts

echo "preparing protodir"
popproto

echo "copying files"
(cd ${protodir} && tar -cf - .) | (cd /mntram && tar -xf -)

echo "umounting filesystems"
umountall

echo "fixing menu.lst"
fixmenulst

echo "Done...Reboot to continue"



I'll attach the self-contained zip and an example microroot soon.

No comments: