Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[HowTo] DistroHopper data management

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
jmgibson1981
Posts: 305
Joined: 2015-06-07 14:38
Has thanked: 11 times
Been thanked: 34 times

[HowTo] DistroHopper data management

#1 Post by jmgibson1981 »

This is a simple thing I wanted to share. I have a tendency to distro hop quite often yet I don't like sharing /home/"$USER" between different distros for various reasons. Ubuntu uses stuff in snaps. I prefer flatpaks where possible. And a few other distros seem to use nonstandard dotfile locations in /home/"$USER". For the moment I've written a script that allows one to have a separate data partition with (thus far) static locations in /home/"$USER"

Code: Select all

#!/bin/sh
# non volatile directories for user data

DATAMNT=/.data

DIRS=".gnupg
      .ssh
      .config/codeblocks
      .config/kmymoney
      .local/share/flatpak
      .var
      Documents
      Music
      Pictures
      Videos"

for user in /home/* ; do
  USERNAME=$(basename "$user")

  if [ "$USERNAME" = partimg ] || \
     [ "$USERNAME" = lost+found ] ; then
    continue
  fi

  case "$1" in
    boot)
      for dir in $DIRS ; do
        DIRNAME=/home/"$USERNAME"/"$dir"
        DATADIR="$DATAMNT"/"$USERNAME"
        [ -d "$DIRNAME" ] || mkdir -p "$DIRNAME"
        [ -d "$DATADIR"/"$dir" ] || mkdir -p "$DATADIR"/"$dir"
        mount -o bind "$DATADIR"/"$dir" "$DIRNAME"
        chown -R "$USERNAME":"$USERNAME" "$DIRNAME"
      done
      ;;
    shutdown)
      for dir in $DIRS ; do
        umount /home/"$USERNAME"/"$dir"
      done
      ;;
  esac
done
It can probably be refined but I've been working with this for a bit now and seems to work just fine. I fire it on boot via systemd service.

Code: Select all

[Unit]
Description = Mount user data directories

[Service]
Type = oneshot
ExecStart = /usr/local/bin/databind.sh boot
User = root
Group = root

[Install]
WantedBy = multi-user.target
I went with bind mounts because flatpak has some odd occasional issues with symlinks. This bypassed that problem altogether and pretty much takes care of itself. With this there is no reason to move data around, or worry about having miscellaneous stuff floating in home for the OCD crowd that I know I'm a part of. An example of my logical volume layout.

Code: Select all

elementary      main -wi-ao----  12.00g                                                    
  elementary-home main -wi-ao----  25.00g                                                    
  elementary-var  main -wi-ao----   5.00g                                                    
  swap            main -wi-ao----  16.00g                                                    
  userdata        main -wi-ao---- 200.00g
This is on an elementary boot. I'm reinstalling Debian and a few others. With this they can all have instant access to the same stuff with little to no real extra setup.

Post Reply