Jump to content
Xaero

Persistent home directory

1 post in this topic Last Reply

Recommended Posts

Posted (edited)

Good evening!
I'd like to not only request this as a feature, but explain how one could implement this on their own!

Basically, the idea is that all user customization done via configuration files located in "/root" are lost on each boot.
I know this is intentional, but there's an "easy" way to implement this with clever failsafe mechanics.
I also know that one can work around this by adding a couple of lines to /boot/config/go, and storing the configuration files on the flash drive. This isn't as desirable as Fat32 doesn't properly handle Linux permissions, and can require other manual edits to the go file down the road.


Enter OverlayFS (a feature built into the Linux kernel for eons)

 

First we create our "persistent" image:


#This will allocate a 1kb sparse file, with an apparent size of ~4GB - the Fat32 ceiling.

dd if=/dev/zero of=/boot/config/root.persist bs=1k seek=4000k count=1

mkfs.ext4 /boot/config/root.persist

 

Next, we must set up some directories for the overlayfs module to work properly:


mkdir /tmp/overlay

mount /boot/config/root.persist /tmp/overlay

mkdir /tmp/overlay/upper

mkdir/tmp/overlay/work

 


And finally, now that this has been created we must create the overlayfs:

 

 

 

 

Finally, we can use /boot/config/go to do the two mount operations on startup, by adding the following three lines to the bottom of the go file:


mkdir /tmp/overlay

mount /boot/config/root.persist /tmp/overlay

mount -t overlay -o lowerdir=/root,upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work none /root

 


So, how does this work from Limetech's perspective and with the "failsafe" boot mode? How are users protected from themselves or persist file corruption?

Overlay FS makes the "lowerdir" (in this case, the stock unraid /root folder) read-only. Unraid's /root folder is created on boot every time, and is effectively read only anyways. The upperdir, is read/write, any changes made to the upperdir "mask" the contents of the lowerdir, and any additions appear seamlessly. If upperdir fails to mount (corruption), the mount will fail gracefully, and the stock unraid /root folder will be intact and the boot should continue normally. If this isn't the case, a user could also easily boot into failsafe mode, where the mount operation shouldn't be called (this would be if limetech were to implement this as a feature. You as a user making changes to the 'go' file are responsible for what happens in the event of the 'go' file not doing what it's supposed to.

For sanity, one should be wrapping the mount commands like so:

mkdir /tmp/overlay
{ mount /boot/config/root.persist /tmp/overlay &&
  mount -t overlay -o lowerdir=/root,upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work none /root
} || { rmdir /tmp/overlay }

 


What the above snippet does is this:
Creates the overlay directory.
Tries to both mount the persist image, and create the overlay mount on the /root directory
If that fails either step, it destroys the /tmp/overlay folder.

 

 

Edited by Xaero

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.