# How do I install FreeBSD 9.0 to a USB stick?



## papelboyl1 (Jun 11, 2012)

I don't mean installing *from* a USB stick. But installing the OS *to* a USB stick.

Thanks. â˜º

Ps. I've searched but nothing rally useful came up,


----------



## wblock@ (Jun 11, 2012)

A USB stick is seen as just another drive.  Boot the FreeBSD installer and select the USB stick as the target.


----------



## throAU (Jun 18, 2012)

wblock@ said:
			
		

> A USB stick is seen as just another drive.  Boot the FreeBSD installer and select the USB stick as the target.



Would also suggest using a disklabel, to avoid the possibility of boot failure due to the device name changing when other USB devices are plugged in.


----------



## papelboyl1 (Jun 18, 2012)

throAU said:
			
		

> Would also suggest using a disklabel, to avoid the possibility of boot failure due to the device name changing when other USB devices are plugged in.



*C*ould you please explain? *M*aybe a link? *T*hanks


----------



## throAU (Jun 18, 2012)

Sorry I actually meant `# glabel`.

Sorry I'm not sure where to find a howto, but the concept is described here

You'll want to have a read through there, and maybe experiment with glabel in a virtual machine copy (or physical machine BEFORE you put all your data back on it) of FreeBSD first.

If you don't label your USB stick, you'll eventually boot up with some other USB storage device plugged in and the root filesystem will be missing


----------



## kpa (Jun 18, 2012)

For maximum compatibility you should use MBR partitioning on a USB stick. Instead of glabel(8) you can use UFS filesystem labels that appear under /dev/ufs.

This is how I would prepare a USB memory stick for install, da0 is the device name for the stick in this example.

`# gpart create -s MBR da0`
`# gpart add -t freebsd da0`
`# gpart create -s BSD da0s1`
`# gpart add -b 16 -t freebsd da0s1`

I add only one partition that fills the whole stick, no swap. Modify this scheme for your own needs.

Set the first slice active:

`# gpart -a active -i 0 da0`

These install the boot code:
`# gpart bootcode -b /boot/mbr da0`
`# gpart bootcode -b /boot/boot da0s1`

Create a filesystem on /dev/da0s1a and call it myroot

`# newfs -j -L myroot /dev/da0s1a`

Then just mount the filesystem under /mnt

`# mount /dev/ufs/myroot /mnt`

Then proceed with the install. Either manually extract the distribution or use bsdinstall(8).


----------



## wblock@ (Jun 18, 2012)

Should also set the first slice active:
`# gpart set -a active -i 1 da0`

But really, use GPT unless you have a particular reason not to, like having one of those Lenovo Thinkpads with broken BIOS.
GPT is simpler and lets you assign labels to the partitions:
`# gpart create -s gpt da0`
`# gpart add -t freebsd-boot -l myboot   -s 512k da0`
`# gpart add -t freebsd-ufs  -l myrootfs -s 20g  da0`
`# gpart add -t freebsd-swap -l myswap   -s 256M da0`
`# gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 da0`

Those labels appear in /dev/gpt.  (Swap included because FreeBSD really wants to have some, see tuning(7).)


----------



## kpa (Jun 18, 2012)

I've seen surprising number of machines that have no problem with GPT on a SATA or PATA disk but completely fail to boot if GPT is used on a USB disk of any kind.


----------

