Richard Bucker

Formatting a USB drive for NixOS

Posted at — Jan 10, 2015

Recently I posted some general instructions on installing NixOS on a USB drive. One area I was having trouble with was the basic format of the drive. At the time I decided to use a SmartOS USB image and a little ‘dd’ magic to copy the image file from the local drive to the USB stick. Since then I have worked out the missing pieces.With a booted OS X where the USB drive is located at /dev/disk2 …sudo fdisk -e /dev/disk2fdisk> auto dosfdisk> f 1fdisk> wfdisk> qNow you have a msdos formatted(partition table) USB drive. At this point I followed a few of the same steps to be able to connect the USB drive from the host OS X to the quest NixOS. Keep in mind that the USB stick is currently partitioned with partition 1 as the active boot partition; but not formatted so it cannot be mounted just yet.With NixOS booted and at a console (where the USB drive is located at /dev/sdb and the fat partition is at /dev/sdb1) …format the partition sudo mkdosfs /dev/sdb1net-env -i wgetnet-env -i unetbootinmkdir -p /media/{NIXBOOT,iso}mount -o loop nixos.iso /media/isocp -a /media/iso/. /media/NIXBOOTnow you can mount the partition sudo mount -t vfat /dev/sdb1 /media/NIXBOOTand now you can follow the instructions about unetbootin from the other postunetbootin works great if you have X installed. This might be a starting point: unetbootin lang=en method=diskimage isofile=./nixos.iso installtype=USB targetdrive=/dev/sdb1 autoinstall=yes