If you’re wondering how to take the cool SmartOS iso that Joyent just released, and put it on a “real disk” that you can read/write to, here’s my (very) quick HOWTO, done using a VirtualBox VM.

This document draws heavily on Joyent internal documentation that came before this document (credit to those authors!), and scribbled notes during my 24-hour headstart with the ISO. Please leave any comments/corrections in the comments over at this blog post.

I’ve also tested this with VMWare fusion on a Mac, and with similar Joyent-produced operating system builds on real bare-metal machines. Note that the KVM Hypervisor won’t work (in almost all cases) inside another hypervisor (like Virtualbox or VMware). This procedure is really just educational, for those wanting to explore booting this from harddisk (rather than the ISO image) ASAP.

*warning* This document talks about reformatting hard disks, and otherwise modifying your computer system. If you don't know exactly what you're doing, please experiment in a VM, or on some disks that don't contain valuable data.

THIS DOCUMENT IS ALSO OUTDATED. I'M LEAVING IT ONLINE FOR GENERAL INFORMATION, BUT AS WRITTEN, THE RECENT SMARTOS INSTALLERS WILL ERASE YOUR DRIVES AND YOUR WORK DONE HERE. SmartOS is designed to run from a live-image. Don't hot-rod it onto a boot sector unless you really know what you're doing.

Getting started:

… that’s fine.  Now you know that you’ve got just “/dev/sda” as a disk, from that output.

root@ubuntu:~# fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd294cb2b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. 

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
          switch off the mode (command 'c') and change display units to
          sectors (command 'u').

If you do get that complaint about the partition table… just hit “w”, and you’ll write out a label:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
root@ubuntu:~#

… then run fdisk again to set up your partitions.

root@ubuntu:~# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

… create a new partition with “n”

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +500M

… set that partition’s type to “c”, which means “win95 FAT”

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

… create a second primary partition (that I use for zfs later)

Command (m for help): n
Command action
   e   extended

       p   primary partition (1-4)
    p
    Partition number (1-4): 2
    First cylinder (66-1044, default 66):
    Using default value 66
    Last cylinder, +cylinders or +size{K,M,G} (66-1044, default 1044):
    Using default value 1044

… also set that partition’s type, as above:

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): c
Changed system type of partition 2 to c (W95 FAT32 (LBA))

… save your work:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.    

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

… check your work:

root@ubuntu:~# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd294cb2b


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          65      522081    c  W95 FAT32 (LBA)
/dev/sda2              66        1044     7863817+   c  W95 FAT32 (LBA) 

… those two W95 FAT32 partitions mean you did it right. Now look to see the disk partition devices in the Lubuntu’s /dev directory:

root@ubuntu:~# ls /dev/sda*
/dev/sda  /dev/sda1  /dev/sda2    

…make a FAT filesystem on /dev/sda1:

root@ubuntu:~# mkfs.vfat /dev/sda1
mkfs.vfat 3.0.9 (31 Jan 2010)

… and mount it:

root@ubuntu:~# mount /dev/sda1 /mnt -o umask=0000
root@ubuntu:~# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
aufs                    512856    194580    318276  38% /
none                    504680       208    504472   1% /dev
/dev/sr0                558606    558606         0 100% /cdrom
/dev/loop0              522240    522240         0 100% /rofs
none                    512856         0    512856   0% /dev/shm
tmpfs                   512856        32    512824   1% /tmp
none                    512856        88    512768   1% /var/run
none                    512856         0    512856   0% /var/lock
/dev/sda1               521800         0    521800   0% /mnt
root@ubuntu:~# 

… that “/mnt” line is your mounted filesystem on that FAT disk partition

Now, copy the files from the SmartOS iso CD/DVD to your FAT filesystem.  I did this by rsync-ing them from another host:

