2024-11-12 08:43:56 +00:00
|
|
|
mo() {
|
2024-11-16 02:34:01 +00:00
|
|
|
local root="${1}"
|
2024-11-16 03:04:44 +00:00
|
|
|
if [ -z "${root}" ]; then
|
2024-11-16 03:23:54 +00:00
|
|
|
log_error "No root target directory"
|
2024-11-16 02:34:01 +00:00
|
|
|
return 1
|
2024-11-12 09:11:35 +00:00
|
|
|
fi
|
2024-11-16 03:04:44 +00:00
|
|
|
root="$(realpath "${root}")"
|
|
|
|
if ! mkdir "overlay"; then
|
2024-11-16 03:23:54 +00:00
|
|
|
log_error "Unable to make overlay directory"
|
2024-11-16 03:04:44 +00:00
|
|
|
return 2
|
|
|
|
fi
|
2024-11-16 03:23:54 +00:00
|
|
|
(
|
2024-11-16 03:04:44 +00:00
|
|
|
if ! cd "overlay"; then
|
2024-11-16 03:23:54 +00:00
|
|
|
log_error "Unable to move into overlay directory"
|
2024-11-16 03:04:44 +00:00
|
|
|
return 3
|
|
|
|
fi
|
|
|
|
local directory
|
|
|
|
for directory in "lower" "upper" "work" "mount"; do
|
|
|
|
if ! mkdir --parents "${directory}"; then
|
2024-11-16 03:23:54 +00:00
|
|
|
log_error "Unable to make directory: ${directory}"
|
2024-11-16 03:04:44 +00:00
|
|
|
return 4
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
local file="${root}/filesystem.squashfs"
|
|
|
|
if ! mount "${file}" "lower"; then
|
2024-11-16 03:23:54 +00:00
|
|
|
log_error "Unable to lower mount: ${file}"
|
2024-11-16 03:04:44 +00:00
|
|
|
return 5
|
|
|
|
fi
|
|
|
|
if ! mount \
|
|
|
|
-o "lowerdir=lower,upperdir=upper,workdir=work" \
|
|
|
|
-t "overlay" \
|
|
|
|
"overlay" "mount"; then
|
2024-11-16 03:23:54 +00:00
|
|
|
log_error "Unable to overlay mount"
|
2024-11-16 03:04:44 +00:00
|
|
|
return 6
|
|
|
|
fi
|
2024-11-16 03:23:54 +00:00
|
|
|
)
|
2023-05-09 20:02:34 +00:00
|
|
|
}
|
|
|
|
|
2024-11-12 08:43:56 +00:00
|
|
|
uo() {
|
2024-11-16 03:23:54 +00:00
|
|
|
(
|
|
|
|
if ! cd "overlay"; then
|
|
|
|
log_error "Unable to move into overlay directory"
|
|
|
|
return 1
|
|
|
|
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
|
2024-11-12 09:11:35 +00:00
|
|
|
fi
|
2024-11-16 03:23:54 +00:00
|
|
|
)
|
|
|
|
if ! rmdir "overlay"; then
|
|
|
|
log_error "Unable to remove overlay directory"
|
|
|
|
return 7
|
2024-11-12 09:11:35 +00:00
|
|
|
fi
|
2023-05-09 20:02:34 +00:00
|
|
|
}
|
|
|
|
|
2024-11-12 08:43:56 +00:00
|
|
|
mr() {
|
2024-11-12 09:11:35 +00:00
|
|
|
local f
|
2024-11-13 10:34:59 +00:00
|
|
|
for f in "dev" "dev/pts" "proc" "sys"; do
|
2024-11-12 09:11:35 +00:00
|
|
|
mount --bind "/${f}" "overlay/mount/${f}"
|
|
|
|
done
|
2023-05-09 20:02:34 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 21:12:22 +00:00
|
|
|
alias cr="\
|
|
|
|
chroot \
|
|
|
|
\"overlay/mount\" \
|
|
|
|
"
|
|
|
|
|
|
|
|
alias cru="\
|
|
|
|
chroot \
|
|
|
|
--userspec \"1000:1000\" \
|
|
|
|
\"overlay/mount\" \
|
|
|
|
"
|
2023-05-09 20:02:34 +00:00
|
|
|
|
2024-11-12 08:43:56 +00:00
|
|
|
ur() {
|
2024-11-12 09:11:35 +00:00
|
|
|
local f
|
2024-11-13 10:34:59 +00:00
|
|
|
for f in "sys" "proc" "dev/pts" "dev"; do
|
2024-11-12 09:11:35 +00:00
|
|
|
umount --lazy "overlay/mount/${f}"
|
|
|
|
done
|
2023-05-09 20:02:34 +00:00
|
|
|
}
|
|
|
|
|
2024-11-12 08:43:56 +00:00
|
|
|
mm() {
|
2024-11-12 09:11:35 +00:00
|
|
|
mount --make-rslave --rbind "/deb" "overlay/mount/deb"
|
2023-05-09 20:02:34 +00:00
|
|
|
}
|
|
|
|
|
2024-11-12 08:43:56 +00:00
|
|
|
um() {
|
2024-11-12 09:11:35 +00:00
|
|
|
umount --recursive "overlay/mount/deb"
|
2023-05-09 20:02:34 +00:00
|
|
|
}
|
|
|
|
|
2024-11-12 08:43:56 +00:00
|
|
|
ms() {
|
2024-11-12 09:11:35 +00:00
|
|
|
local directory="${1}"
|
2024-11-16 02:34:01 +00:00
|
|
|
local file
|
2024-11-12 09:11:35 +00:00
|
|
|
local level="${2}"
|
2024-11-13 10:34:59 +00:00
|
|
|
if [ -n "${directory}" ]; then
|
|
|
|
if mkdir "${directory}"; then
|
2024-11-12 09:25:44 +00:00
|
|
|
[ -n "${level}" ] || level="18"
|
2024-11-16 02:34:01 +00:00
|
|
|
for file in "vmlinuz" "initrd.img"; do
|
|
|
|
cp "overlay/mount/${file}" "${directory}"
|
|
|
|
done
|
2024-11-12 09:11:35 +00:00
|
|
|
mksquashfs \
|
|
|
|
"overlay/mount" "${directory}/filesystem.squashfs" \
|
|
|
|
-noappend \
|
|
|
|
-comp "zstd" -Xcompression-level "${level}"
|
|
|
|
chown --recursive 1000:1000 "${directory}"
|
|
|
|
fi
|
|
|
|
fi
|
2023-05-09 20:02:34 +00:00
|
|
|
}
|