10 Jan 2016, 11:32

Freebsd on Raspberry Pi 2 and Golang

FreeBSD is now fully supported on the Raspberry Pi2, makes it a fun small computer to experiment with BSD.

If you have a Raspberry Pi 1, you can simply install 10.2-RELEASE image.

For Raspberry Pi 2, you need 11.0-CURRENT which is the development branch, images can be found here.

dd the image as usual to a SD card, it will be auto resized at first boot. (See growfs_enable="YES") in rc.conf.

CPU frequency

To enable on demand cpu overclocking (ranging from 600 to 1000MHz), enable powerd by adding this to rc.conf.

powerd_enable="YES"
powerd_flags="-a hadp"

Production speed

FreeBSD CURRENT is the development version, some debugging tools may slow down your system.

As stated in UPDATING if you are running CURRENT:

ln -s 'abort:false,junk:false' /etc/malloc.conf

Wifi

Depending on your wifi dongle this may be different, for RealTek devices add an entry to /etc/wpa_supplicant.conf:

network={
    ssid="myssid"
    psk="mypass"
}

And this to /etc/rc.conf:

wlans_urtwn0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP"

And this to /boot/loader.conf

legal.realtek.license_ack=1

And type service netif restart.

Installing the ports

The ports are a long list of third parties software you can install on your system, first synchronize the ports tree:

portsnap fetch
portsnap extract

It’s highly recommend you install portmaster to keep your ports updated:

cd /usr/ports/ports-mgmt/portmaster/
make install clean

To later update your ports tree and ports:

portsnap fetch update
portmaster -a

To compile and install a port simply go to its directory and run make install clean.

Keeping the sources updated (optional)

All the FreeBSD sources are available and can be used to recompile the whole system.

Subversion needs some space in /tmp to complete this task, edit /etc/fstab to grow tmpfs to at least 70M the reboot:

tmpfs /tmp tmpfs rw,mode=1777,size=70m 0 0
cd /usr/ports/security/ca_root_nss
make install clean
svnlite checkout https://svn.FreeBSD.org/base/head /usr/src

To keep it in sync later, just type:

cd /usr/src
svnlite update

Keeping your FreeBSD updated can be achieved by recompiling the system aka make world, note that this could take a long time on a Raspberry Pi but still doable (remember to use make -j 4 on RPi2).

Installing Go (optional)

If you are into Go and need a recent version, first you need to compile Go 1.4 as a bootstraper (note that you also need to install git):

cd /usr/ports/lang/go14
make install clean

Then you can compile a more recent Go, for example using /usr/local/go:

cd /usr/local
git clone https://go.googlesource.com/go
cd go/src
env TMPDIR=/var/tmp GOARM=7 GOROOT_BOOTSTRAP=/usr/local/go14 ./all.bash

Add /usr/local/go/bin to your PATH.

28 Nov 2014, 20:29

FreeBSD on Google Compute Engine

First you need to create a VirtualBox FreeBSD install using a 10G qcow format, use an SCSI controller for the install as the disk will be visible as da0 inside GCE.

On FreeBSD 10.1 I had to load virtio manually, so set this in /boot/loader.conf

`virtio_load="YES"
virtio_pci_load="YES"
virtio_blk_load="YES"
if_vtnet_load="YES"`

Copy your ssh key in your home user .ssh/authorized_keys, be sure to be in the wheel group.

On a Mac you need to install GNU tar (brew install gnu-tar), shutdown your VirtualBox vm and upload your image to GCE

`VBoxManage clonehd -format RAW ../VirtualBox\ VMs/FreeBSDGCE/BSDGCE.qcow
~/Downloads/disk.raw
gtar -Szcf freebsd.tar.gz disk.raw
gsutil mb gs://bsdimage
gsutil cp freebsd.tar.gz gs://bsdimage/gce-bsd.tar.gz
gcutil addimage freebsd  gs://bsdimage/gce-bsd.tar.gz`

You should now see “freebsd” as available install image in your console

19 Feb 2014, 05:05

FreeBSD 10 on Dedibox SC gen 2 or any remote server with a rescue shell

FreeBSD 10 is out and it’s time to replace your Linux boxes cheeky

SC gen 2 is a VIA U2250 with 2Gb memory.

