[howto] nanobsd custom compact flash image size

  • Here is how I managed to install pfSense using a larger Compact Flash card. You can use any size CF and use its all sectors.
    I'm quite new to pfSense and freeBSD so this might not be the best procedure but it worked for me and I wanted to share it.

    PfSense version: nanobsd vga 2.0.2
    Target Box:  alix 3d3
    support pc: freebsd 9.1

    Get CF sector size:

    freebsd# dmesg | grep -e '^da0:' | grep sectors
    da0: 7647MB (15662304 512 byte sectors: 255H 63S/T 974C)

    Calc slices size (see footer example script)

    start         size         slice
    63 7779681 da0s1
    7779744 63
    7779807 7779681 da0s2
    15559488 102816 da0s3

    make mount dirs

    freebsd# mkdir /mnt/nanobsd
    freebsd# mkdir /mnt/nanobsd-conf
    freebsd# mkdir /mnt/cf-s1a
    freebsd# mkdir /mnt/cf-s3

    Get and mount pfSense image (here the source is a 512M image)

    freebsd# wget http://files.nl.pfsense.org/mirror/downloads/pfSense-2.0.2-RELEASE-512mb-i386-nanobsd[_vga].img.gz
    freebsd# gunzip pfSense-2.0.2-RELEASE-512mb-i386-nanobsd.img.gz
    freebsd# mdconfig -a -t vnode -f pfSense-2.0.2-RELEASE-512mb-i386-nanobsd[_vga].img -u 1
    freebsd# mount /dev/md1s1a /mnt/nanobsd
    freebsd# mount /dev/md1s3 /mnt/nanobsd-conf

    Create CF slices

    freebsd# gpart add -b 63 -s 7779681  -t freebsd da0
    da0s1 added
    freebsd# gpart add -b 7779807 -s 7779681  -t freebsd da0
    da0s2 added
    freebsd# gpart add -b 15559488 -s 102816 -t freebsd da0
    da0s3 added
    freebsd# gpart set -a active -i 1 da0
    active set on da0s1

    freebsd# bsdlabel -w -B -b /mnt/nanobsd/boot/boot /dev/da0s1
    freebsd# bsdlabel -w -B -b /mnt/nanobsd/boot/boot /dev/da0s2

    freebsd# newfs -E -L pfsense0 /dev/da0s1a
    freebsd# newfs -E -L pfsense1 /dev/da0s2a
    freebsd# newfs -E -L cf /dev/da0s3

    Copy data from image to CF

    freebsd# mount /dev/da0s1a /mnt/cf-s1a
    freebsd# mount /dev/da0s3 /mnt/cf-s3
    freebsd# cp -a /mnt/nanobsd/* /mnt/cf-s1a/
    freebsd# cp -a /mnt/nanobsd-conf/* /mnt/cf-s3/

    note: put what you want in /mnt/cf-s1a/etc/nanosize.txt (now it's 512mb image source -> 8gb)

    freebsd# boot0cfg -B -b /mnt/cf-s1a/boot/boot0[sio] -m3 -s1 da0
    note: "sio" for serial console output

    Umount and clean

    freebsd# umount /mnt/cf-s* /mnt/nanobsd*
    freebsd# rm -rf /mnt/cf-s* /mnt/nanobsd*
    freebsd# mdconfig -d -u 1

    Remove the CF and put it in your box.

    – To calculate slices size using all CF available sectors --

    set geom="da0"
    set start=63
    set confSize="102816"
    if ($#argv == 1) then
    	set geom=$1
    set sectors=`diskinfo $geom | awk '{print $4}'`
    if ($sectors <= 0 ) then
    	exit 1
    set sliceSize=`expr \( $sectors - $confSize - 126 \) / 2`
    set slice2=`expr $sliceSize + 126`
    set slice3=`expr $slice2 + $sliceSize`
    echo "start - size - slice"
    printf "$start - $sliceSize - $geom\s1a\n"
    printf "$slice2 - $sliceSize - $geom\s2a\n"
    printf "$slice3 - $confSize - $geom\s3\n"

  • Rebel Alliance Developer Netgate

    Looks ok though you probably want to use something more like cpio, rsync, or dump/restore to duplicate because a cp alone may miss (or mishandle) some special files or file settings.

  • ok, thanks!
    I tried to duplicate with tar and it worked fine as well. Is this a more proper way?

    cd /mnt/nanobsd
    tar cf - * | ( cd /mnt/cf-s1a ; tar xf - )

  • Rebel Alliance Developer Netgate

    tar may work ok so long as it's set to perserve permissions (-p)

  • If you set up your slices properly, upgrades should still work; however, you will need to create appropriately sized upgrade images or when you upgrade the file system will not fill the whole slice (which is typical when using an upgrade image smaller than intended for your base image size).

  • It's been asked other places, but I never really saw an answer.  What's the benefit of having more available space on a Compact Flash card?  As long as your packages fit, it's not like you should be using the space for any dynamic data (since you'd wear out the flash cells.)

  • Rebel Alliance Developer Netgate

    There really isn't any benefit, aside from fitting more user/package data.

    If your card does wear leveling it's actually better to use a small image size and leave more cells free to disappear as they wear out.

Log in to reply