root@ubuntu:~# rsync -avz --no-o --no-g ryan@10.0.1.105:/Volumes/CDROM/ /mnt
Password:
receiving file list ... done
./
boot.catalog
boot/
boot/grub/
boot/grub/menu.lst
boot/grub/stage1
boot/grub/stage2
boot/grub/stage2_eltorito
platform/
platform/root.password
platform/i86pc/
platform/i86pc/amd64/
platform/i86pc/amd64/boot_archive
platform/i86pc/amd64/boot_archive.gitstatus
platform/i86pc/amd64/boot_archive.manifest
platform/i86pc/kernel/
platform/i86pc/kernel/amd64/
platform/i86pc/kernel/amd64/unix


sent 288 bytes  received 169987263 bytes  7233512.81 bytes/sec
total size is 282328116  speedup is 1.66

Then, run grub, and make your FAT partition bootable:

root@ubuntu:~# grub
Probing devices to guess BIOS drives. This may take a long time.


       [ Minimal BASH-like line editing is supported.   For
         the   first   word,  TAB  lists  possible  command
         completions.  Anywhere else TAB lists the possible
         completions of a device/filename. ]


grub> find /boot/grub/stage1
 (hd0,0)


grub> root (hd0,0)


grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/fat_stage1_5" exists... no
 Running "install /boot/grub/stage1 (hd0) /boot/grub/stage2 p /boot/grub/menu.lst ".
.. succeeded
Done.


grub> quit

Eject the Lubuntu CD from your virtualbox media menu:

… and restart that VM, (ungracefully, you’re in a ramdisk, so who cares!)

… and reboot into SmartOS. After a bit, you should see this:

Now, log in (root/root), confirm that your boot stuff is on the disk (you booted, so it totally is, I swear… but confirm exactly where:)

[root@08-00-27-ed-e3-20 ~]# format < /dev/null
Searching for disks...done

c0t0d0: configured with capacity of 8.00GB

AVAILABLE DISK SELECTIONS:
       0. c0t0d0 &lt;ATA-VBOXHARDDISK-1.0 cyl 4094 alt 2 hd 128 sec 32>
          /pci@0,0/pci8086,2829@d/disk@0,0
Specify disk (enter its number):


[root@08-00-27-ed-e3-20 ~]# fstyp /dev/dsk/c0t0d0p1
pcfs
[root@08-00-27-ed-e3-20 ~]# fstyp /dev/dsk/c0t0d0p2
unknown_fstyp (no matches)
[root@08-00-27-ed-e3-20 ~]#

…mount the pcfs disk:

[root@08-00-27-ed-e3-20 ~]# mkdir /original-boot_media
[root@08-00-27-ed-e3-20 ~]# mount -F pcfs /dev/dsk/c0t0d0p1 /original-boot_media
[root@08-00-27-ed-e3-20 ~]# df -k
Filesystem            kbytes    used   avail capacity  Mounted on
/devices/ramdisk:a    270415  260712    9703    97%    /
/devices                   0       0       0     0%    /devices
/dev                       0       0       0     0%    /dev
ctfs                       0       0       0     0%    /system/contract
proc                       0       0       0     0%    /proc
mnttab                     0       0       0     0%    /etc/mnttab
swap                  687992     836  687156     1%    /etc/svc/volatile
objfs                      0       0       0     0%    /system/object
sharefs                    0       0       0     0%    /etc/dfs/sharetab
/devices/pseudo/lofi@0:1
                      385390  351552   33838    92%    /usr
/usr/lib/libc/libc_hwcap1.so.1
                      385390  351552   33838    92%    /lib/libc.so.1
fd                         0       0       0     0%    /dev/fd
swap                  687164       8  687156     1%    /tmp
swap                  687208      52  687156     1%    /var/run
/dev/dsk/c0t0d0p1     521800  275848  245952    53%    /original-boot_media
[root@08-00-27-ed-e3-20 ~]# 

… lay down a zfs zpool on that 2nd partition you made, so you can have some mountable, sane storage like a 21st century human:

[root@08-00-27-ed-e3-20 ~]# zpool create tank /dev/dsk/c0t0d0p2

[root@08-00-27-ed-e3-20 ~]# df -k
Filesystem            kbytes    used   avail capacity  Mounted on
/devices/ramdisk:a    270415  260717    9698    97%    /
/devices                   0       0       0     0%    /devices
/dev                       0       0       0     0%    /dev
ctfs                       0       0       0     0%    /system/contract
proc                       0       0       0     0%    /proc
mnttab                     0       0       0     0%    /etc/mnttab
swap                  682688     836  681852     1%    /etc/svc/volatile
objfs                      0       0       0     0%    /system/object
sharefs                    0       0       0     0%    /etc/dfs/sharetab
/devices/pseudo/lofi@0:1
                      385390  351552   33838    92%    /usr
/usr/lib/libc/libc_hwcap1.so.1
                      385390  351552   33838    92%    /lib/libc.so.1
fd                         0       0       0     0%    /dev/fd
swap                  681860       8  681852     1%    /tmp
swap                  681904      52  681852     1%    /var/run
/dev/dsk/c0t0d0p1     521800  275848  245952    53%    /original-boot_media
tank                 7676928      31 7676835     1%    /tank


[root@08-00-27-ed-e3-20 ~]# cp /original-boot_media/platform/i86pc/amd64/boot_archive /tank/boot_archive_copy


[root@08-00-27-ed-e3-20 ~]# lofidev=`lofiadm -a /tank/boot_archive_copy` ; echo lofi device is: $lofidev
lofi device is: /dev/lofi/2

Note that there’s a ufs filesystem in that “lofi device”:

[root@08-00-27-ed-e3-20 ~]# fstyp $lofidev
ufs
 

…then, mount it!

[root@08-00-27-ed-e3-20 ~]# fsck $lofidev
** /dev/rlofi/2
** Last Mounted on /tmp/create_ramdisk.644542.tmp/rd.mnt.32
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3a - Check Connectivity
** Phase 3b - Verify Shadows/ACLs
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cylinder Groups
2158 files, 259907 used, 10508 free (160 frags, 2587 blocks, 0.1% fragmentation)
[root@08-00-27-ed-e3-20 ~]#
[root@08-00-27-ed-e3-20 ~]# mkdir /bootarchive_working_copy_mount
[root@08-00-27-ed-e3-20 ~]# mount $lofidev /bootarchive_working_copy_mount
[root@08-00-27-ed-e3-20 ~]# df -k
Filesystem            kbytes    used   avail capacity  Mounted on
/devices/ramdisk:a    270415  260737    9678    97%    /
/devices                   0       0       0     0%    /devices
/dev                       0       0       0     0%    /dev
ctfs                       0       0       0     0%    /system/contract
proc                       0       0       0     0%    /proc
mnttab                     0       0       0     0%    /etc/mnttab
swap                  401028     836  400192     1%    /etc/svc/volatile
objfs                      0       0       0     0%    /system/object
sharefs                    0       0       0     0%    /etc/dfs/sharetab
/devices/pseudo/lofi@0:1
                      385390  351552   33838    92%    /usr
/usr/lib/libc/libc_hwcap1.so.1
                      385390  351552   33838    92%    /lib/libc.so.1
fd                         0       0       0     0%    /dev/fd
swap                  400200       8  400192     1%    /tmp
swap                  400244      52  400192     1%    /var/run
/dev/dsk/c0t0d0p1     521800  275848  245952    53%    /original-boot_media
tank                 7676928  272221 7404470     4%    /tank
/dev/lofi/2           270415  260935    9480    97%    /bootarchive_working_copy_mount
[root@08-00-27-ed-e3-20 ~]# 


Now, let's change the root password:


[root@08-00-27-ed-e3-20 ~]# grep root /etc/shadow
root:$5$2HOHRnK3$NvLlm.1KQBbB0WjoP7xcIwGnllhzp2HnT.mDO7DpxYA:14897::::::
[root@08-00-27-ed-e3-20 ~]#
[root@08-00-27-ed-e3-20 ~]#
[root@08-00-27-ed-e3-20 ~]# passwd root
New Password:
Re-enter new Password:
passwd: password successfully changed for root
[root@08-00-27-ed-e3-20 ~]#
[root@08-00-27-ed-e3-20 ~]# grep root /etc/shadow
root:$5$XkkqmFRE$nvgOs2GGDHV/gDtFIj4KPgt5IUChabi.E/ldtIX8Uh1:15201::::::