Start the rescue shell in amd64 12.04 Ubuntu, connect to the box via SSH with the temporary password

sudo -s
cd /tmp
wget http://ftp1.fr.freebsd.org/pub/FreeBSD/snapshots/ISO-
IMAGES/10.0/FreeBSD-10.0-STABLE-amd64-20140216-r261948-disc1.iso
apt-get update
apt-get install qemu-kvm

sudo qemu-system-x86_64 -no-kvm -hda /dev/sda -cdrom ./FreeBSD-10.0-STABLE-
amd64-20140216-r261948-disc1.iso -net nic,model=e1000 -vnc :1,yourpassword
-boot d

This install qemu and run the FreeBSD installer from the downloaded CD.

Run a VNC client on your computer and connect to your dedibox ip, you should watch FreeBSD boot from the CDROM.

Complete a normal installation, at the end it will ask if you want to run a shell **answer is YES **and then type this to reinstall the bootloader.

If you are using UFS (default)

fdisk -B -b /boot/boot0 /dev/ada0

If you are using ZFS:

gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

Type exit and reboot to the normal mode.

Happy FreeBSD !

Further notes:

  • If you are not using ZFS, you can enable softupdate and TRIM as the SC gen 2 contains an hybrid SSD, you should theoretically have better performance
  • The last fdisk command is not the normal process but it was the only way I get it boot
  • Do not use qemu with KVM as there is a bug with this particular cpu, so yes the installation will be dead slow
  • The DHCP won’t answer it’s ok

30 Jan 2014, 17:37

FreeBSD on RaspBerry Pi

FreeBSD images for arm are now built from the FreeBSD Foundation ! So it’s an easy process to get it on your Pi.

Download your image from the ftp repository

Insert a 4Gb or more SD card in your PC and copy the FreeBSD image into it, here are the commands for a Mac:

sudo diskutil list​
sudo diskutil unmountDisk /dev/disk1​
sudo dd if=/Users/akh/Downloads/FreeBSD-10.0-STABLE-arm-
armv6-RPI-B-20140127-r261200.img  of=/dev/rdisk1 bs=1m​
sudo diskutil eject /dev/disk1​

Boot your pi with the card and welcome to FreeBSD !

If you are using the wifi dongle from Adafruit this may help:

