Skip to content

Instantly share code, notes, and snippets.

@bdha
Last active April 7, 2018 10:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdha/543bdc8b1fc16252b910 to your computer and use it in GitHub Desktop.
Save bdha/543bdc8b1fc16252b910 to your computer and use it in GitHub Desktop.
Modify a SmartOS vmware platform image

Using OS X and vmware Fusion. Requires an actual Solarish system or VM to modify the boot_archive.

Why would you want to do this? Well, it's an easy way of modifying an excellent platform for your own nefarious ends. Maybe you want to inject some extra (or less) work into the install scripts. Or just add some extra default services. Or drop in some leet figlet into /etc/issue. Or more usefully: Drop your application bootstrapping code into the platform to create turnkey appliances.

Prep

Download and decompress the SmartOS VMware image.

Copy the boot image out of the VM directory and mount it.

$ open ~/vms/smartos-latest.vmware/smartos.img

The image is now mounted as /Volumes/NONAME.

Copy the boot archive from the image to a SmartOS VM and log into it.

scp /Volumes/NONAME/platform/i86pc/amd64/boot_archive root@10.0.1.90:/var/tmp/
$ ssh root@10.0.1.90

Once you're on the box, you need to mount the boot archive via lofi.

# lofiadm -a /var/tmp/boot_archive
/dev/lofi/2
# mkdir /mnt/boot_archive
# mount -F ufs -o nologging /dev/lofi/2 /mnt/boot_archive

From /mnt/boot_archive you can now modify all sorts of things, like /etc/issue, or add default SMF services to /lib/svc/manifest/site.

Modifying /usr

One of SmartOS’s features is the hypervisor is mostly immutable. Thus, /usr is read-only. This is great, unless you need to modify something in /usr. (For instance, if you have legacy pkgsrc builds in /usr/pkg, or .. any number of reasons.)

There are an extra few hoops to jump through to modify /usr on the platform:

# cp /mnt/boot_archive/usr.lgz /var/tmp
# lofiadm -U /var/tmp/usr.lgz
# lofiadm -a /var/tmp/usr.lgz
/dev/lofi/3
# mkdir /mnt/usr
# mount -F ufs -o nologging /dev/lofi/3 /mnt/usr

When you are done modifying /mnt/usr, you need to unwind your changes and copy the modified usr.lgz back into /mnt/boot_archive.

# umount /mnt/usr
# lofiadm -d /dev/lofi/3
# lofiadm -C /var/tmp/usr.lgz
# cp /var/tmp/usr.lgz /mnt/boot_archive/

Unwinding boot_archive

# umount /mnt/boot_archive
# lofiadm -d /dev/lofi/2

Finishing up

Copy your modified image back into the vmware directory, unmount the SmartOS platform image, and put it back in place.

$ scp root@10.0.1.90:/var/tmp/boot_archive /Volumes/NONAME/platform/i86pc/amd64/
$ diskutil umount /Volumes/NONAME

Boot your VM.

comeatme

[root@00-0c-29-ad-58-f7 ~]# svcs -a | grep helium
online         23:31:02 svc:/site/helium-init:default

[root@00-0c-29-ad-58-f7 ~]# cat /lib/svc/method/helium-init
#!/bin/sh

. /lib/svc/share/smf_include.sh

# XXX This should be an etherstub.
echo "Creating int0 device"
if ! dladm show-vnic int0; then
  dladm create-vnic -l e1000g0 int0
  ifconfig int0 plumb
  ifconfig int0 up
  ifconfig int0 172.16.100.250 netmask 255.255.255.0
fi

[root@00-0c-29-ad-58-f7 ~]# dladm show-vnic
LINK         OVER       SPEED MACADDRESS        MACADDRTYPE VID  ZONE
int0         e1000g0    1000  2:8:20:34:ab:19   random      0    --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment