Installing FreeBSD onto a USB stick

Posted by Ceri Davies Mon, 20 Mar 2006 22:55:00 GMT

Note: this is pretty much obsoleted by the followup article. You really should read that one instead.


It seems that a bunch of folks are ending up here by searching for instructions for installing FreeBSD on a USB stick, so here they are.

I'll assume that, like me, you don't have any SCSI disks and so your USB stick will show up on da0. I'm also assuming that you don't care much for the data on there.

The easy way

A little secret - the easy way to do this is to boot from the installation CDROM while you have the USB stick in and just install to it.

You didn't come here for that though, did you?

The slightly more involved way

It doesn't qualify as "hard".

You'll still need to grab that ISO — get the latest one.

  • Mount that ISO on /dist:
     # mkdir /dist
     # mdconfig -a -f /a/FreeBSD/6.1-BETA4-i386-disc1.iso
     md17
     # mount -t cd9660 /dev/md17 /dist
  • Insert the stick. They come preformatted with a FAT32 partition on, so we'll need to throw a BSD slice label on there — this command will destroy all existing slices. If you get a warning regarding "Geom not found", don't worry.:

    # fdisk -BI /dev/da0
    
  • We need a disk label:

    # bsdlabel -B -w da0s1
    
  • and a filesystem, which we'll mount on /mnt:

    # newfs -U /dev/da0s1a
    /dev/da0s1a: 481.0MB (985040 sectors) block size 16384, fragment size 2048
            using 4 cylinder groups of 120.25MB, 7696 blks, 15424 inodes.
            with soft updates
      super-block backups (for fsck -b #) at:
      160, 246432, 492704, 738976
    # mount /dev/da0s1a /mnt
    
  • Now to do an install the blindingly easy way:

    # cd /dist/6.1-BETA4/base
    # DESTDIR=/mnt ./install.sh 
    You are about to extract the base distribution into /mnt - are you SURE
    you want to do this over your installed system (y/n)? y
    
  • Since we are using 6.1-BETA4, there is some additional messing about to do. This is very likely to change in later release candidates (since it is somewhat broken), but this works for 6.1-BETA4:

    # cd /dist/6.1-BETA4/kernels
    # DESTDIR=/mnt sh ./install.sh generic
    # rmdir /mnt/boot/kernel
    # mv /mnt/GENERIC /mnt/boot/kernel
    
  • Make the USB stick bootable:

    # boot0cfg -v -B da0
    #   flag     start chs   type       end chs       offset         size
    1   0x80      0:  1: 1   0xa5    480: 63:32           32       985056
    
    
    version=1.0  drive=0x80  mask=0xf  ticks=182
    options=packet,update,nosetdrv
    default_selection=F1 (Slice 1)
    
  • Create an fstab(5) file on the USB stick. Here's a simple one:

    /dev/da0s1a /      ufs    rw                      1 1
    md          /tmp   mfs    rw,-s16M,nosuid,noatime 0 0
    /dev/acd0   /cdrom cd9660 ro,noauto,nosuid        0 0
    proc        /proc  procfs rw                      0 0
    
  • Install any packages you might want:

    # chroot /mnt /bin/sh
    # pkg_add -r lsof rsync unzip zsh kde...
    

You're done.

Posted in ,  | 4 comments | no trackbacks

Comments

  1. arved said 3 days later:
    I think the most interesting topic is, how to minimize write access to the flash, to increase the lifetime of the flash on the USB stick..
  2. ceri said 3 days later:
    Agreed. I'm still working on that myself, but will write something up should I feel confident in my solution.
  3. mdff said 2 months later:
    the line: "mv /mnt/GENERIC /mnt/boot/kernel" should read as: "mv /mnt/boot/GENERIC /mnt/boot/kernel" best regards.
  4. ceri said 2 months later:
    Actually, with the slightly buggy kernel dists in 6.1-BETA4, this was right. It's good in the RELEASE, as captured in the followup.

Trackbacks

Use the following link to trackback from your own site:
http://typo.submonkey.net/articles/trackback/67

Comments are disabled