Installing FreeBSD on a USB stick using buildworld
Installing FreeBSD to a USB stick is not hard. Someone have already done that using the simplest solution possible. But I want to install FreeBSD to a USB stick by using buildworld/installworld instead, so that I can make a simple NAS out of it.
This is how I did it:
Use csup to get the source
csup supfile
My supfile looks like this:
*default host=cvsup.no.FreeBSD.org
*default base=/var/db
*default prefix=/usr
*default release=cvs tag=RELENG_7_2
*default delete use-rel-suffix
*default compress
src-all
Build
Build world and kernel as described in /usr/src/UPDATING or take a look in the FreeBSD handbook. You may want a seperate src.conf(5) for this if you want.
cd /usr/src
rm -rf /usr/obj/*
make cleandir clean buildworld buildkernel SRCCONF=/etc/src-usb.conf
Prepare USB stick
While this may take some time you can begin preparing the USB stick. First you’ll plug the USB stick in your machine and look in /var/log/messages for something like this:
da0 at umass-sim0 bus 0 target 0 lun 0
Then make a partition the stick, label it and create a filesystem on the new slice. After that mount it to ensure that it works. The last step will install a bootloader.
fdisk -BI /dev/da0
bsdlabel -B -w da0s1
newfs -U /dev/da0s1a
mount /dev/ad0s1a /mnt
Install to USB stick
When buildworld and buildkernel is finished we need to install it on the stick.
cd /usr/src
make installworld installkernel distribution DESTDIR=/mnt SRCCONF=/etc/src-usb.conf
The last thing we need to do is to create /mnt/etc/fstab
/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
The only thing you need to do now is to unmount /mnt, the rest is…
Optional
Create a basic /mnt/etc/rc.conf
hostname=pony.your.lan
defaultrouter="192.168.0.1"
ifconfig_age0="inet 192.168.0.3 netmask 255.255.255.0"
sshd_enable="YES"
Add user
chroot /mnt /bin/sh
pw user add username -m -G wheel
passwd username
Unmount the stick
cd
umount /mnt
Create a backup of the stick
dd if=/dev/da0 of=freebsd-usb.img bs=50k
Posted in Everything
May 20th, 2009 at 12:12:54
Copied from http://www.mail-archive.com/freebsd-stable@freebsd.org/msg102306.html
Here’s the steps I use to create a 1GB USB image:
# dd if=/dev/zero of=bootable.image bs=1m count=1 oseek=1000 conv=sparse
# mdconfig -a -t vnode -f bootable.image -u 0
# newfs -m 0 -o space -n /dev/md0
# mount /dev/md0 /mnt
# cd /usr/src
# make installworld DESTDIR=/mnt
# make distribution DESTDIR=/mnt
# make installkernel DESTDIR=/mnt
# umount /mnt
At this point you have a file “bootable.image” but instead of actually making that a bootable dd image, I choose to create a dump file which is a bit more flexible as you can restore it to a USB stick of any size.
# dump -0 -C 8 -f – /dev/md0 | gzip -9 > bootable.dump.gz
# mdconfig -d -u 0
At this point, you have a dump file which you can use to create a bootable USB as follows:
Assuming the USB stick is /dev/da0 !
# dd if=/dev/zero of=/dev/da0 bs=16k
# fdisk -BI /dev/da0
# disklabel -B -w /dev/da0s1
# newfs -m 0 -o space -n /dev/da0s1a
# mount -o noatime,async /dev/da0s1a /mnt
# gzcat bootable.dump.gz | ( cd /mnt ; restore -rvf – )
# umount /mnt
November 9th, 2009 at 18:18:51
Thanks for the guide worked perfect !!!
December 12th, 2009 at 0:00:35
I really enjoyed reading your article, keep up writing such exciting stuff!!
January 14th, 2010 at 13:13:39
[...] Installing FreeBSD on a USB stick using buildworld [...]