OS Hacking and more.


Altering /sbin/init

In x86.microroot, we need to alter /sbin/init to prepare the ZFS boot volume and call up the proper init. This appears simple, but there are a few adjustments that need to be made to ensure that when we hand control over to init, it has all the environment characteristics it needs. After conclusive tests, I have come up with the following replacement /sbin/init, to be inserted in x86.microroot.
Basically what we is import the real root filesystem (ZFS) from the barebones(but functional) ramdisk image...Once that is done, we need to move/remount the special filesystems that kernel has setup in /device(and other places) to our new root. This is the bulk of the script, as these needed to be tweaked in just the right way...
Before you implement this, ensure that the following modifications have been made to x86.microroot:
- /mnt2 exists inside x86.microroot AND it is empty.
Further, you may want to copy the kernel modules present in /usr/kernel to /kernel; even though they are non-essential, they will initialize devices like /dev/pts, which are essential to the *correct* function of certain programs (eg. terminal/gterm).

#!/bin/bash -x

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

exec >/dev/msglog 2>&1
# /bin/bash

echo "initializing devices"
echo "remounting root"
mount -F ufs -o rw,remount /devices/ramdisk:a /

echo "preparing devfsadm"
devfsadm -I
devfsadm -P
#/usr/lib/devfsadm/devfsadmd -v
echo "finding devices"
ls /dev/dsk

echo "Importing rpool..."
zpool import -f rpool
zfs umount /opt
zfs umount -f /export/home
zfs umount -f /export
echo "Mounting root file system..."
mount -F zfs rpool/ROOT/opensolaris /mnt2
ls /mnt2

echo "mounting /proc, dev, etc.."
chroot /mnt2 /sbin/mount -F mntfs mnttab /etc/mnttab
chroot /mnt2 /sbin/mount -F proc /proc /proc

chroot /mnt2 /sbin/mount -F tmpfs /etc/svc/volatile /etc/svc/volatile

mount -F lofs /devices /mnt2/devices
(cd /dev && tar -cf - .) | (cd /mnt2/dev && tar -xf -)
chroot /mnt2 /sbin/mount -F dev /dev /dev

chroot /mnt2 /sbin/mount -F ctfs ctfs /system/contract
chroot /mnt2 /sbin/mount -F objfs objfs /system/object

chroot /mnt2 /sbin/mount -F sharefs sharefs /etc/dfs/sharetab
echo "autopush and soconfig..." >/dev/msglog
chroot /mnt2 /sbin/autopush -f /etc/iu.ap
chroot /mnt2 /sbin/soconfig -f /etc/sock2path

echo "Executing chroot /sbin/init"
exec chroot /mnt2 /sbin/init $@

Save this as /sbin/init. Make sure it has the same permissions as the /sbin/init originally had. You may need to change the owner as well:
in a superuser shell (su)

$ ls -l /sbin/init
-r-xr-xr-x 1 root sys 58044 Apr 26 18:42 /sbin/init

if it doesn't look like that (not including filesize or timestamp

$ chown root:sys /sbin/init
$ chmod 555 /sbin/init

Good Hunting!

Previous Step
Next Step

No comments: