# Run FreeBSD from an SD-card?



## rainer_d (Feb 18, 2016)

Hi,

with the advent of ZFS on Linux, running FreeBSD (and Linux) from an SD-card has come into focus here, once again.
The last time I tried it, I got "strange" errors sometimes, maybe due to the slowness of the card.
Are there any guidelines or  tips for running a stock operating system on SD-cards?
The idea is to be able to utilize all available drive slots for actual data-drives (ZFS pool).
Currently, for our HP Gen9 servers, we need to buy a special "rear cage" which holds two drives and an extra RAID controller.


----------



## wblock@ (Feb 18, 2016)

There are actual USB3 SSDs now.  I'd lean more towards that.  Actually, I have a 32G Lexar USB3 stick with an install of FreeBSD.  Other than booting speed, it's not bad.


----------



## robroy (Feb 18, 2016)

rainer_d, I use a ThinkPad X230 which boots from a SanDisk Ultra Fit on a USB 3.0 port.  I have noticed that this particular USB stick runs warm to the touch, and it's occasionally slow while installing packages (including sporadic I/O hangs which last about five seconds), but it seems fine otherwise.  ZFS scrubs have never reported any problems with it, and I've used it like this for about a year.

I've also been running a Supermicro 5018A-MHN4 with this same USB stick model plugged directly in to its motherboard for the past few months, and it's working fine so far, though I know it might fail at any moment.  I wouldn't risk it like this if either system were depended on by a lot of people.


----------



## rainer_d (Feb 18, 2016)

People tell me they run Ubuntu on SD-cards with no problem (at home, read/write mounted, of course).
But I just can't bring myself to completely trust it. I would trust read-only mounted SD-cards more, but I'm not sure how useful that really is in practice. 

BTW: the NanoBSD documentation here: https://www.freebsd.org/doc/en/articles/nanobsd/howto.html seems to be bit out of date. Still mentions pkg_add.


----------



## SirDice (Feb 19, 2016)

rainer_d said:


> I would trust read-only mounted SD-cards more, but I'm not sure how useful that really is in practice.


It might take a bit of fiddling but it should certainly be possible to run off a read-only system, the Live CD option of the CD/DVD installers use the same principle. You could point syslogd(8) to an external logging host and you'd probably need to use a RAM disk (tmpfs(5) and/or mdmfs(8)) for things like /var/ and /tmp.

You can keep it read-only during normal operations and only switch it to read/write for updates for example.


----------



## Oko (Feb 20, 2016)

rainer_d said:


> Hi,
> 
> with the advent of ZFS on Linux, running FreeBSD (and Linux) from an SD-card has come into focus here, once again.
> The last time I tried it, I got "strange" errors sometimes, maybe due to the slowness of the card.
> ...


There is something even better. There are two (possibly three) turn key NAS appliances which could run of SD cards. I have being using FreeNAS 9.2.1.9 almost for two years now without any problems. I run it from 16 GB M.2 SSD drive. Note that 9.2.1.9 is the last version which uses UFS for OS. It is based of NanoBSD so it is read only system. FreeNAS 9.3 uses ZFS for OS. NAS4Free is also tailored for embedded devices (read to run of SSD, flash drive or similar). It has a smaller following but it is a nice product. Finally I am not familiar with ZFSgury so I am not sure if it is tailored for embedded devices.

There is nothing that prevents you from building minimalists embedded image using NanoBSD tools.


----------



## sidetone (Feb 20, 2016)

So to make it a read-only SD-card or USB, you'd set the partition with boot by using /etc/fstab with ro? I understand that will work, but will it be enough to stop the filesystem from being corrupted if it doesn't start up properly? This problem happened too many times with me for USB operating systems or install medium, where the contents had to be constantly reinstalled.


----------



## Juha Nurmela (Feb 20, 2016)

This looks promising https://www.seanet.com/~karllunt/sdlocker.html

"the PERM_WRITE_PROTECT bit in the card's CSD register.  As its name implies, this is a permanent write-lock, though the card's data can still be read.  The bit is cleared from the factory and can be set one time only; once set, it cannot be cleared."

Juha


----------



## sidetone (Feb 20, 2016)

"TMP_WRITE_PROTECT bit in the card's CSD register." Which file does this, or how is this done for FreeBSD?


----------



## Juha Nurmela (Feb 20, 2016)

That Mr Lunt uses a microcontroller. It should be doable on FreeBSD also, browsing /dev/mmc/

Juha


----------



## sidetone (Feb 20, 2016)

It appears to be in the driver or physically soldered on. Why not set the partition to 
	
	



```
ro
```
 in /etc/fstab? Ok, now I realize this isn't always early enough in the boot process to protect the filesystem.


----------



## Juha Nurmela (Feb 20, 2016)

I'm just being silly again. If one really wanted to, an SD could be turned into a ROM by flipping a write-once bit in the chip. One bit for temporary write-protect, another for permanent freeze.

The functionality does not seem to exist in FreeBSD: MMC_PROGRAM_CSD command is defined, but not used anywhere.

Juha


----------



## rainer_d (Feb 20, 2016)

NanoBSD is probably the way to go. I will have to look into it more closely. For stuff like a NAS, FreeNAS is probably enough.
Perhaps it might be more practical to run NanoBSD + iocage (AFAIK, iocage stores all its configuration on ZFS datasets, so the read-only SD card would be untouched.
I would only need to get nullfs mounts inside the jails working (I run mostly php stuff, chrooted, with some directories read-only mounted from the base-system).


----------



## Oko (Feb 20, 2016)

rainer_d said:


> People tell me they run Ubuntu on SD-cards with no problem (at home, read/write mounted, of course).


People do silly things  I run my home firewall flashrd embedded installation of OpenBSD of 16GB SSD. With exception of /flash partition everything is read only and fully loaded into the RAM.DF HAMMER is one of those rare file system which can take advantage of flash based hard drives. Unfortunately /boot on DF is always UFS. That is only 1MB


----------

