Installing FreeBSD on a USB stick, episode II
Posted by Ceri Davies Thu, 13 Apr 2006 21:37:00 GMT
I previously wrote about putting a 6.1-BETA4 FreeBSD installation on a USB stick. Since the bugs that were in the 6.1-BETA4 installation have been fixed, plus to get 6.1-RC1 tested, here are updated instructions (which should work with 6.1-RELEASE as well).
These instructions result in a downloadable image suitable for dding direct to a USB stick of 512MB or larger.
arved pointed out that it’s good to minimize the amount of writes done to USB sticks (and flash memory in general), and I’ve got some pointers in these instructions, but I haven’t really looked at this point.
If you are looking to install FreeBSD from a USB stick, you should check out Dario Freni’s script.
Note
I assume that, like me, you don't have any SCSI disks and so your USB stick will show up on da0, at least while you're preparing it; we're using GEOM disk labels in the image so we don't care so much where the disk appears in the device tree. I'm also assuming that you don't care much for the data on your USB stick.
The installation
You'll need to grab the disc1 ISO — get the latest one.
- Mount that ISO on /dist:
# mkdir -p /dist
# mdconfig -a -f /a/FreeBSD/6.1-RC1-i386-disc1.iso
md1
# mount -t cd9660 /dev/md1 /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/da0We need a disk label:
# bsdlabel -B -w da0s1and a filesystem, which we'll mount on
/mnt. In order to reduce the number of writes to the USB pen, and as common practice, we use the-Uflag to enable soft updates. Additionally, so that we can find the filesystem easily no matter where the USB pen appears in the device tree, we will label the filesystem asFreeBSDonUSB:# newfs -U -L FreeBSDonUSB /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 /mntNow to do an install the blindingly easy way:
# cd /dist/6.1-RC1/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)? yWith 6.1, we are providing both uniprocessor and SMP kernels on the CD.
sysinstallwill install the correct one depending on your hardware configuration, but we need to decide. It's probably OK to just use the SMP one, but I have no multiprocessor machines, so will use the UP kernel. If you want the SMP kernel, just specifysmpwhere I havegenericbelow:# cd /dist/6.1-RC1/kernels # DESTDIR=/mnt ./install.sh generic # rmdir /mnt/boot/kernel # mv /mnt/boot/GENERIC /mnt/boot/kernelInstall the boot manager. We use the
noupdateoption to preventboot0writing itself back to disk every boot:# boot0cfg -v -B -o noupdate 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,noupdate,nosetdrv default_selection=F1 (Slice 1)Create an fstab(5) file on the USB stick. Here's a simple one that puts the logs on to memory storage (to try to minimize writes). We also null mount
/var/tmpon/tmp, which makes it non-persistent:# Device Mountpoint FStype Options Dump Pass# /dev/ufs/FreeBSDonUSB / ufs rw,noatime 1 1 md /tmp mfs rw,-s16M,nosuid,noatime 0 0 md /var/run mfs rw,-s4M,nosuid,noatime 0 0 md /var/log mfs rw,-s16M,nosuid,noatime 0 0 /dev/acd0 /cdrom cd9660 ro,noauto,nosuid 0 0 /proc /proc procfs rw,noauto 0 0 /tmp /var/tmp nullfs rw 0 0Since we're using the UFS label to define the root filesystem, we must force the GEOM label class to be loaded early:
# cat >> /mnt/boot/loader.conf << EOF geom_label_load="YES" EOFvi(1) likes to have a
/var/tmp/vi.recoveraround, so we ensure that it exists on boot. Pull down this example script and install it:# mkdir -p /mnt/usr/local/etc/rc.d/ # cd /mnt/usr/local/etc/rc.d/ # fetch http://people.freebsd.org/~ceri/FreeBSDonUSB/scripts/mkvirecover # chmod 555 mkvirecoverIn order for commands that use wtmp(5) to work correctly with
/var/logon a memory disk, we need to tell newsyslog(8) that it is OK to create an empty/var/log/wtmp. Edit/mnt/etc/newsyslog.confand addCto the/var/log/wtmpline:/var/log/wtmp 644 3 * @01T05 BCSet the interfaces to configure themselves over DHCP. I exclude
plip0andfwe0since they are practically never connected to a DHCP server, but are reasonably common:# cat >> /etc/rc.conf << EOF ifconfig_DEFAULT="DHCP" ifconfig_fwe0="NOAUTO" ifconfig_plip0="NOAUTO" EOFAgain, to reduce the number of writes to the USB key, we will pregenerate a locate database and then turn off the weekly update:
# chroot /mnt /bin/sh # mount_devfs devfs /dev # /etc/periodic/weekly/310.locate Rebuilding locate database: # cat >> /etc/periodic.conf << EOF weekly_locate_enable="NO" weekly_whatis_enable="NO" EOFInstall any packages you might want, and set a root password:
# chroot /mnt /bin/sh # passwd root # pkg_add -r lsof rsync unzip zsh kde...
That's it for now.
Very cool indeed. I don't have a 512MB+ USB stick, but I've now got a reason to get one :-) Thanks.
So cool! I'm gonna try it! Thx a bunch for this great tutorial.
leo, you may need to frig about in your BIOS to get it to boot from the USB stick. Mine just defaults to doing it if there is a stick inserted.
Very useful! how to install the usb storage? need to modify the boot file? thx a lot!
ceri,Thank you!I have installed freebsd on a usb 2.0 hard drive, and setup the boot sequence in bios,but can not boot into freebsd system after boot manager,some machine code is on the screen. I don't know why? so pls help me. thanks again.
The 0:fd(0,a) indicates that it is trying to boot from a floppy. Do you have a floppy in there, or does your BIOS make the USB stick look like one somehow? Try specifying da(0,a) at the loader prompt and see how that goes. By the way, why can't you mount UFS2 - using an older release?
Me either ;-)
hi, thank you for your reply :) i tried, but i still get the same prompt: Not ufs, and then the fd(0,a) story. specifying da(0,a)/boot/kernel/kernel gives "error 1 lba 0" and then the same boot: prompt. i'm using freebsd 6.1-Release, the pc is a decently recent asus pundit w an award medallion 6.0 bios (release 2003). no floppy and no hd. i don't know why i cannot mount the thumb driver if i format it w ufs2, but it keeped saying bad superblock until i tried ufs1...
i just tried on another (different) pc, and it booted. i don't know what's the problem with the other bios
How can I build custom Kernel on USB flash
hi, thank you for this article :) i have some problem, though: in the newfs phase i have to specify -O 1 to get an UFS v1 file system, otherwise I'm not able to mount the stick. the rest of the operations go well, but when i try to boot with the USB device i get this: Not ufs FreeBSD/i386 boot Default: 0:fd(0,a)/boot/loader boot: _ what am i missing? thank you.