Difference between revisions of "FreeBSD Network Backup Thing from Scrap"

From Run Your Own
Jump to: navigation, search
(Some config)
(Prepare the USB hard-drive for backup)
Line 69: Line 69:
 
* Format the new partition
 
* Format the new partition
 
   newfs -U /dev/da1p1
 
   newfs -U /dev/da1p1
 +
* Edit /etc/fstab and add an entry for the disk's mount point:
 +
/dev/da1p1      /sendhelp      ufs    rw      2      2
 +
* Create and mount the mount point
 +
mkdir /sendhelp
 +
mount /sendhelp

Revision as of 13:24, 12 July 2018

This document shows how to setup a dedicated backup machine for LAN use, made from bit and pieces most people don't care about these days: a Raspberry Pi 1, a 32MB SD Card, and a 2GB USB key. For the software, we will use FreeBSD and BorgBackup.

Prepare the OS

Why waste a 8GB or 16GB fancy SD Card when you probably have some old SD and USB sticks lying around? Also reading performances on the RPi1 is much better on USB than with the crappy SD reader. Finally, FreeBSD on the RPi1 works great, and very light on resources which is a plus given the limitation of the RPi CPU and RAM.

What needs to be done in a nutshell is to have the mandatory MS-DOS /boot partition on the 32MB SD card and have the rest of the filesystem on the USB stick.

  • Get the FreeBSD RPi1 image (update to latest RPI-B image)
wget https://download.freebsd.org/ftp/releases/arm/armv6/ISO-IMAGES/11.2/FreeBSD-11.2-RELEASE-arm-armv6-RPI-B.img.xz
  • Plug USB stick and copy the FreeBSD image to it (adjust /dev/sdX)
xzcat FreeBSD-11.2-RELEASE-arm-armv6-RPI-B.img.xz | sudo dd bs=1M of=/dev/sdX status=progress
  • Plug the 32MB sdcard and create a W95 FAT32 partition with fdisk or something (Hex code b) then format it:
sudo mkfs.vfat /dev/sdY1
  • Mount both the USB key's first partition and the SD card partition and copy the boot content from the USB key to the SD card:
sudo mount /dev/sdX1 /media/usb-key
sudo mount /dev/sdY1 /media/sd-card
sudo cp /media/usb-key/* /media/sd-card/
umount /dev/sdX1
umount /dev/sdY1

Boot FreeBSD and basic system configuration

Booting and ssh'ing

  • Insert the SD card and USB key on the RPi1
  • Optionally: connect the composite out to something for easier troubleshooting
  • Power the RPi1, the booting process will automagically find the USB key and the FreeBSD system partition (that's super nice actually).
  • Optionally: if you can't figure out the IP of the RPi1, you can sweep your LAN with:
nmap -sP 192.168.1.0/24
  • ssh in the RPi1 (default user is freebsd:freebsd):
ssh freebsd@192.168.1.XXX

Basic system config

Note: The first time FreeBSD starts, it will expand the filesystem to the full available space of the USB key.

  • Change default password for freebsd user:
passwd
  • Become root with su (password is root)
  • Change default password for root user:
passwd
  • update the FreeBSD repos catalogue (will take some time to process):
pkg update
  • Install $YOUR_FAV_TEXT_EDITOR
pkg install vim-tiny
echo "set nocompatible" > /root/.vimrc
  • Enable NTP for setting up time at every startup (the RPi1 has no RTC to keep actual time), edit /etc/rc.conf and add the following:
ntpd_enable="YES"
ntpd_sync_on_start="YES"
  • While you're here, feel free to rename the RPi:
hostname="thevault"
  • Configure your time zone:
tzsetup
  • reboot to celebrate your escape from Groundhog Day
reboot

Prepare the USB hard-drive for backup

Note: I'm using a 4TB USB disk here, do whatever you want.

  • ssh back in the RPi1, and become root
ssh freebsd@192.168.1.XXX
su
  • Plug the USB drive
  • If all goes well, it will show up as da1 (da0 is the USB key)
dmesg | grep da1
  • Create a partition
gpart create -s GPT da1
gpart add -t freebsd-ufs -a 1M da1
gpart show da1
  • Format the new partition
 newfs -U /dev/da1p1
  • Edit /etc/fstab and add an entry for the disk's mount point:
/dev/da1p1      /sendhelp       ufs     rw      2       2
  • Create and mount the mount point
mkdir /sendhelp
mount /sendhelp