Skip to content

1. Setup Development Environment for pfSense FreeBSD port

Ricky Zhang edited this page Dec 18, 2020 · 7 revisions

Download FreeBSD VM image

See link

Add an extra disk as home mount

gpart create -s GPT ada1
gpart add -t freebsd-ufs -a 1M ada1
newfs -U /dev/ada1p1
mkdir /home
add the following to /etc/fstab: 

/dev/ada1p1	/home	ufs	rw	2	2

mount /home

Resize rootfs

Resize vmdk image

VBoxManage clonemedium "FreeBSD-11.2-rootfs-amd64.vmdk" "FreeBSD-11.2-rootfs-amd64-cloned.vdi" --format vdi

VBoxManage modifymedium "FreeBSD-11.2-rootfs-amd64-cloned.vdi" --resize 102400

VBoxManage clonemedium "FreeBSD-11.2-rootfs-amd64-cloned.vdi" "FreeBSD-11.2-rootfs-amd64-resized.vmdk" --format vmdk

Check/Recover/Resize the rootfs

Ricky@freebsd ~ $ gpart show ada0
=>       3  65013755  ada0  GPT  (100G) [CORRUPT]
         3       130     1  freebsd-boot  (65K)
       133   2097152     2  freebsd-swap  (1.0G)
   2097285  62914560     3  freebsd-ufs  (30G)
  65011845      1913        - free -  (957K)

Ricky@freebsd ~ $ sudo gpart recover ada0
ada0 recovered

Ricky@freebsd ~ $ gpart show ada0
=>        3  209715189  ada0  GPT  (100G)
          3        130     1  freebsd-boot  (65K)
        133    2097152     2  freebsd-swap  (1.0G)
    2097285   62914560     3  freebsd-ufs  (30G)
   65011845  144703347        - free -  (69G)

Ricky@freebsd ~ $ sudo gpart resize -i 3 -s 98G -a 1M ada0
ada0p3 resized
Ricky@freebsd ~ $ gpart show ada0
=>        3  209715189  ada0  GPT  (100G)
          3        130     1  freebsd-boot  (65K)
        133    2097152     2  freebsd-swap  (1.0G)
    2097285  205520763     3  freebsd-ufs  (98G)
  207618048    2097144        - free -  (1.0G)

Ricky@freebsd ~ $ sudo growfs /dev/gpt/rootfs

Ricky@freebsd ~ $ df -h
Filesystem         Size    Used   Avail Capacity  Mounted on
/dev/gpt/rootfs     95G     18G     70G    20%    /
devfs              1.0K    1.0K      0B   100%    /dev
/dev/ada1p1         97G     18G     71G    20%    /home

Resize the disk -i partition index -s desirable size -a align

Run ‘adduser’ to add Ricky account.

Remember to add it to wheel group

Enable sshd

Add line in /etc/rc.conf: sshd_enable="YES"

Run: service sshd start

Add ssh key

ssh-keygen -t rsa

Copy ssh key from gtx host:

[Ricky@gtx .ssh]$ scp authorized_keys bsd:.ssh
Password for Ricky@freebsd:
authorized_keys                                                                                                                                                                                      100%   15KB  15.8MB/s   00:00    
[Ricky@gtx .ssh]$ scp config bsd:.ssh
config

Change user login shell

chsh -s /usr/local/bin/bash

Install pkg

If pfSense uses outdated FreeBSD, change the URL /etc/pkg/FreeBSD.conf to match the FreeBSD version.

Install sudo pkg

pkg install sudo

Modify /usr/local/etc/sudoers

## Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL

Install other useful pkg

[Ricky@freebsd ~/script]$ cat install-stuffs.sh 
pkg install -y bash
pkg install -y vim-console
pkg install -y git
pkg install -y poudriere-devel
pkg install -y mkfile
pkg install -y rsync
pkg install -y nginx
pkg install -y unbound
pkg install -y screen
pkg install -y the_silver_searcher
pkg install -y htop
pkg install -y tmux
pkg install -y qemu-user-static
pkg install -y subversion
pkg install -y bash-completion
pkg install -y gnupg
pkg install -y coreutils

# For Packet Sorter
pkg install -y libpcap
pkg install -y gmake
pkg install -y gsed
pkg install -y pkgconf
pkg install -y cmake
pkg install -y pkgconf

Build port from FreeBSD official release (NOT pfsense)

Get FreeBSD port from FreeBSD upstream repository

sudo portsnap auto

Build Barnyard2 from FreeBSD official port

cd /usr/ports/security/barnyard2
make

Build Barnyard2 from pfsense port

cd /home/Ricky/repo/github/pfsense/FreeBSD-ports/security/barnyard2
make

This will build Barnyard2 and its dependencies. But you need to answer so many option settings dialog.