echo legal.realtek.license_ack=1 >> /boot/loader.conf
echo wlans_urtwn0="wlan0" >> /etc/rc.conf
echo ifconfig_wlan0="wpa DHCP" >> /etc/rc.conf`

And set your wifi password with wpa_passphrase

wpa_passphrase yourssid yourwifipassword >> /etc/wpa_supplicant.conf

28 Feb 2012, 15:32

FreeBSD vimage jails

I tried to use VIMAGE for jails, can be summarized as: independant network stack, firewalling, nat, a real loopback … for your jails

First I had pf in my kernel, it does not work with VIMAGE, it will kernel panic, (as module too), so remove it (I hope it will be solved soon).

I used the package from DruidBSD: vimage boot, and used the following config:

vimage_enable="YES"     
vimage_list="testjail"
vimage_testjail_rootdir="/usr/jails/testjail"           # root directory
vimage_testjail_hostname="testjail"      # hostname
vimage_testjail_devfs_enable="YES"                      # mount devfs
vimage_testjail_vnets="vtnet1"                         # network interfaces

vtnet1 is a dedicated hard interface (from KVM) and will appears only in the jail after you start /etc/rc.d/vimage start

Nice but I need a bridge there so I needed netgraph modules, but I encounter this issue: link_elf_obj: symbol ifnet undefined, for unknown reason VIMAGE will break ng_ether if used as module, add it to your kernel then rebuild:

# Virtual networking for jail
options         VIMAGE
device          epair
device          if_bridge

option          NETGRAPH
option          NETGRAPH_ETHER

No you can use vimage_testjail_bridges=“vtnet0” instead of vimage_testjail_vnets, it will automagically create a bridge visible in you jail named ng0_testjail.

Happy jailing !

07 Feb 2012, 15:05

FreeBSD 9.0 ZFS root on OVH

I had so much pain to make it work so here is how to have a ZFS root with a raidz pool on 5 disks, specially with OVH without any console or kvm to debug the boot process.

The server has 5 disks that I put in raidz and boot on it, but this should apply to most installation.

gpart destroy -F ada0
gpart destroy -F ada1
gpart destroy -F ada2
gpart destroy -F ada3
gpart destroy -F ada4

gpart create -s gpt ada0
gpart create -s gpt ada1
gpart create -s gpt ada2
gpart create -s gpt ada3
gpart create -s gpt ada4

gpart add -b 34 -s 64k -t freebsd-boot ada0
gpart add -b 34 -s 64k -t freebsd-boot ada1
gpart add -b 34 -s 64k -t freebsd-boot ada2
gpart add -b 34 -s 64k -t freebsd-boot ada3
gpart add -b 34 -s 64k -t freebsd-boot ada4

# if you are very low on ram use a real partition for swap otherwise don't  
gpart add -s 4G -t freebsd-swap -l swap0 ada0 
gpart add -s 4G -t freebsd-swap -l swap1 ada1 
gpart add -s 4G -t freebsd-swap -l swap2 ada2 
gpart add -s 4G -t freebsd-swap -l swap3 ada3 
gpart add -s 4G -t freebsd-swap -l swap4 ada4  

gpart add -t freebsd-zfs -l disk0 ada0 
gpart add -t freebsd-zfs -l disk1 ada1 
gpart add -t freebsd-zfs -l disk2 ada2 
gpart add -t freebsd-zfs -l disk3 ada3 
gpart add -t freebsd-zfs -l disk4 ada4  

gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0 
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1 
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada2 
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada3 
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada4  

zpool create -o cachefile=/boot/zfs/zpool.cache -m none -f rpool raidz /dev/gpt/disk0 /dev/gpt/disk1 /dev/gpt/disk2 /dev/gpt/disk3 /dev/gpt/disk4 
#cannot mount '/rpool': failed to create mountpoint  
zfs set checksum=fletcher4 rpool 
zfs create rpool/root 
mkdir /tmp/mntzfs 
zfs set mountpoint=/tmp/mntzfs rpool/root  
zfs create -o canmount=off  rpool/root/usr 
zfs create  -o canmount=off rpool/root/var 
zfs create -o compression=on -o exec=on -o setuid=off rpool/root/tmp 
zfs create -o compression=gzip -o setuid=off  rpool/root/usr/ports 
zfs create -o compression=off -o exec=off -o setuid=off rpool/root/usr/ports/distfiles 
zfs create -o compression=off -o exec=off -o setuid=off rpool/root/usr/ports/packages 
zfs create -o compression=gzip -o exec=off -o setuid=off  rpool/root/usr/src 
zfs create -o compression=lzjb rpool/root/usr/obj zfs create -o compression=lzjb  -o exec=off     -o setuid=off   rpool/root/var/crash 
zfs create -o compression=off -o exec=off -o setuid=off   rpool/root/var/empty 
zfs create -o compression=lzjb  -o exec=on -o setuid=off   rpool/root/var/tmp  
zpool export rpool 
zpool import -o cachefile=/tmp/zpool.cache rpool chmod 1777 /tmp/mntzfs/tmp chmod 1777 /tmp/mntzfs/var/tmp  
sh cd /tmp/mntzfs 
mkdir fileinstall 
cd fileinstall 
fetch http://ftp1.fr.FreeBSD.org/pub/FreeBSD/releases/amd64/9.0-RELEASE/base.txz 
fetch http://ftp1.fr.FreeBSD.org/pub/FreeBSD/releases/amd64/9.0-RELEASE/kernel.txz 
fetch http://ftp1.fr.FreeBSD.org/pub/FreeBSD/releases/amd64/9.0-RELEASE/src.txz 
fetch http://ftp1.fr.FreeBSD.org/pub/FreeBSD/releases/amd64/9.0-RELEASE/doc.txz 
export DESTDIR=/tmp/mntzfs 
for file in base.txz kernel.txz doc.txz src.txz; 
do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); 
done

cp /tmp/zpool.cache /tmp/mntzfs/boot/zfs/zpool.cache 
echo 'zfs_enable="YES"' >> /tmp/mntzfs/etc/rc.conf 
echo 'zfs_load="YES"' >> /tmp/mntzfs/boot/loader.conf 
echo 'if_em_load="YES"' >> /tmp/mntzfs/boot/loader.conf 
echo 'vfs.root.mountfrom="zfs:rpool/root"' >> /tmp/mntzfs/boot/loader.conf  
echo 'sshd_enable="YES"' >> /tmp/mntzfs/etc/rc.conf 
echo 'ifconfig_em0="inet 188.165.XXX.XXX netmask 255.255.255.0 broadcast 188.165.XXX.255"' >> /tmp/mntzfs/etc/rc.conf 
echo 'defaultrouter="188.165.XXX.254"' >> /tmp/mntzfs/etc/rc.conf 
echo 'hostname="ksXXXX.kimsufi.com"' >> /tmp/mntzfs/etc/rc.conf  
chroot /tmp/mntzfs /bin/sh 
passwd root 
vi /etc/ssh/sshd_config 
# Change PermitRootLogin to yes for debug only exit  

zfs set mountpoint=legacy rpool/root
zfs set mountpoint=/tmp rpool/root/tmp 
zfs set mountpoint=/usr rpool/root/usr 
zfs set mountpoint=/var rpool/root/var 
zpool set bootfs=rpool/root rpool  

# not if you are low on RAM 
zfs create -V 8G rpool/swap 
zfs set checksum=off rpool/swap 
zfs set org.freebsd:swap=on rpool/swap  

zfs set readonly=on rpool/root/var/empty 
touch /tmp/mntzfs/etc/fstab 
# or add the swap if you use real partition 
cd /   
zfs umount -a

EDIT: as mentioned here do not put the swap in the zpool if you are low on ram or unstability will occur. http://lists.freebsd.org/pipermail/freebsd- current/2007-September/076831.html

14 Oct 2011, 13:57

FreeBSD 9.0 guest with virtio support in KVM

Performance are really bad for FreeBSD in KVM, one solution is to use paravirtualized driver, virIO.

At the time of writing FreeBSD 9.0 is beta 3 and the last commit in the virtio project is 225710

cd /usr/src/sys/dev
svn co http://svn.freebsd.org/base/projects/virtio/sys/dev/virtio
cd /usr/src/sys/modules
svn co http://svn.freebsd.org/base/projects/virtio/sys/modules/virtio
cd /usr/src/sys/modules/virtio

make install

add this to /boot/loader.conf

virtio_load="YES"
virtio_pci_load="YES"
virtio_blk_load="YES"
if_vtnet_load="YES"
virtio_balloon_load="YES"

# dmesg | grep -i  virtio
vtnet0:  on virtio_pci0
virtio_pci1:  port 0xc060-0xc07f irq 11 at device 4.0 on pci0
vtballoon0:  on virtio_pci1
virtio_pci2:  port 0xc080-0xc0bf mem 0xf2040000-0xf2040fff irq 10 at device 5.0 on pci0
vtblk0:  on virtio_pci2

It needs further tests, but seems to work except for the net driver which give me no links, (you can still use the previous net driver in KVM)

EDIT: the vtnet driver issue is solve and should be in the trunk

14 Oct 2011, 11:00

Install FreeBSD 9.0 with ZFS root

The “new” FreeBSD installer does not give you the options to simply install ZFS as root, so sad, here is how to do it.

Most installation recommand to install / in the zpool root, which is not always clean, for example a recursive snapshot will snapshot your swap …

#Boot cd and choose shell:


umount /dev/md1
mdmfs -s 1024M md1 /tmp

gpart destroy -F ada0

gpart create -s gpt ada0

gpart add -b 34 -s 64k -t freebsd-boot ada0
#gpart add -s 4G -t freebsd-swap -l swap0 ada0
gpart add -t freebsd-zfs -l disk0 ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

zpool destroy rpool
# use -f if you already have a zpool
zpool create -f rpool /dev/gpt/disk0

zfs set checksum=fletcher4 rpool
zfs create rpool/root
zfs set mountpoint=none rpool
zfs set mountpoint=/mnt rpool/root

zfs create -o canmount=off  rpool/root/usr
zfs create  -o canmount=off rpool/root/var
zfs create -o compression=on -o exec=on -o setuid=off rpool/root/tmp
zfs create -o compression=gzip -o setuid=off  rpool/root/usr/ports
zfs create -o compression=off -o exec=off -o setuid=off rpool/root/usr/ports/distfiles
zfs create -o compression=off -o exec=off -o setuid=off rpool/root/usr/ports/packages
zfs create -o compression=gzip -o exec=off -o setuid=off  rpool/root/usr/src
zfs create -o compression=lzjb rpool/root/usr/obj
zfs create -o compression=lzjb  -o exec=off     -o setuid=off   rpool/root/var/crash
zfs create -o compression=off -o exec=off -o setuid=off   rpool/root/var/empty
zfs create -o compression=lzjb  -o exec=on -o setuid=off   rpool/root/var/tmp

zpool export rpool
zpool import -o cachefile=/tmp/zpool.cache rpool
chmod 1777 /mnt/tmp
chmod 1777 /mnt/var/tmp

sh
cd /usr/freebsd-dist
export DESTDIR=/mnt
for file in base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz;
do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done

cp /tmp/zpool.cache /mnt/boot/zfs/zpool.cache
echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
echo 'vfs.root.mountfrom="zfs:rpool/root"' >> /mnt/boot/loader.conf

zfs set readonly=on rpool/root/var/empty
touch /mnt/etc/fstab
zfs umount -a

zfs set mountpoint=legacy rpool/root
zfs set mountpoint=/tmp rpool/root/tmp
zfs set mountpoint=/usr rpool/root/usr
zfs set mountpoint=/var rpool/root/var
zpool set bootfs=rpool/root rpool
zfs create -V 2G rpool/swap
zfs set checksum=off rpool/swap
zfs set org.freebsd:swap=on rpool/swap


#reboot

# if close to 4G of memory
#echo "vfs.zfs.prefetch_disable=0" >> /boot/loader.conf

#echo WRKDIRPREFIX=/usr/obj >> /etc/make.conf
#passwd root

This installation has been made on a Linux KVM, later blog post will follow how to enable Dtrace, virtio …

31 Mar 2011, 21:06

(Re)Discovering FreeBSD and ZFS

Since Sun’s killers euh Oracle shutdown OpenSolaris, FreeBSD is becoming more and more attracting with ZFS port, you should really give it a try (We are back baby).

Here is a fast installation of FreeBSD with a ZFS root.

Download http://mfsbsd.vx.sk/, a special iso image that will give you a ZFS on root FreeBSD with no pain.

Note that I’m using it over KVM on Gentoo: (kvm -hda /dev/vg0/freebsdvm_root -m 4096 -cdrom /opt/data/kvm/installer/mfsbsd-se-8.2-amd64.iso -net nic -net user -boot d), but you can test it with Virtualbox, vmware, real installation …

At prompt login as root with password **mfsroot.

mount_cd9660 /dev/acd- /cdrom_  
zfsinstall -d /dev/ad0 -t /cdrom/8.2-RELEASE-amd64.tar.xz  
chroot /mnt  
vi /etc/rc.conf

Add:

sshd_enable="YES_  
hostname="freebsdvm"  
ifconfig_re0="DHCP"  
zfs create -V 2G tank/swap  
zfs set org.freebsd:swap=on tank/swap  
zfs set checksum=off tank/swap  
reboot  

Restart your vm (kvm -hda /dev/vg0/freebsdvm_root -m 4096 -net nic -net user )

log in as root no password
set a password

zfs set atime=off tank   
zfs create tank/root/usrports _# this is not a typo 
zfs set compression=gzip tank/root/usrports  
zfs set mountpoint=/usr/ports tank/root/usrports  
zfs create tank/root/usrports/distfiles  
zfs compression=off tank/root/usrports/distfiles

Install the ports with the methods you want. (http://www.freebsd.org/doc/handbook/ports-using.html)

portsnap fetch  
portsnap extract  
      
cd /usr/ports/shell/bash  
make install clean  

Adduser Put your user in the wheel group (admin)_

cd /usr/ports/ports-mgmt/portupgrade 
make install clean  
      
cd /usr/ports/security/sudo  
make install clean
      
cd /usr/ports/ports-mgmt/portaudit  
make install clean  
      
cd /usr/ports/sysutils/lsof  
make install clean

# update your system  
      
freebsd-update fetch  
freebsd-update install  
   
portsnap fetch  
portsnap update  
      
portaudit -F  
      
portupgrade -ai