From fbfb4c27e623dffcfdae5d0c7480e0ddab2ad7bb Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 12 Nov 2024 10:11:35 +0100 Subject: [PATCH] mount --- bash/mount.sh | 100 ++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/bash/mount.sh b/bash/mount.sh index 9fda047..b9bc609 100644 --- a/bash/mount.sh +++ b/bash/mount.sh @@ -1,41 +1,44 @@ mo() { -local directory="${1}" -local file -if [ "${directory}" ] ; then - directory="$(realpath "${directory}")" - file="${directory}/filesystem.squashfs" - if mkdir "overlay" ; then - cd "overlay" - mkdir {lower,upper,work,mount} - if mount "${file}" "lower" ; then - mount -t "overlay" "overlay" "mount" \ --o lowerdir="lower",upperdir="upper",workdir="work" - fi - cd .. - fi -else - echo "KO: directory?" -fi + local directory="${1}" + local file + if [ "${directory}" ] ; then + directory="$(realpath "${directory}")" + file="${directory}/filesystem.squashfs" + if mkdir "overlay" ; then + cd "overlay" + mkdir {lower,upper,work,mount} + if mount "${file}" "lower" ; then + mount \ + -o lowerdir="lower",upperdir="upper",workdir="work" + -t "overlay" \ + "overlay" "mount" + fi + cd .. + fi + else + echo "KO: directory?" + fi } uo() { -cd "overlay" -if umount "mount" ; then - rmdir "mount" - rm --recursive "upper" "work" - if umount "lower" ; then - rmdir "lower" - fi -fi -cd .. -rmdir "overlay" + cd "overlay" + if umount "mount" ; then + rmdir "mount" + rm --recursive "upper" "work" + if umount "lower" ; then + rmdir "lower" + fi + fi + cd .. + rmdir "overlay" } mr() { -for f in "dev" "dev/pts" "proc" "sys" ; do - mount --bind "/${f}" "overlay/mount/${f}" -done + local f + for f in "dev" "dev/pts" "proc" "sys" ; do + mount --bind "/${f}" "overlay/mount/${f}" + done } alias cr="\ @@ -50,33 +53,34 @@ chroot \ " ur() { -for f in "sys" "proc" "dev/pts" "dev" ; do - umount --lazy "overlay/mount/${f}" -done + local f + for f in "sys" "proc" "dev/pts" "dev" ; do + umount --lazy "overlay/mount/${f}" + done } mm() { -mount --make-rslave --rbind "/deb" "overlay/mount/deb" + mount --make-rslave --rbind "/deb" "overlay/mount/deb" } um() { -umount --recursive "overlay/mount/deb" + umount --recursive "overlay/mount/deb" } ms() { -local directory="${1}" -local level="${2}" -if [ "${directory}" ] ; then - if mkdir "${directory}" ; then - [ "${level}" ] || level="18" - cp overlay/mount/{vmlinuz,initrd.img} "${directory}" - mksquashfs \ -"overlay/mount" "${directory}/filesystem.squashfs" \ --noappend \ --comp "zstd" -Xcompression-level "${level}" - chown --recursive 1000:1000 "${directory}" - fi -fi + local directory="${1}" + local level="${2}" + if [ "${directory}" ] ; then + if mkdir "${directory}" ; then + [ "${level}" ] || level="18" + cp overlay/mount/{vmlinuz,initrd.img} "${directory}" + mksquashfs \ + "overlay/mount" "${directory}/filesystem.squashfs" \ + -noappend \ + -comp "zstd" -Xcompression-level "${level}" + chown --recursive 1000:1000 "${directory}" + fi + fi }