Tag Archives: usb

FreeBSD Desktop – Part 17 – Configuration – Automount Removable Media

In this article in the FreeBSD Desktop series I will introduce various methods to automatically (or not) mount external/removable devices such as USB or eSATA disks/pendrives or SD/microSD flash cards.

You may want to check other articles in the FreeBSD Desktop series on the FreeBSD Desktop – Global Page where you will find links to all episodes of the series along with table of contents for each episode’s contents.

One of the FreeBSD daemons is devd(8) – the device state change daemon that provides a way to have userland programs run when certain kernel events happen. Such events are when new block device appears/disappears from the /dev directory.

For this problem about 2013 I created a devd(8) based solution – the automount daemon. Its workflow is very simple. When new ada/da/mmcsd* device appears then it tries to detect the filesystems on these partitions/slices and mount them. It you remove such device (device disappears) then it forcefully unmounts it and cleans used mountpoint from the /media directory.

It is available on GitHub - https://github.com/vermaden/automount - and in the FreeBSD Ports as sysutils/automount port. You can also install it as pkg(8) package. Its 2018 and various other solutions appeared in the meantime. One is the included in the FreeBSD base system autofs(8)/automount(8)
subsystem.

The other one is dsbmd/dsbmc – a media mounting daemon/automounter for FreeBSD with optional graphical GTK+ frontend. There is also FreeBSD base system solution called autofs(8) which I was not able to make work.

