mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.7 KiB
74 lines
1.7 KiB
6 years ago
|
#!/bin/bash
|
||
|
|
||
|
# Mount home as an overlay filesystem
|
||
|
|
||
|
# Log stdout & stderr
|
||
|
exec > >(tee -i /tmp/gdm3_postlogin.log)
|
||
|
exec 2>&1
|
||
|
|
||
|
# Treat unset variables as an error when substituting.
|
||
|
set -u
|
||
|
|
||
|
# Exit immediately if a command exits with a non-zero status.
|
||
|
set -e
|
||
|
|
||
|
# Separate tokens on newlines only
|
||
|
IFS='
|
||
|
'
|
||
|
|
||
|
# The value of this parameter is expanded like PS1 and the expanded value is the
|
||
|
# prompt printed before the command line is echoed when the -x option is set
|
||
|
# (see The Set Builtin). The first character of the expanded value is replicated
|
||
|
# multiple times, as necessary, to indicate multiple levels of indirection.
|
||
|
# \D{%F %T} prints date like this : 2019-12-31 23:59:59
|
||
|
PS4='-\D{%F %T} '
|
||
|
|
||
|
# Print commands and their arguments as they are executed.
|
||
|
set -x
|
||
|
|
||
|
sleep 0.5
|
||
|
|
||
|
# Find the first removable F2FS partition
|
||
|
PART=$(lsblk -o tran,kname,hotplug,type,fstype -pr |
|
||
|
grep '1 part f2fs' |
|
||
|
cut -d' ' -f2 |
|
||
|
sort |
|
||
|
head -n1)
|
||
|
|
||
|
# Make sure the mountpoints are free
|
||
|
(
|
||
|
lsof -t $HOME | xargs kill -9
|
||
|
umount $HOME
|
||
|
umount /mnt
|
||
|
) || true
|
||
|
|
||
|
if test "$PART"
|
||
|
then
|
||
|
mount -o noatime "$PART" /mnt
|
||
|
else
|
||
|
# No removable F2FS partition found, use the third local partition instead
|
||
|
PART=$(lsblk -o tran,kname,hotplug,type,fstype -pr |
|
||
|
grep -v usb |
|
||
|
grep '0 part' |
|
||
|
cut -d' ' -f2 |
|
||
|
sort |
|
||
|
head -n3 |
|
||
|
tail -n1)
|
||
|
|
||
|
if test -z "$PART"
|
||
|
then
|
||
|
# No local partition found, error
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# We don't care about data consistency since the partition is temporary
|
||
|
/sbin/mke2fs -t ext4 -O ^has_journal -F "$PART"
|
||
|
mount -o noatime,nobarrier "$PART" /mnt
|
||
|
fi
|
||
|
|
||
|
USER_PATH=/mnt/.01/$USER
|
||
|
TEMP_PATH=/mnt/.01/tmp
|
||
|
|
||
|
mkdir -p $USER_PATH $TEMP_PATH
|
||
|
mount -t overlay -o lowerdir=$HOME,upperdir=$USER_PATH,workdir=$TEMP_PATH overlay $HOME
|