...compare the shadow passwords from the running system (in ramdisk) and in your mounted boot_archive:



[root@08-00-27-ed-e3-20 ~]# diff /etc/shadow /bootarchive_working_copy_mount/etc/shadow
1c1
< root:$5$XkkqmFRE$nvgOs2GGDHV/gDtFIj4KPgt5IUChabi.E/ldtIX8Uh1:15201::::::
---
> root:$5$vSMLW40i$tFNnlQT7AmzcCnHdv8eX24u9wYUnMseZsdGTf28bvz4:14897::::::

Copy the new shadow file into the boot_archive:


[root@08-00-27-ed-e3-20 ~]# cp /etc/shadow /bootarchive_working_copy_mount/etc/shadow

tweak the /etc/motd file, as a proof-of-concept for editing things in the boot_archive:


[root@08-00-27-ed-e3-20 ~]# echo 'special Ryan-customized version!' >> /bootarchive_working_copy_mount/etc/motd
[root@08-00-27-ed-e3-20 ~]#

... unmount your boot archive, and copy the "file that is a device" back onto your original boot media:


[root@08-00-27-ed-e3-20 ~]# umount /bootarchive_working_copy_mount
[root@08-00-27-ed-e3-20 ~]# lofiadm
Block Device             File                           Options
/dev/lofi/1              /usr.lgz                       Compressed(gzip)
/dev/lofi/2              /tank/boot_archive_copy        -
[root@08-00-27-ed-e3-20 ~]# cp /tank/boot_archive_copy /boot
boot/                           bootarchive_working_copy_mount/
[root@08-00-27-ed-e3-20 ~]# cp /tank/boot_archive_copy /original-boot_media/platform/i86pc/amd64/boot_archive
[root@08-00-27-ed-e3-20 ~]# df -k
Filesystem            kbytes    used   avail capacity  Mounted on
/devices/ramdisk:a    270415  260741    9674    97%    /
/devices                   0       0       0     0%    /devices
/dev                       0       0       0     0%    /dev
ctfs                       0       0       0     0%    /system/contract
proc                       0       0       0     0%    /proc
mnttab                     0       0       0     0%    /etc/mnttab
swap                  465472     836  464636     1%    /etc/svc/volatile
objfs                      0       0       0     0%    /system/object
sharefs                    0       0       0     0%    /etc/dfs/sharetab
/devices/pseudo/lofi@0:1
                      385390  351552   33838    92%    /usr
/usr/lib/libc/libc_hwcap1.so.1
                      385390  351552   33838    92%    /lib/libc.so.1
fd                         0       0       0     0%    /dev/fd
swap                  464644       8  464636     1%    /tmp
swap                  464688      52  464636     1%    /var/run
/dev/dsk/c0t0d0p1     521800  275848  245952    53%    /original-boot_media
tank                 7676928  272221 7404639     4%    /tank
[root@08-00-27-ed-e3-20 ~]# umount /original-boot_media
[root@08-00-27-ed-e3-20 ~]#
[root@08-00-27-ed-e3-20 ~]# reboot

… now… although we changed root’s entry in /etc/shadow, and put it into our working copy of boot_archive, and then installed that boot_archive, you’ll notice that root’s password is still unchanged after a reboot.

That’s because our grub menu actually passes in a boot argument that specifies the root password at boot time.  That overrides our chosen password.

If you really want to change your password, then you should either put the hash of the password (you can retrieve that hash from /etc/shadow after you  run the “passwd” command to change it) into the boot arguments in  /original-boot_media/boot/grub/menu.lst , or you can remove the  ”root_shadow=… ” argument from the menu.lst altogether, and it’ll use what you’ve placed in the /etc/shadow file (that’s inside the boot_archive filesystem’s mountpoint)

Finally, with the zpool we created earlier, (and it’s automatically-created top-level zfs filesystem) “tank” , you have easily-mountable, writable filesystem space.  Where I’ve left these instructions, you’ll need to import the pool after boot by running:    zpool import -f tank

… we’ll discuss how to make that import and mount more automatic and permanent in a later post.