Below I will try to compare all their features, strengths and weaknesses.

  • sysutils/automount
    + can customize mount options for each filesystem type
    + written in POSIX /bin/sh script – easy to modify
    + can open selected file manager when device is inserted
    + provides /var/log/automount.log log file
    + supports MTP devices (Android phones for example)
    + supports XFS and HFS
    - does not support BTRFS (can be added)
  • sysutils/dsbmd
    + can customize mount options for each filesystem type
    + supports MTP devices (Android phones for example)
    + provides graphical fronted in GTK+ toolkit
    + can open selected file manager when device is inserted
    + supports BTRFS/HFS/XFS
    + provides /var/log/dsbmd.log log file
    - sometimes hangs at 100% cpu usage
  • autofs(8)
    + supports MTP devices (Android phones for example)
    + is available in the base system
    - does not allow custom mount options per filesystem
    - does not provide log file
    - does not support BTRFS/HFS/XFS (can be added)
    - mount being done only after interaction with /media/* dir
    - removed device is not unmounted automatically

Up to this day I used mine sysutils/automount exclusively as removable devices automount solution. For Android phones I used simple-mtpfs command within xterm(1) terminal. I tried sysutils/dsbmd along with sysutils/dsbmc-cli and GTK+ graphical sysutils/dsbmd frontend and I really liked it but it sometimes fails me with 100% cpu usage and requires restarting. That does not happen withΒ sysutils/automount which just works so I will stick to it but I will provide an update later with results after longer period of testing the sysutils/dsbmd daemon.

sysutils/automount

First I will describe daemon that I used since 2013. The sysutils/automount solution. Its installation and setup is very easy, just add the automount package using pkg(8). Nothing more is needed as the pkg(8) will restart devd(8) after adding new configuration files.

# pkg install automount

One of the nice features of sysutils/automount is /var/log/automount.log log file which has all details about mounted filesystems.

% tail /var/log/automount.log
2018-10-08 12:18:45 /dev/da0s1: mount (fat)
2018-10-08 12:19:23 /dev/da0: detach
2018-10-08 12:19:23 /dev/da0: mount point '/media/da0' removed
2018-10-08 12:19:23 /dev/da0s1: detach
2018-10-08 12:19:23 /dev/da0s1: mount point '/media/da0s1' removed
2018-10-09 11:38:14 /dev/da0: random wait for '0.1' seconds before 'attach' action
2018-10-09 11:38:14 /dev/da0: attach
2018-10-09 11:38:14 /dev/da0: mount (exfat)
2018-10-09 11:44:02 /dev/da0: detach
2018-10-09 11:44:02 /dev/da0: mount point '/media/da0' removed

The sysutils/automount comes with /usr/local/etc/automount.conf configuration file which has these options on my box.

% cat /usr/local/etc/automount.conf
USERUMOUNT=YES
ATIME=NO
REMOVEDIRS=YES
FM="caja --browser --no-desktop"
USER=vermaden
ENCODING=pl_PL.UTF-8
CODEPAGE=cp852

Besides not supporting (yet) MTP devices it just works. It is also very simple solution and being written in POSIX /bin/sh script it is very easy to modify it to one’s needs.

sysutils/dsbmd

The second option is the sysutils/dsbmd solution. Check the links below for more detailed description of this automounting daemon.

To install the dsbmd/dsbmc/dsbmc-cli trio just use pkg(8).

# pkg install dsbmc-cli dsbmc dsbmd

To configure dsbmd/dsbmc/dsbmc-cli trio these steps are needed.

1. Add dsbmd_enable=YES to your /etc/rc.conf file.

2. Install additional filesystems support depending on your needs:

  • fusefs-exfat
  • fusefs-gphotofs
  • fusefs-ntfs
  • fusefs-simple-mtpfs (MTP)
  • fusefs-ext2
  • fusefs-hfsfuse
  • fusefs-lkl

3. Add these lines below to your ~/.xinitrc file (or ~/.xsession).

# DSB AUTOMOUNTER
  dsbmc-cli -a &
  dsbmc &

You will then see the dsbmc icon in the system tray area.

dsbmc-tray

By default dsbmd will mount storage devices as regular user but You need to make sure that vfs.usermount=1 is in your /etc/sysctl.conf file and applied.

After I put the FAT32 or exFAT USB device it was automatically mounted.

/dev/da0 on /media/da0 (msdosfs, local, nosuid, mounted by vermaden)

The configuration file is available at /usr/local/etc/dsbmd.conf location. The dsbmd also comes with /var/log/dsbmd.log log file.

% tail /var/log/dsbmd.log
dsbmd: Killing blocking process 85421 ... on Thu Oct 11 16:48:10 2018
dsbmd: Sending SIGTERM to 85421 ... on Thu Oct 11 16:48:10 2018
dsbmd: Command /usr/local/sbin/mount.exfat ${DSBMD_DEVICE} "${DSBMD_MNTPT}" executed by UID 1000 failed with code 15: No error: 0 on Thu Oct 11 16:48:11 2018
dsbmd: Device /dev/da0 mounted on /media/GKPGE by UID 1000 on Thu Oct 11 16:48:12 2018
dsbmd: Device /dev/da0 unmounted from /media/GKPGE by UID 1000 on Thu Oct 11 16:49:09 2018
dsbmd: Device /dev/da0 mounted on /media/GKPGE by UID 1000 on Thu Oct 11 16:49:15 2018
dsbmd: Device /dev/da0 unmounted from /media/GKPGE by UID 1000 on Thu Oct 11 16:49:16 2018
dsbmd: Client with UID 1000 disconnected on Thu Oct 11 16:52:53 2018
dsbmd: Client with UID 1000 connected on Thu Oct 11 16:52:55 2018
dsbmd: Device /dev/da0 mounted on /media/GKPGE by UID 1000 on Thu Oct 11 16:58:22 2018

The dsbmd can also be configured with many useful options like mount(8) options for each filesystem type separately.

% grep _opts /usr/local/etc/dsbmd.conf | sed 's|\#\ ||g' | awk '{print $1}' | sort -u
cd9660_opts
exfat_opts
ext_opts
ext4_opts
msdosfs_opts
ntfs_opts
ufs_opts

The main GTK+ dsbmc window looks as follows.

dsbmc-prefs.jpg

You can also disable automatic mounting and can mount devices by hand with dsbmc tool.

dsbmc-mount.png

… or unmount them.

dsbmc-unmount.png

It is also a solution used in the NomadBSD portable distribution.

It sometimes fails with 100% cpu usage or with error message as this one:

dsbmc-error

autofs(8)

Last one is the FreeBSD base system solution.

To enable it one should do these steps:

  1. Add autofs_load=YES to your /boot/loader.conf file.
  2. Add autofs_enable=YES to your /etc/rc.conf file.
  3. Uncomment the /media -media -nosuid line in /etc/auto_master file.
  4. In the /etc/devd.conf file you need to add (or uncomment) the following content.
    notify 100 {
      match "system" "GEOM";
      match "subsystem" "DEV";
      action "/usr/sbin/automount -c";
    };
    
  5. To have MTP support you will also have to install sysutils/fusefs-simple-mtpfs and add the /mtp -simple-mtpfs -allow_other line to the /etc/auto_master file. Along with fuse_load=YES in the /boot/loader.conf file.

After doing all these I restarted the autofs(8) daemons.

# grep -r autofs_enable /etc
/etc/rc.d/automountd:rcvar="autofs_enable"
/etc/rc.d/autounmountd:rcvar="autofs_enable"
/etc/rc.d/automount:rcvar="autofs_enable"
/etc/defaults/rc.conf:autofs_enable="NO" # Run autofs daemons.
# /etc/rc.d/automountd onestop
# /etc/rc.d/autounmountd onestop
# /etc/rc.d/automount onestop
# /etc/rc.d/automountd onestart
# /etc/rc.d/autounmountd onestart
# /etc/rc.d/automount onestart

Now after attaching the USB drive the /var/log/messages file shows following information.

# tail /var/log/messages
Nov 21 13:37:42 t420s kernel: ugen2.4:  at usbus2
Nov 21 13:37:42 t420s kernel: umass0 on uhub4
Nov 21 13:37:42 t420s kernel: umass0:  on usbus2
Nov 21 13:37:42 t420s kernel: umass0:  SCSI over Bulk-Only; quirks = 0x8100
Nov 21 13:37:42 t420s kernel: umass0:4:0: Attached to scbus4
Nov 21 13:37:42 t420s kernel: da0 at umass-sim0 bus 0 scbus4 target 0 lun 0
Nov 21 13:37:42 t420s kernel: da0: {USB DISK 3.0 PMAP} Removable Direct Access SPC-4 SCSI device
Nov 21 13:37:42 t420s kernel: da0: Serial Number EC0068F1F89A7D02
Nov 21 13:37:42 t420s kernel: da0: 40.000MB/s transfers
Nov 21 13:37:42 t420s kernel: da0: 14786MB (30283008 512 byte sectors)
Nov 21 13:37:42 t420s kernel: da0: quirks=0x3

When you now check the contents of the /media directory it will contain the da0 dir.

# ls -l /media
total 1
drwxr-xr-x  3 root  wheel  512 2018.11.21 13:37 da0/

The drive/directory is not mounted yet, but when you will try to access that da0 dir (for example display its contents with ls(1) or try to enter it with cd(1) command) then it will get automatically mounted).

# mount | grep media
map -media on /media (autofs)
# ls /media/da0
NLUUG/  OTHER/
# mount | grep media
map -media on /media (autofs)
/dev/da0 on /media/da0 (msdosfs, asynchronous, local, noatime, nosuid, automounted)

After I removed the USB drive the /media/da0 directory remained mounted.

# tail /var/log/messages
Nov 21 13:52:48 t420s kernel: ugen2.4:  at usbus2 (disconnected)
Nov 21 13:52:48 t420s kernel: umass0: at uhub4, port 2, addr 4 (disconnected)
Nov 21 13:52:48 t420s kernel: da0 at umass-sim0 bus 0 scbus4 target 0 lun 0
Nov 21 13:52:48 t420s kernel: da0: {USB DISK 3.0 PMAP}  s/n EC0068F1F89A7D02 detached
Nov 21 13:52:48 t420s kernel: (da0:umass-sim0:0:0:0): Periph destroyed
Nov 21 13:52:48 t420s kernel: umass0: detached
Nov 21 13:52:49 t420s kernel: uhub_reattach_port: giving up port reset - device vanished

The autofs(8) subsystem did not unmounted it automatically.

# mount | grep media
map -media on /media (autofs)
/dev/da0 on /media/da0 (msdosfs, asynchronous, local, noatime, nosuid, automounted)

Of course manual unmounting by hand works (umount /media/da0) but its not what you expect from automounting daemon. It is not very suitable for the desktop usage because of the need to manually ‘access’ the created /media/* directory each time to make it mount.

History

Historically was also sysutils/am-utils – the Berkeley Automounter and Suite of Utilities – and sysutils/automounter which provides scripts to dynamically configure amd(8) daemon.

UPDATE 1 – Make autofs(8) Work

I have reworked the autofs(8) section to make it work. Thanks to the author of the autofs(8) subsystem – trasz – for showing me the source of the problem. The needed entry in the /etc/devd.conf file was missing in the original post. Now it works as advertised, at least for mounting. I am still not able to make it unmount the directory automatically after USB drive removal.

UPDATE 2 – The sysutils/automount 1.5.9 Update

Recently I implemented MTP support (Android phones for example) into the sysutils/automount script. I also added HFS and XFS support. Various fixes and other speed improvements were done (like removal of unneeded __random_wait() function or DELAY time reduction from 1 to just 0.1 second).

The new version is not yet available in the FreeBSD Ports (or packages). Grab it directly from the GitHub page available here:

The ‘manual’ installation is not hard, first built these Ports (or add as packages):

  • sysutils/exfat-utils (for exFAT support)
  • sysutils/fusefs-exfat (for exFAT support)
  • sysutils/fusefs-ntfs (for NTFS read write support)
  • sysutils/fusefs-ext4fuse (for EXT4 support)
  • sysutils/fusefs-simple-mtpfs (for MTP support)
  • sysutils/fusefs-hfsfuse (for HFS support)
  • sysutils/fusefs-lkl (for XFS support)

Then download automount/automount.conf/automount_devd.conf files from GitHub page. Put them into appropriate places and make automount executable. Then restart the devd(8) daemon.

# fetch https://raw.githubusercontent.com/vermaden/automount/master/automount
# fetch https://raw.githubusercontent.com/vermaden/automount/master/automount.conf
# fetch https://raw.githubusercontent.com/vermaden/automount/master/automount_devd.conf
# cp automount.conf      /usr/local/etc/automount.conf
# cp automount_devd.conf /usr/local/etc/devd/automount_devd.conf
# cp automount           /usr/local/sbin/automount
# chmod +x               /usr/local/sbin/automount
# /etc/rc.d/devd restart

Now plugin Your USB thumb drive and have fun πŸ˜‰

Also forgot one thing, it also requires x11/zenity port or package for MTP.

UPDATE 3 – The sysutils/automount 1.6.1 Update

A new version 1.6.1 of sysutils/automount is available with the following fixes:

  • Fix MBR/msdosfs partition unmount issue.

As its not yet available in the FreeBSD Ports please use manual procedure.

Download and unpack the automount-1.6.1.tar.gz file.

Then copy its files to appropriate places as shown below.

# cp automount.conf      /usr/local/etc/automount.conf
# cp automount_devd.conf /usr/local/etc/devd/automount_devd.conf
# cp automount           /usr/local/sbin/automount
# chmod +x               /usr/local/sbin/automount
# /etc/rc.d/devd restart

Β 

EOF
Advertisements

Silent Fanless FreeBSD Server – DIY Backup

I already once wrote about this topic at the Silent Fanless FreeBSD Desktop/Server article. To my pleasant surprise BSD NOW Episode 253: Silence of the Fans featured my article for which I am very grateful. Today I would like to show another practical example of such setup and with more hands on approach along with real power usage measurements with power meter. I also got more power efficient ASRock N3150B-ITX motherboard with only 6W TDP which includes 4-core Celeron N3150 CPU and also nice small Supermicro SC101i Mini ITX case. Keep in mind that ASRock also made very similar N3150-ITX motherboard (no ‘B’ in model name) with different ports/connectors that may better suit your needs better.

Build

Here is how the Supermicro SC101i case looks like with ASRock N3150B-ITX motherboard installed.

silent-backup-case-external.jpg

silent-backup-case-back.jpg

One thing that surprised me very much was the hard disk cost. The internal Seagate 4TB ST4000LM024 2.5 SATA drive costs about $180-190 but the same disk sold as Maxtor M3 4TB 2.5 disk in external case with Maxtor brand (which is owned by Seagate anyway) and USB 3.0 port costs half of that – about $90-100. At least in Europe/Poland location.

I think you do already know where I am going with my thoughts. I will use an external Maxtor M3 4TB 2.5 drive and connect it via the USB 3.0 port in this setup. While SATA III provides theoretical throughput of 6Gbps the USB 3.0 provides 5Gbps theoretical throughput. The difference can be important for low latency high throughput SSD drives that approach 580MB/s speed but not for traditional rotational disks moving gently at 5400RPM.

The maximum performance I was able to squeeze from this Maxtor M3 4TB 2.5 USB 3.0 drive was 90MB/s write speed and 120MB/s read speed using pv(1) tool, and that was at the beginning of the disk. These speeds will drop to about 70MB/s and 90MB/s at the end of the disk respectively for write and read operations. We are not even approaching SATA I standard here which tops at 1.5Gbps. Thus it will not make a difference or not a significant one for sure for such storage.

At first I wanted to make a hole on the motherboard end steel plate (somewhere beside the back ports) with drill to get outside with USB cable from the case and attach it to one of the USB 3.0 ports at the back of the motherboard but fortunately I got better idea. This motherboard has connector for internal USB 3.0 (so called front panel USB on the case) so I bought Akyga AK-CA-57 front panel cable with USB 3.0 port and connected everything inside the case.

This is the Akyga AK-CA-57 USB 3.0 cable.

silent-backup-usb-akyga-cable-AK-CA-57.jpg

If I was going to install two USB 3.0 disks using this method I would use one of these cables instead:

The only problem can be more physical one – will it blend will it fit? Fortunately I was able to find a way to fit it in the case and there is even space for the second disk. As this will be my offsite backup replacement which is only 3rd stage/offsite backup I do not need to create redundant mirror/RAID1 protection but it’s definitely possible with two Maxtor M3 4TB 2.5 USB 3.0 drives.

The opened Supermicro SC101i case with ASRock N3150B-ITX motherboard inside and attached Pico PSU looks like that.

silent-backup-mobo-case.jpg

With attached Akyga AK-CA-57 USB 3.0 cable things get little narrow, but with proper cable lay you will still be able to fit another internal 2.5 SATA disk or external 2.5 USB 3.0 disk.

silent-backup-mobo-case-blue.jpg

I attached Akyga AK-CA-57 cable to this USB 3.0 connector on the motherboard.

silent-backup-mobo-case-usb.jpg

Case with Maxtor M3 4TB disk. The disk placement required little modifications.

silent-backup-mobo-case-blue-disk.jpg

I created custom disk holders using steel plates I got from window mosquito net set for my home but you should be able to get something similar in any hardware shop. I modified them a little with pliers.

silent-backup-handles

I also ‘silenced’ the disk vibrations with felt stickers.

silent-backup-silence.jpg

The silenced disk in the Supermicro SC101i case.

silent-backup-mobo-case-blue-disk-silence.jpg

Ancestor

Before this setup I used Raspberry Pi 2B with external Western Digital 2TB 2.5 USB 3.0 disk but the storage space requirements become larger so I needed to increase that. It was of course with GELI encryption and ZFS with enabled LZ4 compression on top. The four humble ARM32 cores and soldered 1GB of RAM was able to squeeze whooping 5MB/s read/write experience from this ZFS/GELI setup but that was not hurting me as I used rsync(1) for differential backups and the Internet connection to that box was limited to about 1.5MB/s. I would still use that setup but it just won’t boot with that larger Maxtor M3 4TB disk because it requires more power and I already used stronger 5V 3.1A charger then 5V 2.0A suggested by vendor. Even the safe_mode_gpio=4 and max_usb_current=1 options at /boot/msdos/config.txt did not help.

Cost

The complete setup price tops at $220 total. Here are the parts used.

PRICE  COMPONENT
  $59  CPU/Motherboard ASRock N3150B-ITX Mini-ITX
  $14  RAM Crucial 4GB DDR3L 1.35V
  $13  PSU 12V 7.5A 90W Pico (internal)
   $2  PSU 12V 2.5A 30W Leader Electronics (external)
  $29  Supermicro SC101i (used)
   $3  Akyga AK-CA-57 USB 3.0 Cable
   $3  SanDisk Fit 16GB USB 2.0 Drive (system)
  $95  Maxtor M3 4TB 2.5 USB 3.0 Drive (data)
 $220  TOTAL

PSU

In earlier Silent Fanless FreeBSD Desktop/Server article I used quite large 90W PSU from FSP Group. From the PSUs that I owned only ThinkPad W520/W530 bricks can compete in size with this beast. As this motherboard will use very little power (details lower) it will require a lot smaller PSU. As the FSP Group PSU has IEC C14 slot it also requires additional IEC C13 power cable which makes it even bigger solution. The new 12V 2.5A 30W is very compact and also costs fraction of the 90W FSP Group gojira.

New Leader Electronics PSU label.

silent-backup-psu-ext-label.jpg

Below you can see the comparison for yourself.

silent-backup-psu-compare

I also got cheaper and less powerful Pico PSU which now tops as 12V 7.5A 90W power.

silent-backup-psu-pico-12V-90W.jpg

Power Consumption

This is where it gets really interesting. I measured the power consumption with power meter.

silent-backup-power-meter.jpg

Idle

When this box is booted without any media attached it uses only 7.5W of power idling. While the system was idle with SanDisk 16GB USB 2.0 drive (on which FreeBSD was installed) it used about 8.0W of power. When booted with Maxtor M3 4TB disk inside and SanDisk 16GB USB 2.0 drive attached it run idle at about 8.5W of power.

Load

As I do not need full CPU speed I limited the CPU speed in powerd(8) options to 1.2Ghz. With this limit set the fully loaded system with all 4 cores busy at 100% and two dd(8) processes for read both boot SanDisk 16GB drive and Maxtor M3 4TB disk and with GELI enabled ZFS pool doing scrub operation in progress and additional two find(1) processes for both disks it would not pass the 13.9W barrier. Without CPU limitation (that means Intel Turbo Boost enabled) the system used 16.0W of power at most.

Summary of power usage for this box.

 POWER  TYPE  CONFIGURATION
 7.5 W  IDLE  System
 8.0 W  IDLE  System + SanDisk 16GB drive
 8.5 W  IDLE  System + SanDisk 16GB drive + Maxtor M3 4TB drive + CPU 1.2 Ghz limit
 8.5 W  IDLE  System + SanDisk 16GB drive + Maxtor M3 4TB drive
13.9 W  LOAD  System + SanDisk 16GB drive + Maxtor M3 4TB drive + CPU 1.2 Ghz limit
16.0 W  LOAD  System + SanDisk 16GB drive + Maxtor M3 4TB drive

For comparision the Raspberry Pi 2B with 16GB MicroSD card attached used only 1.5W but we all know how slow it is. When used with Western Digital 2TB 2.5 USB 3.0 drive it used about 2.2W at idle state.

Configuration for Low Power Consumption

Below are FreeBSD configuration files used in this box to lower the power consumption.

The /etc/sysctl.conf file.

# ANNOYING THINGS
  vfs.usermount=1
  kern.coredump=0
  hw.syscons.bell=0
  kern.vt.enable_bell=0

# LIMIT ZFS ARC EFFICIENTLY
  kern.maxvnodes=32768

# ALLOW UPGRADES IN JAILS
  security.jail.chflags_allowed=1

# ALLOW RAW SOCKETS IN JAILS
  security.jail.param.allow.raw_sockets=1
  security.jail.allow_raw_sockets=1

# RANDOM PID
  kern.randompid=12345

# PERFORMANCE/ALL SHARED MEMORY SEGMENTS WILL BE MAPPED TO UNPAGEABLE RAM 
  kern.ipc.shm_use_phys=1

# MEMORY OVERCOMMIT SEE tuning(7)
  vm.overcommit=2

# NETWORK/DO NOT SEND RST ON SEGMENTS TO CLOSED PORTS
  net.inet.tcp.blackhole=2

# NETWORK/DO NOT SEND PORT UNREACHABLES FOR REFUSED CONNECTS
  net.inet.udp.blackhole=1

# NETWORK/ENABLE SCTP BLACKHOLING blackhole(4) FOR MORE DETAILS
  net.inet.sctp.blackhole=1

# NETWORK/MAX SIZE OF AUTOMATIC RECEIVE BUFFER (2097152) [4x]
  net.inet.tcp.recvbuf_max=8388608

# NETWORK/MAX SIZE OF AUTOMATIC SEND BUFFER (2097152) [4x]
  net.inet.tcp.sendbuf_max=8388608

# NETWORK/MAXIMUM SOCKET BUFFER SIZE (5242880) [3.2x]
  kern.ipc.maxsockbuf=16777216

# NETWORK/MAXIMUM LISTEN SOCKET PENDING CONNECTION ACCEPT QUEUE SIZE (128) [8x]
  kern.ipc.soacceptqueue=1024

# NETWORK/DEFAULT tcp MAXIMUM SEGMENT SIZE (536) [2.7x]
  net.inet.tcp.mssdflt=1460

# NETWORK/MINIMUM TCP MAXIMUM SEGMENT SIZE (216) [6x]
  net.inet.tcp.minmss=1300

# NETWORK/LIMIT ON SYN/ACK RETRANSMISSIONS (3)
  net.inet.tcp.syncache.rexmtlimit=0

# NETWORK/USE TCP SYN COOKIES IF THE SYNCACHE OVERFLOWS (1)
  net.inet.tcp.syncookies=0

# NETWORK/ENABLE TCP SEGMENTATION OFFLOAD (1)
  net.inet.tcp.tso=0

# NETWORK/ENABLE IP OPTIONS PROCESSING ([LS]SRR, RR, TS) (1)
  net.inet.ip.process_options=0

# NETWORK/ASSIGN RANDOM ip_id VALUES (0)
  net.inet.ip.random_id=1

# NETWORK/ENABLE SENDING IP REDIRECTS (1)
  net.inet.ip.redirect=0

# NETWORK/IGNORE ICMP REDIRECTS (0)
  net.inet.icmp.drop_redirect=1

# NETWORK/ASSUME SO_KEEPALIVE ON ALL TCP CONNECTIONS (1)
  net.inet.tcp.always_keepalive=0

# NETWORK/DROP TCP PACKETS WITH SYN+FIN SET (0)
  net.inet.tcp.drop_synfin=1

# NETWORK/RECYCLE CLOSED FIN_WAIT_2 CONNECTIONS FASTER (0)
  net.inet.tcp.fast_finwait2_recycle=1

# NETWORK/CERTAIN ICMP UNREACHABLE MESSAGES MAY ABORT CONNECTIONS IN SYN_SENT (1)
  net.inet.tcp.icmp_may_rst=0

# NETWORK/MAXIMUM SEGMENT LIFETIME (30000) [0.27x]
  net.inet.tcp.msl=8192

# NETWORK/ENABLE PATH MTU DISCOVERY (1)
  net.inet.tcp.path_mtu_discovery=0

# NETWORK/EXPIRE TIME OF TCP HOSTCACHE ENTRIES (3600) [2x]
  net.inet.tcp.hostcache.expire=7200

# NETWORK/TIME BEFORE DELAYED ACK IS SENT (100) [0.2x]
  net.inet.tcp.delacktime=20

The /boot/loader.conf file.

# BOOT OPTIONS
  autoboot_delay=1
  boot_mute=YES

# MODULES FOR BOOT
  zfs_load=YES

# DISABLE HYPER THREADING
  machdep.hyperthreading_allowed=0

# REDUCE NUMBER OF SOUND GENERATED INTERRUPTS
  hw.snd.latency=7

# RACCT/RCTL RESOURCE LIMITS
  kern.racct.enable=1

# PIPE KVA LIMIT | 320 MB
  kern.ipc.maxpipekva=335544320

# NUMBER OF SEGMENTS PER PROCESS
  kern.ipc.shmseg=1024

# LARGE PAGE MAPPINGS
  vm.pmap.pg_ps_enabled=1

# SHARED MEMORY
  kern.ipc.shmmni=1024
  kern.ipc.shmseg=1024

# ZFS TUNING
  vfs.zfs.prefetch_disable=1
  vfs.zfs.cache_flush_disable=1
  vfs.zfs.vdev.cache.size=16M
  vfs.zfs.arc_min=32M
  vfs.zfs.arc_max=128M
  vfs.zfs.txg.timeout=1

# NETWORK MAX SEND QUEUE SIZE
  net.link.ifqmaxlen=2048

# POWER OFF DEVICES WITHOUT ATTACHED DRIVER
  hw.pci.do_power_nodriver=3

# AHCI POWER MANAGEMENT FOR EVERY USED CHANNEL (ahcich 0-7)
  hint.ahcich.0.pm_level=5
  hint.ahcich.1.pm_level=5
  hint.ahcich.2.pm_level=5
  hint.ahcich.3.pm_level=5
  hint.ahcich.4.pm_level=5
  hint.ahcich.5.pm_level=5
  hint.ahcich.6.pm_level=5
  hint.ahcich.7.pm_level=5

# GELI THREADS
  kern.geom.eli.threads=2
  kern.geom.eli.batch=1

The /etc/rc.conf file.

# NETWORK
  hostname=offsite.local
  background_dhclient=YES
  extra_netfs_types=NFS
  defaultroute_delay=3
  defaultroute_carrier_delay=3

# MODULES/COMMON/BASE
  kld_list="${kld_list} aesni geom_eli"
  kld_list="${kld_list} fuse coretemp sem cpuctl ichsmb cc_htcp"
  kld_list="${kld_list} libiconv cd9660_iconv msdosfs_iconv udf_iconv"

# POWER
  performance_cx_lowest=C1
  economy_cx_lowest=Cmax
  powerd_enable=YES
  powerd_flags="-n adaptive -a hiadaptive -b adaptive -m 400 -M 1200"

# DAEMONS | yes
  zfs_enable=YES
  nfs_client_enable=YES
  syslogd_flags='-s -s'
  sshd_enable=YES

# DAEMONS | no
  sendmail_enable=NONE
  sendmail_submit_enable=NO
  sendmail_outbound_enable=NO
  sendmail_msp_queue_enable=NO

# FS
  fsck_y_enable=YES
  clear_tmp_enable=YES
  clear_tmp_X=YES
  growfs_enable=YES

# OTHER
  keyrate=fast
  font8x14=vgarom-8x14
  virecover_enable=NO
  update_motd=NO
  devfs_system_ruleset=desktop
  hostid_enable=NO

USB Boot Drive

I was not sure if I should use USB 2.0 drive or USB 3.0 drive for FreeBSD system so I got both versions from SanDisk and tested their performance with pv(1) and diskinfo(8) tools. The pv(1) utility had options enabled shown below and for diskinfo(8) the -c and -i parameters were used.

% which pv
pv: aliased to pv -t -r -a -b -W -B 1048576

The dmesg(8) information for the SanDisk Fit USB 2.0 16GB drive.

# dmesg | tail -6
da0 at umass-sim0 bus 0 scbus3 target 0 lun 0
da0:  Removable Direct Access SPC-4 SCSI device
da0: Serial Number 4C530001100609104091
da0: 40.000MB/s transfers
da0: 15060MB (30842880 512 byte sectors)
da0: quirks=0x2

The dmesg(8) information for the SanDisk Fit USB 3.0 16GB drive.

# dmesg | tail -6
da0 at umass-sim0 bus 0 scbus3 target 0 lun 0
da0:  Removable Direct Access SPC-4 SCSI device
da0: Serial Number 4C530 001070202100093
da0: 40.000MB/s transfers
da0: 14663MB (30031250 512 byte sectors)
da0: quirks=0x2

There is also noticeable size difference as the USB 2.0 version has additional 400 MB of space!

By the way … the SanDisk Fit USB 3.0 16GB came with this sticker inside the box – a serial number for the RescuePRO Deluxe software – which I will never use. Not because its bad or something but because I have no such needs. You may take it … of course unless someone else did not took it already πŸ™‚

silent-backup-license.jpg

Below are the results of the benchmarks, I tested them in both USB 2.0 and USB 3.0 ports.


                   DRIVE  USB  pv/READ  pv/WRITE  diskinfo/OVERHEAD  diskinfo/IOPS
SanDisk Fit USB 2.0 16GB  2.0   29MB/s     5MB/s   0.712msec/sector           2521
SanDisk Fit USB 2.0 16GB  3.0   33MB/s     5MB/s   0.799msec/sector           2441
SanDisk Fit USB 3.0 16GB  2.0   35MB/s     9MB/s   0.618msec/sector           1920
SanDisk Fit USB 3.0 16GB  3.0   91MB/s    11MB/s   0.567msec/sector           1588

What is also interesting is that while USB 2.0 version has lower throughput it has more IOPS then the newer USB 3.0 incarnation of the SanDisk Fit drive. I also did other more real life test. I checked how long would it take to boot FreeBSD system installed on each of them from the loader(8) screen to the login: prompt. The difference is 5 seconds. Details are shown below.

 TIME  DRIVE
  28s  SanDisk Fit USB 3.0 16GB
  33s  SanDisk Fit USB 2.0 16GB

With such small ~15% difference I will use SanDisk Fit USB 2.0 16GB as it sticks out little less outside from the slot as shown below.

silent-backup-usb-drives.jpg

Cloud Storage Prices Comparison

The Tarsnap“online backups for the truly paranoid” – costs $0.25/GB/month. The price in Tarsnap is for data transmitted after deduplication and compression but that does not change much here. For my data the compressratio property from ZFS dataset is at 3% (1.03). When I estimate deduplication savings with zdb -S pool command I get additional 1% of the savings (1.01). Lets assume that with both deduplication and compression it would take 5% (1.05) savings. That would lower the Tarsnap price to $0.2375/GB/month.

The Backblaze B2 Cloud Storage – storage costs $0.005/GB/month.

Our single 4TB disk solution costs $230 for lets say 3 years. You can expect disk failure after that period but it may serve you as well for another 3 years. Now as we know the cloud storage prices lets calculate price for 4TB data stored for 3 years in these cloud services.

Self Solution Electricity Cost

We also need to calculate how much energy our build solution would consume. Currently 1kWh of power costs about $0.20 in Europe/Poland (rounded up). This means that running computer with 1000W power usage for 1 hour would cost you $0.20 on electricity bill. Our solution idles at 8.5W and uses 13.9W when fully loaded. It will be idle for most of the time so I will assume that it will use 10W on average here. That would cost us $0.002 for 10W device running for 1 hour.

Below you will also find calculations for 1 day (24x multiplier), 1 year (another 365.25x multiplier) and 3 years (another 3x multiplier).

  COST  TIME
$0.002  1 HOUR
$0.048  1 DAY
$17.53  1 YEAR
$52.60  3 YEARS

Our total 3 years electricity cost is $282.60 for building and then running the system non-stop. We can also implement features like Wake On LAN to limit that power usage even more for example.

Here are these cloud storage service providers prices.


PROVIDER     PRICE  DATA  TIME
Tarsnap    $0.2375   1GB  1 Month
Backblaze  $0.0050   1GB  1 Month

The price for 1 month of keeping 4TB of data on these providers looks as follows.


PROVIDER   PRICE  DATA  TIME
Tarsnap     $973   4TB  1 Month
Backblaze    $20   4TB  1 Month

For just 1 month the Tarsnap is 4 TIMES more expensive the keeping the backup on your self computer with 4TB disk. The Backblaze service is at 1/10 cost which is still reasonable.

Lets compare prices for 3 years of 4TB storage.


PROVIDER    PRICE  DATA  TIME
Tarsnap    $35021   4TB  3 Years
Backblaze    $737   4TB  3 Years

After 3 years the Backblaze solutions is about 2.5 TIMES more expensive then our personal setup, but if you really do not want to create your solution the difference for 3 years is not that big. The Tarsnap is out of bounds here being more then 120 TIMES more expensive then self hosted solution. Remember that I also did not included costs for transferring the data into or from the cloud storage. That would make cloud storage costs even bigger depending how often you would want to pull/push your data.

EOF