Howto: Resize Embedded Flash Image
Update: There is a script for FreeBSD available which does it automatically for you: FlashHowtoScript
If you wish to use a larger Compact Flash card than the default image is meant for (64MB), you'll need to resize the image. Instructions for doing so follow. The old method, though reported broken, is preserved below the new on this page.
First, download the appropriate image. At the time of this writing, it's
pfSense-Embedded-BETA4a.img.gz.
Next, you'll need to decide whether you want to resize the image before or after writing it to your Compact Flash card. I recommend writing it first, then resizing it, but both should work. If you go with resizing after writing, you'll obviously need to write the image to the CF card now. (If you prefer to resize before writing, uncompress the image, mount it using mdconfig (mdconfig -a -t vnode -f pfSense-Embedded-BETA4a.img), and use md0 (or whichever md it creates) instead of da0 in the steps below.)
Linux or
FreeBSD (or similar systems):
zcat pfSense-Embedded-BETA4a.img.gz | dd of=/dev/sdc bs=16k
(I did this on a linux system, /dev/sdc is the device created for my CF reader. If you're not sure which device to use, check the output of the 'dmesg' command for it. On my freebsd system, the device is /dev/da0. Change accordingly)
Windows:
Download
physdiskwrite from
http://m0n0.ch/wall/physdiskwrite.php∞ and use it do write the image like so (in a command/cmd window):
physdiskwrite.exe pfSense-Embedded-BETA4a.img.gz
The rest of the process requires a freebsd machine or livecd. Plug in your CF reader and card and check /var/log/messages or the 'dmesg' command for info about the device. The information you're looking for is the size (in sectors) of the CF card. For a 1GB CF card, the info looks something like this:
May 18 14:59:19 stfu kernel: da0 at umass-sim0 bus 0 target 0 lun 0
May 18 14:59:19 stfu kernel: da0: <notwork CF Card CF 1.6E> Removable Direct Access SCSI-0 device
May 18 14:59:19 stfu kernel: da0: 1.000MB/s transfers
May 18 14:59:19 stfu kernel: da0: 977MB (2002896 512 byte sectors: 64H 32S/T 977C)
Remember the number of sectors, 2002896 in this case.
In order to resize the image, the following steps need to be taken:
- Backup both pfSense partitions/filesystems
- Resize the freebsd slice with fdisk
- Correct the disk label with bsdlabel
- Recreate both pfSense filesystems with newfs and tunefs
- Restore the filesystem backups
1. Backup pfSense partitions
Mount the pfSense partitions from the CF card and back them up like so:
# mkdir /tmp/pfSense
# mount /dev/da0a /tmp/pfSense
# cd /tmp/pfSense
# tar jcf /tmp/pfSense-slash.tar.bz2 .
# cd ..
# umount /tmp/pfSense
# mount /dev/da0d /tmp/pfSense
# cd pfSense
# tar jcf /tmp/pfSense-conf.tar.bz2 .
# cd ..
# umount /tmp/pfSense
Now you have backups of the / and conf partitions in /tmp.
2. Resize the freebsd slice with fdisk
Run 'fdisk -u da0' to start the interactive slice editing process. Most of the options it prompts for can be left alone. The BIOS geometry and unused slices don't need to be changed, just the 4th partition. The default size shows as 50000 sectors, 24MB. Leave the sysid and start values alone but change the 'size' value to the number of sectors you saw in the 'dmesg' output earlier. In this case, 2002896. If fdisk wants to autocorrect values, I recommend NOT letting it do so. Save the entry and the partition table and go on to step 3.
3. Correct the disklabel with bsdlabel
Run 'bsdlabel -e da0' to edit the disklabel. By default, it looks like this:
# /dev/da0:
8 partitions:
# size offset fstype [fsize bsize bps/cpg]
a: 119974 0 4.2BSD 1024 8192 15000
c: 124086 0 unused 0 0 # "raw" part, don't edit
d: 4096 119974 4.2BSD 1024 8192 520
Change the 'size' of the 'c' partition to the number of sectors on your CF card, the 'size' of the 'a' partition to (sectors - 'd' size), and the 'offset' of the 'd' partition to the same value as the new size of 'a'. For the 1GB card, this means 'a' 'size' is 1998800 (2002896 - 4096), 'c' 'size' is 2002896, and 'd' 'offset' is 1998800. Exit the editor to save the disklabel.
4. Recreate and label pfSense filesystems with newfs and tunefs
In order to recreate the filesystems, simply run newfs like so:
# newfs da0a
# tunefs -L pfSense da0a
# newfs da0d
# tunefs -L pfSenseCfg da0d
5. Restore filesystem backups
Lastly, mount up your new filesystems and restore the backups from step 1:
# mount /dev/da0a /tmp/pfSense
# tar jxf /tmp/pfSense-slash.tar.bz2 -C /tmp/pfSense
# umount /dev/da0a
# mount /dev/da0d /tmp/pfSense
# tar jxf /tmp/pfSense-conf.tar.bz2 -C /tmp/pfSense
# umount /dev/da0d
If all went well, you should be able to swap the CF card back into your embedded hardware and fire it up.
Outdated (broken) flash resize method
If you have larger
CompactFlash disks and want to make full use of it, it is necessary to resize the pfsense image that can be downloaded.
NOTE! THIS HAS NOT BEED TESTED RECENTLY. IT HAS BEEN REPORTED AS BROKEN.
To resize an flash image with a default size of 128 Megabyte to a new image of 256 Mb you can use the following script (
FreeBSD, change the device names if needed):
# extract img and duplicate it to img.bak
cp $1 $1.bak
# original images are ~112Mb
# enlarge by 140mb to ~252Mb
dd if=/dev/zero bs=1k count=140000 >> $1
# mount old and new image as memory disk
mdconfig -a -t vnode -f $1.bak -u 0
mdconfig -a -t vnode -f $1 -u 1
# change partition(?) sizes
# assuming the sector size is 512 byte
# i had good luck adding ~210000 sectors
# (otherwise the image could get too big for your flash card)
# to "size" of "a" and "c"
# and to "offset" of "d"
disklabel -e md1 # grow a and c and move d to end
# grow filesystem
growfs md1a
newfs md1d
# copy old image to new image
dd if=/dev/md0d of=/dev/md1d
# umount/detach
mdconfig -d -u 1
# optionally copy image to cf card
#dd if=$1 of=/dev/da2 bs=16k # where da2 is my CF-card
Thanks to Max Laier & Scott Ullrich...
Prebuild Images
Bao C. Ha has prepared some images for common
CompactFlash disk sizes (128Mb, 256Mb, 512Mb, 1Gb):
http://shopping.hacom.net/catalog/pub/pfsense/∞
These images contains GRUB as the bootloader which is not part of the official pfSense release.
GRUB will hang on Soekris 4xxx hardware without serial console device attached.
You will have to customise grub config file (menu.lst) if you want an autonomous box when rebooted
For Wrap you should use the ad0 images. Unfortunately the wrap seems to boot from another device (mdo?) so these images do not work (yet).
HowTo: Write Flash Image
To write a flash image on Windows you can use
physdiskwrite∞ available from
m0n0wall∞.
HowTo: Read Flash Image
Sometimes it makes sense to create an backup image of a
CompactFlash Card.
For Windows you can use
RawDisk∞ to create an image of a CF Card.
Categories
CategoryHowTo
There are no comments on this page. [Add comment]