Skip to content

Commit ff6742c

Browse files
committed
custom-persist: handle mounts from /rw/home and /rw/usrlocal
Custom persist disables /home and /usr/local persistence by default but a user may want to bind mount a file or a directory in one of those locations without mounting the whole directories. For example, we should be able to mount /home/user/.ssh/ but keep the rest of /home/user non-persistent. With this fix, bind dirs detects when an object is located under /home or /usr/local and will look in the associated /rw/home or /rw/usrlocal instead of /rw/bind-dirs. If needed, custom-persist will pre-create the objects in the same location.
1 parent 4d12979 commit ff6742c

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

vm-systemd/bind-dirs.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ shopt -s nullglob dotglob
2929
# shellcheck source=init/functions
3030
source /usr/lib/qubes/init/functions
3131

32+
readonly DEFAULT_RW_BIND_DIR="/rw/bind-dirs"
33+
3234
prerequisite() {
3335
if is_fully_persistent ; then
3436
echo "No TemplateBasedVM/DisposableVM detected. Exiting."
@@ -37,7 +39,7 @@ prerequisite() {
3739
}
3840

3941
init() {
40-
[ -n "$rw_dest_dir" ] || rw_dest_dir="/rw/bind-dirs"
42+
[ -n "$rw_dest_dir" ] || rw_dest_dir="$DEFAULT_RW_BIND_DIR"
4143
[ -n "$symlink_level_max" ] || symlink_level_max="10"
4244
mkdir --parents "$rw_dest_dir"
4345
}
@@ -49,6 +51,21 @@ legacy() {
4951
true
5052
}
5153

54+
rw_from_ro() {
55+
ro="$1"
56+
# special cases for files/dirs in /home or /usr/local
57+
if [[ "$ro" =~ ^/home/ ]]; then
58+
# use /rw/home for /home/... binds
59+
rw="/rw${ro}"
60+
elif [[ "$ro" =~ ^/usr/local/ ]]; then
61+
# use /rw/usrlocal for /usr/local/... binds
62+
rw="/rw/usrlocal/$(echo "$ro" | cut -d/ -f4-)"
63+
else
64+
[ -z "$rw_dest_dir" ] && rw="${DEFAULT_RW_BIND_DIR}${ro}" || rw="${rw_dest_dir}${ro}"
65+
fi
66+
echo "$rw"
67+
}
68+
5269
bind_dirs() {
5370
## legend
5471
## fso: file system object
@@ -77,7 +94,7 @@ bind_dirs() {
7794
done
7895

7996
true "fso_ro: $fso_ro"
80-
fso_rw="${rw_dest_dir}${fso_ro}"
97+
fso_rw="$(rw_from_ro "$fso_ro")"
8198

8299
# Make sure fso_ro is not mounted.
83100
umount "$fso_ro" 2> /dev/null || true
@@ -159,7 +176,7 @@ if is_custom_persist_enabled; then
159176
continue
160177
fi
161178

162-
rw_path="/rw/bind-dirs${path}"
179+
rw_path="$(rw_from_ro "${path}")"
163180
# create resource if it does not exist
164181
if ! [ -e "${path}" ] && ! [ -e "$rw_path" ]; then
165182
if [ "$resource_type" = "file" ]; then

0 commit comments

Comments
 (0)