Wednesday, June 28, 2006

ZFS root on Solaris

Below is the log of commands I used to have a ZFS root partition with a small ufs for grub. Before I was swapping between 2 root partitions for upgrade, with everything I wanted to keep between upgrades on a ZFS partition. This time I divided one of the root partitions into a small UFS partition, and the rest I used as a ZFS root.

The next step is a total backup (done), and repartition the disk into a small UFS boot partition for grub boots, a ~4GB ufs install partition, and the rest including root will be all on one ufs partition. On a laptop, the extra diskspace is very handy. I will also spend some time on writing better notes :-)

newfs /dev/dsk/c0d0s0
if [ ! -d /altroot ]; then
mkdir -m 0755 /altroot
echo "/dev/dsk/c0d0s0 /dev/rdsk/c0d0s0 /altroot ufs 3 yes -" >> /etc/vfstab
mount /altroot
zpool create -m none rootdisk c0d0s4
zfs create rootdisk/root
zfs set mountpoint=legacy rootdisk/root
zfs set compression=on rootdisk/root

rootdisk/root - /zfsroot zfs - yes -

cd /zfsroot
ufsdump 0f - / | ufsrestore -rf -

echo "rootfs:zfs" >> /zfsroot/etc/system
echo "zfsroot:rootdisk/root" >> /zfsroot/etc/system
echo "etc/zfs/zpool.cache" >> /zfsroot/boot/solaris/filelist.ramdisk
grep -v 'rootdisk/root' /etc/vfstab | awk '$3 == "/" { printf "rootdisk/root\t-\t/\tzfs\t-\tno\t-\n" } ; $3 != "/" { print $0 }' > /zfsroot/etc/vfstab
mv /zfsroot/sbin/bootadm /zfsroot/sbin/bootadm.real

cat - > /zfsroot/sbin/bootadm << EOM

/sbin/bootadm.real "\$@"
/usr/bin/cp /platform/i86pc/boot_archive /boot/boot_archive
exit 0

chmod +x /zfsroot/sbin/bootadm
/usr/sbin/bootadm update-archive -R /zfsroot
cp -pr /zfsroot/boot /altroot
cp /zfsroot/platform/i86pc/boot_archive /altroot/boot/boot_archive

echo "title Solaris ZFS"
echo "kernel /boot/multiboot"
echo "module /boot/boot_archive"
) >> /altroot/boot/grub/menu.lst

cd /altroot/boot/grub
installgrub stage1 stage2 /dev/rdsk/c0d0s0

No comments: