RaspberryPI is a cheap yet highly capable pico-computer that I recently purchased along with a 16Gb SD-card for storage. As my operating system of choice is FreeBSD, naturally I’d like to install the PI using just that.
FreeBSD/arm is available in FreeBSD 10 which is still at beta-phase. For the time being the easiest way is to download the latest image from freebsdarm.org. As only 4Gb and 8Gb images are available, the first order of business is to extend it so that all of the 16Gb SD-card is put to use.
After uncompressing the image, it can be mounted as a memory disk while writing changes made to the imagefile. The 16Gb SD-card has been inserted and recognised as /dev/da0. Naturally as with almost all flashmedia it comes preformated as a FAT32 disk.
root@server:~> mdconfig -a -t vnode -f freebsd-pi-8G-r249581.img -u 1
root@server:~> gpart show md1
=> 63 15429624 md1 MBR (7.4G)
63 65520 1 !12 [active] (32M)
65583 15364062 2 freebsd (7.3G)
15429645 42 - free - (21k)
root@server:~> gpart show da0
=> 63 30881729 da0 MBR (14G)
63 8129 - free - (4M)
8192 30873600 1 !12 (14G)
We need an image file that will fit onto the SD-card. By transferring it using dd, we're making an image that's also guaranteed to fit.
root@server:~> dd if=/dev/da0 of=./16Gb_formated.img bs=1m
Now mount that as /dev/md2
root@server:~> mdconfig -a -t vnode -f 16Gb_formated.img -u 2
root@server:~> gpart show md2
=> 63 30881729 md2 MBR (14G)
63 8129 - free - (4M)
8192 30873600 1 !12 (14G)
root@server:~> gpart show md1
=> 63 15429624 md1 MBR (7.4G)
63 65520 1 !12 [active] (32M)
65583 15364062 2 freebsd (7.3G)
15429645 42 - free - (21k)
Then write the FreeBSD/arm image file onto our newly made memorydisk
root@server:~> dd if=/dev/md1 of=/dev/md2 bs=1M
7534+1 records in
7534+1 records out
7899999744 bytes transferred in 1142.792356 secs (6912892 bytes/sec)
root@server:~> gpart show md2
=> 63 30881729 md2 MBR (14G)
63 65520 1 !12 [active] (32M)
65583 15364062 2 freebsd (7.3G)
15429645 15452147 - free - (7.4G)
root@server:~> gpart show md2s2
=> 0 15364062 md2s2 BSD (7.3G)
0 6873088 1 freebsd-ufs (3.3G)
6873088 8490974 2 freebsd-swap (4.0G)
Now we have a 16Gb image with a whole lot of space in it. Now comes the time to expand that space.
First increase the partition.
root@server:~> gpart resize -i 2 md2
md2s2 resized
root@server:~> gpart show md2
=> 63 30881729 md2 MBR (14G)
63 65520 1 !12 [active] (32M)
65583 30816198 2 freebsd (14G)
30881781 11 - free - (5.5k)
Then delete the swap partition, making room to expand the ufs partition on the freebsd-slice.
root@server:~> gpart delete -i 2 md2s2
md2s2b deleted
root@server:~> gpart show md2s2
=> 0 15364062 md2s2 BSD (14G)
0 6873088 1 freebsd-ufs (3.3G)
6873088 8490974 - free - (4.0G)
In order to be able to update gpart's notion of how much data can fit within the slice, the disk needs to be reinserted. As we're making use of a memory disk that's easy.
root@server:~> mdconfig -d -u 2
root@server:~> gpart show md2
gpart: No such geom: md2.
root@server:~> mdconfig -a -t vnode -f 16Gb_formated.img -u 2
root@server:~> gpart show md2
=> 63 30881729 md2 MBR (14G)
63 65520 1 !12 [active] (32M)
65583 30816198 2 freebsd (14G)
30881781 11 - free - (5.5k)
root@server:~> gpart show md2s2
=> 0 30816198 md2s2 BSD (14G)
0 6873088 1 freebsd-ufs (3.3G)
6873088 23943110 - free - (11G)
Then we can increase the partition within the freebsd-slice and add a swap partition at the end of it.
root@server:~> gpart resize -s 13G -i 1 md2s2
md2s2a resized
root@server:~> gpart show md2s2
=> 0 30816198 md2s2 BSD (14G)
0 27262976 1 freebsd-ufs (13G)
27262976 3553222 - free - (1.7G)
root@server:~> gpart add -t freebsd-swap md2s2
md2s2b added
root@server:~> gpart show md2s2
=> 0 30816198 md2s2 BSD (14G)
0 27262976 1 freebsd-ufs (13G)
27262976 3553222 2 freebsd-swap (1.7G)
The last step is to increase the filesystem ontop of the root partition within the freebsd-slice. The question asked about having backed up the disk need to be answered capitalized. Or you can throw a -y
flag to growfs if you're feeling brave enough.
root@server:~> growfs /dev/md2s2a
We strongly recommend you to make a backup before growing the Filesystem
Did you backup your data (Yes/No) ? Yes
new file systemsize is: 3407872 frags
Warning: 335936 sector(s) cannot be allocated.
growfs: 13148.0MB (26927040 sectors) block size 32768, fragment size 4096
using 21 cylinder groups of 626.09MB, 20035 blks, 80256 inodes.
with soft updates
super-block backups (for fsck -b #) at:
7693632, 8975872, 10258112, 11540352, 12822592, 14104832, 15387072, 16669312,
17951552, 19233792, 20516032, 21798272, 23080512, 24362752, 25644992
Verify that it can be mounted
root@server:~> mount /dev/md2s2a /mnt
root@server:~> df -h /mnt
Filesystem Size Used Avail Capacity Mounted on
/dev/md2s2a 12G 1.3G 10G 11% /mnt
root@server:~> ls /mnt
./ .sujournal etc/ mnt/ sbin/
../ COPYRIGHT home/ opt/ sys@
.cshrc bin/ lib/ proc/ tmp/
.profile boot/ libexec/ rescue/ usr/
.snap/ dev/ media/ root/ var/
That's how you expand a volume. As for transferring the image onto the SD-card, a final step remains. You may want to edit some configuration files in /etc
, most notably /etc/rc.conf
, on the mounted filesystem before that. First of, run fsck as to not run into any surprises when booting from the SD-card.
root@server:~> fsck -t ufs /dev/md2s2a
** /dev/md2s2a
** Last Mounted on /tmp/mnt
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
188890 files, 333580 used, 2926603 free (51 frags, 365819 blocks, 0.0% fragmentation)
***** FILE SYSTEM IS CLEAN *****
root@server:~> dd if=/dev/md2 of=/dev/da0 bs=1M
15079+0 records in
15079+0 records out
15811477504 bytes transferred in 1868.344856 secs (8462826 bytes/sec)
root@server:~> gpart show md2
=> 63 30881729 md2 MBR (14G)
63 65520 1 !12 [active] (32M)
65583 30816198 2 freebsd (14G)
30881781 11 - free - (5.5k)
root@server:~> gpart show da0
=> 63 30881729 da0 MBR (14G)
63 65520 1 !12 [active] (32M)
65583 30816198 2 freebsd (14G)
30881781 11 - free - (5.5k)
However, it will only see 128Mb of memory which is a bit low and you might run into problems where the sd-card isn't recognised fast enough by FreeBSD upon booting resulting in not finding a valid root-partition. The former is addressed by editing config.txt in the boot-loader partition.
root@server:~> mount -t msdosfs /dev/da0s1 /mnt
root@server:~> cat /mnt/config.txt
kernel=uboot.img
#gpu_mem=128
device_tree=rpi-b.dtb
device_tree_address=0x100
disable_commandline_tags=1
Change #gpu_mem=128
to gpu_mem=16
. Valid numbers range from 16 to 256 in increments of powers of two but strangely enough, not 32. If you have no intention of running anything graphical from it, select 16.
As for the other issues, edit /boot/loader.rc
on the FreeBSD root-partition and add the following.
set hw.bcm2835.sdhci.hs="0"
set hw.bcm2835.min_freq="8000000"
fdt addr 0x100
The last line is required for honouring the gpu_mem
setting above as well as having the MAC-address on the NIC coming from the eprom on the NIC instead of the one statically set at kernel compilation.
Recent Comments