Resizing FreeBSD partitions on an SD card for Raspberry Pi Using gpart and growfs 7

UPDATE 2: Newer instructions here: https://github.com/daveish/freebsd-arm-tools/blob/master/README.md#extracting-and-writing-images

UPDATE 1: You cannot blindly cut and paste the commands below and get any results.  You must read and understand what is happening from one command to the next.  This is an example, which is intended to provide a practical example of how to do this yourself.

Below is (an admittedly quick and dirty) terminal session save in which I was able to grow the FreeBSD filesystem to fill my 16GB SDHC card for Raspberry Pi. I am still a little fuzzy on the math, but it seems that 2150400 is the magic multiplier for gigabytes. That is, 13.8GB * 2150400 = 29675520, which is the number I used for size when adding the partition. Note that the freebsd-ufs partition must start where it originally did when you delete and then re-add it. Also note that the SD card was not mounted while I was working on it. I plugged it in to another FreeBSD system to manipulate the sizes.

Hat tips:
http://kernelnomicon.org/?p=246
http://dave.cheney.net/2012/12/31/testing-go-on-the-raspberry-pi-running-freebsd
http://lists.freebsd.org/pipermail/freebsd-arm/2012-December/004331.html
http://www.peach.ne.jp/archives/rpi/

╰─$ gpart show

=> 63 31047617 da1 MBR (14G)
63 64197 1 !12 [active] (31M)
64260 7513317 2 freebsd (3.6G)
7577577 23470103 - free - (11G)

=> 0 64197 da1s1 EBR (31M)
0 64197 - free - (31M)

=> 0 7513317 da1s2 BSD (3.6G)
0 252 - free - (126k)
252 6451200 1 freebsd-ufs (3.1G)
6451452 1048576 2 freebsd-swap (512M)
7500028 13289 - free - (6.5M)

=> 0 64197 msdosfs/BOOT EBR (31M)
0 64197 - free - (31M)

╰─$ sudo gpart resize -i 2 da1
da1s2 resized
╰─$ gpart show da1

=> 63 31047617 da1 MBR (14G)
63 64197 1 !12 [active] (31M)
64260 30983400 2 freebsd (14G)
31047660 20 - free - (10k)

=> 0 64197 da1s1 EBR (31M)
0 64197 - free - (31M)

=> 0 7513317 da1s2 BSD (14G)
0 252 - free - (126k)
252 6451200 1 freebsd-ufs (3.1G)
6451452 1048576 2 freebsd-swap (512M)
7500028 13289 - free - (6.5M)

=> 0 64197 msdosfs/BOOT EBR (31M)
0 64197 - free - (31M)
╰─$ sudo gpart delete -i 2 da1s2
da1s2b deleted

╰─$ gpart show

=> 63 31047617 da1 MBR (14G)
63 64197 1 !12 [active] (31M)
64260 30983400 2 freebsd (14G)
31047660 20 - free - (10k)

=> 0 64197 da1s1 EBR (31M)
0 64197 - free - (31M)

=> 0 7513317 da1s2 BSD (14G)
0 252 - free - (126k)
252 6451200 1 freebsd-ufs (3.1G)
6451452 1061865 - free - (518M)

=> 0 64197 msdosfs/BOOT EBR (31M)
0 64197 - free - (31M)
╰─$ sudo growfs /dev/da1s2
growfs: superblock not recognized
╰─$ sudo gpart delete -i 1 da1s2
da1s2a deleted

╰─$ sudo gpart add -b 252 -s 25804800 -t freebsd-ufs da1s2
da1s2a added
╰─$ gpart show

=> 63 31047617 da1 MBR (14G)
63 64197 1 !12 [active] (31M)
64260 30983400 2 freebsd (14G)
31047660 20 - free - (10k)

=> 0 64197 da1s1 EBR (31M)
0 64197 - free - (31M)

=> 0 64197 msdosfs/BOOT EBR (31M)
0 64197 - free - (31M)

=> 0 30983400 da1s2 BSD (14G)
0 252 - free - (126k)
252 25804800 1 freebsd-ufs (12G)
25805052 5178348 - free - (2.5G)
╰─$ sudo gpart delete -i 1 da1s2
da1s2a deleted
╰─$ sudo gpart add -b 252 -s 29675520 -t freebsd-ufs da1s2
da1s2a added
╰─$ gpart show da1s2

=> 0 30983400 da1s2 BSD (14G)
0 252 - free - (126k)
252 29675520 1 freebsd-ufs (14G)
29675772 1307628 - free - (638M)
╰─$ sudo gpart add -s 1048576 -t freebsd-swap da1s2
da1s2b added
╰─$ gpart show da1s2

=> 0 30983400 da1s2 BSD (14G)
0 252 - free - (126k)
252 29675520 1 freebsd-ufs (14G)
29675772 1048576 2 freebsd-swap (512M)
30724348 259052 - free - (126M)

Oh, and once the Pi has booted:

# growfs /dev/mmcsd0s2a

7 thoughts on “Resizing FreeBSD partitions on an SD card for Raspberry Pi Using gpart and growfs

  1. Reply Paul Feb 3,2013 11:27 am

    Hi
    Thank you very much for posting this.
    I had tried for quite some time to enlarge the size of the FreeBSD RPi slice (on a 8GB SDCard) until I found your post.
    However, although I tried a number of times, FreeBSD never booted from the enlarged slice even though I had no problem booting before applying the gpart resizing.

    The only way I could get it to boot was by dumping the slice to a usb key then resizing it as you outline.
    Afterwards, I restored the dump to the enlarged slice and this booted without any problems.

    Additionally, I didn’t need to use growfs after the RPi had booted.

    Thanks again
    Paul

    • Reply dave Feb 3,2013 10:49 pm

      Thanks for your feedback, Paul. Not sure why you had trouble booting, but this is a little new to me too, so I can’t offer any advice on that one. To be clear, I did not move slices to a USB key, but I plugged by SD card into a USB card-reader. This is because you cannot manipulate slices like that when they are mounted. It’s good to know that the dump/restore method works as well.

  2. Reply Pavel Feb 6,2013 11:22 pm

    It’s great… My first attempt with 16G SD card failed (just like Paul’s comment above, unable to boot), maybe because I “copied” all your steps without doing little bit of the math (the sectors numbers may differ). Second try with 8GB card was successful. Although I did not leave enough space for swap and I must go few steps back and re-do what I did, it works and it boots. I can read manual thousand times but I don’t understand until I see real example. Thank you for sharing this with us.

  3. Reply Bethany Feb 13,2013 4:38 am

    This was a very helpful guide. I also have a 16GB SDHC card for which I wanted to use the whole space, but I ran into a similar issue as the previous commenters with it not booting after following these steps. I ended up finding a fix to my problem, which involved our partition offsets being a bit different. When intially setting up my RasPi, I used the disk image provided here and dd’ed it straight to the SD card, so bear that in mind.

    It seems the key is to pay attention to the output of the first ‘gpart show’. If, as in your example, it shows 126k of free space before the freebsd-ufs partition on da1s2 (or whatever the slice is), then your instructions should work. However, my da1s2 didn’t have any free space before freebsd-ufs, so the ‘-b 252’ offsets in later commands obviously (in hindsight) wouldn’t work. To fix this, I replaced all instances of ‘-b 252’ in your procedure with ‘-b 0’. Once I started over with the steps and made those replacements, it booted quite happily.

    • Reply dave Feb 18,2013 5:54 pm

      Thanks for the feedback, Bethany. I have updated the article to warn readers that they must use my post as an example only. Good work on setting your correct offset.

Leave a Reply