Making a writable /root for your .ssh directory and other things...

Status
Not open for further replies.
Joined
Oct 24, 2013
Messages
1
Using FreeNAS via thumb drive image leaves us with a / filesystem that isn't writable, of course. The googling around we've done shows you can remount read / write, make the few changes you need, and remount read-only again. Those same places mentioned the same thing we end up seeing... A terrible slowness to commit those changes and remount when going back to read-only, during which, other I/O seems to stop.

Well, for automation, I'm needing to install a lot of ssh keys. But, as luck would have it, FreeBSD supports UnionFS. Sweet!

I can create a "root" directory under /var, or /mnt... or in my case, create a dataset at /mnt/pool01/root.

The advantage of placing this on my ZFS data volume is that if I need to swap to a backup USB stick to boot FreeNAS, the data will be persistent.

Now for the fun part:

Go to 'Init/Shutdown Scripts' in the web ui.
Click 'Add Init/Shutdown Script'
Then Type is: command
Command is: mount -t unionfs -o noatime /mnt/pool01/root /root (or use whatever path you used, maybe /var/root?)
Set Type: Post Init

Reboot, or from a root shell, issue the same command as the Command above, and you are set with a writable /root directory.

And that's it. You now have a writable /root with usable performance, while keeping the rest of / read-only.

Any new files or changes you make to /root will go to the destination directory, like /mnt/pool01/root for permanent storage, but will very nicely appear in /root, as well.

I'm not seeing any ill effects from this. If anyone can think of any, please let me know.
 

Whattteva

Wizard
Joined
Mar 5, 2013
Messages
1,824
While a nifty solution, I'm not exactly sure why you'd need to use /root that much. After all, logging in as root is never recommended. Generally, you log in as yourself and then elevate to root to do maintenance stuff, then go back down to regular user.

You can change your home directory rather easily through FreeNAS web UI and I just place all the scripts/shortcuts I need in there instead and elevate as needed.
It achieves essentially the same effect that you mentioned. It's persistent AND it survives FreeNAS upgrades cause the data is mounted on my zpool instead. On top of that, you can have the whole zpool encrypted for added security.
It's much less hassle, future-proof, and more secure in my opinion, but you're free to do as you wish.
 
Status
Not open for further replies.
Top