wip/mount

This commit is contained in:
Marc Beninca 2024-11-16 04:23:54 +01:00
parent 36aaa275a7
commit 58ca9eb86f
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -1,52 +1,75 @@
mo() { mo() {
local root="${1}" local root="${1}"
if [ -z "${root}" ]; then if [ -z "${root}" ]; then
log_error "No root" log_error "No root target directory"
return 1 return 1
fi fi
root="$(realpath "${root}")" root="$(realpath "${root}")"
if ! mkdir "overlay"; then if ! mkdir "overlay"; then
log_error "Unable to make mount directory" log_error "Unable to make overlay directory"
return 2 return 2
fi fi
{ (
if ! cd "overlay"; then if ! cd "overlay"; then
log_error "Unable to move into mount directory" log_error "Unable to move into overlay directory"
return 3 return 3
fi fi
local directory local directory
for directory in "lower" "upper" "work" "mount"; do for directory in "lower" "upper" "work" "mount"; do
if ! mkdir --parents "${directory}"; then if ! mkdir --parents "${directory}"; then
log_error "Unable to move into: ${directory}" log_error "Unable to make directory: ${directory}"
return 4 return 4
fi fi
done done
local file="${root}/filesystem.squashfs" local file="${root}/filesystem.squashfs"
if ! mount "${file}" "lower"; then if ! mount "${file}" "lower"; then
log_error "Unable to mount: ${file}" log_error "Unable to lower mount: ${file}"
return 5 return 5
fi fi
if ! mount \ if ! mount \
-o "lowerdir=lower,upperdir=upper,workdir=work" \ -o "lowerdir=lower,upperdir=upper,workdir=work" \
-t "overlay" \ -t "overlay" \
"overlay" "mount"; then "overlay" "mount"; then
log_error "Unable to mount: ${file}" log_error "Unable to overlay mount"
return 6 return 6
fi fi
} )
} }
uo() { uo() {
cd "overlay" (
if umount "mount"; then if ! cd "overlay"; then
rmdir "mount" log_error "Unable to move into overlay directory"
rm --recursive "upper" "work" return 1
if umount "lower"; then
rmdir "lower"
fi fi
if ! umount "mount"; then
log_error "Unable to unmount mount directory"
return 2
fi
if ! rmdir "mount"; then
log_error "Unable to remove mount directory"
return 3
fi
local directory
for directory in "upper" "work"; do
if ! rm --force --recursive "${directory}"; then
log_error "Unable to remove directory: ${directory}"
return 4
fi
done
if ! umount "lower"; then
log_error "Unable to unmount lower directory"
return 5
fi
if ! rmdir "lower"; then
log_error "Unable to remove lower directory"
return 6
fi
)
if ! rmdir "overlay"; then
log_error "Unable to remove overlay directory"
return 7
fi fi
cd ..
rmdir "overlay"
} }
mr() { mr() {