Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f456a2b

Browse files
committed
Improved mount and unmount functions
1 parent 1a061e8 commit f456a2b

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

‎cli.sh‎

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,16 @@ mount_part()
618618
selinux)
619619
selinux_support || return 0
620620
msg -n "/sys/fs/selinux ... "
621+
if ! is_mounted "/sys/fs/selinux" ; then
622+
mount -t selinuxfs selinuxfs /sys/fs/selinux
623+
fi
621624
local target="${CHROOT_DIR}/sys/fs/selinux"
622625
if ! is_mounted "${target}" ; then
623626
if [ -e "/sys/fs/selinux/enforce" ]; then
624627
cat /sys/fs/selinux/enforce > "${TEMP_DIR}/selinux_state"
625628
echo 0 > /sys/fs/selinux/enforce
626629
fi
627-
mount -t selinuxfs selinuxfs "${target}" &&
630+
mount -o bind /sys/fs/selinux "${target}" &&
628631
mount -o remount,ro,bind "${target}"
629632
is_ok "fail" "done"
630633
else
@@ -636,64 +639,72 @@ mount_part()
636639
local target="${CHROOT_DIR}/dev"
637640
if ! is_mounted "${target}" ; then
638641
[ -d "${target}" ] || mkdir -p "${target}"
639-
[ -e "/dev/fd" ] || ln -s /proc/self/fd /dev/
640-
[ -e "/dev/stdin" ] || ln -s /proc/self/fd/0 /dev/stdin
641-
[ -e "/dev/stdout" ] || ln -s /proc/self/fd/1 /dev/stdout
642-
[ -e "/dev/stderr" ] || ln -s /proc/self/fd/2 /dev/stderr
643642
mount -o bind /dev "${target}"
644643
is_ok "fail" "done"
645644
else
646645
msg "skip"
647646
fi
648647
;;
649-
tty)
650-
[ ! -e "/dev/tty0" ] || return 0
651-
msg -n "/dev/tty ... "
652-
ln -s /dev/null /dev/tty0
653-
is_ok "fail" "done"
648+
shm)
649+
msg -n "/dev/shm ... "
650+
if ! is_mounted "/dev/shm" ; then
651+
[ -d "/dev/shm" ] || mkdir -p /dev/shm
652+
mount -o rw,nosuid,nodev,mode=1777 -t tmpfs tmpfs /dev/shm
653+
fi
654+
local target="${CHROOT_DIR}/dev/shm"
655+
if ! is_mounted "${target}" ; then
656+
mount -o bind /dev/shm "${target}"
657+
is_ok "fail" "done"
658+
else
659+
msg "skip"
660+
fi
654661
;;
655662
pts)
656663
msg -n "/dev/pts ... "
664+
if ! is_mounted "/dev/pts" ; then
665+
[ -d "/dev/pts" ] || mkdir -p /dev/pts
666+
mount -o rw,nosuid,noexec,gid=5,mode=620,ptmxmode=000 -t devpts devpts /dev/pts
667+
fi
657668
local target="${CHROOT_DIR}/dev/pts"
658669
if ! is_mounted "${target}" ; then
659-
[ -d "${target}" ] || mkdir -p "${target}"
660-
mount -o "mode=0620,gid=5" -t devpts devpts "${target}"
670+
mount -o bind /dev/pts "${target}"
661671
is_ok "fail" "done"
662672
else
663673
msg "skip"
664674
fi
665675
;;
666-
shm)
667-
msg -n "/dev/shm ... "
668-
local target="/dev/shm"
669-
if [ -L "${target}" ]; then
670-
target=$(readlink "${target}")
676+
fd)
677+
if [ ! -e "/dev/fd" -o ! -e "/dev/stdin" -o ! -e "/dev/stdout" -o ! -e "/dev/stderr" ]; then
678+
msg -n "/dev/fd ... "
679+
[ -e "/dev/fd" ] || ln -s /proc/self/fd /dev/
680+
[ -e "/dev/stdin" ] || ln -s /proc/self/fd/0 /dev/stdin
681+
[ -e "/dev/stdout" ] || ln -s /proc/self/fd/1 /dev/stdout
682+
[ -e "/dev/stderr" ] || ln -s /proc/self/fd/2 /dev/stderr
683+
is_ok "fail" "done"
671684
fi
672-
target="${CHROOT_DIR}/${target}"
673-
if ! is_mounted "${target}" ; then
674-
[ -d "${target}" ] || mkdir -p "${target}"
675-
mount -t tmpfs tmpfs "${target}"
685+
;;
686+
tty)
687+
if [ ! -e "/dev/tty0" ]; then
688+
msg -n "/dev/tty ... "
689+
ln -s /dev/null /dev/tty0
676690
is_ok "fail" "done"
677-
else
678-
msg "skip"
679691
fi
680692
;;
681693
tun)
682-
[ ! -e "/dev/net/tun" ] || return 0
683-
msg -n "/dev/net/tun ... "
684-
[ -d "/dev/net" ] || mkdir -p /dev/net
685-
mknod /dev/net/tun c 10 200
686-
is_ok "fail" "done"
694+
if [ ! -e "/dev/net/tun" ]; then
695+
msg -n "/dev/net/tun ... "
696+
[ -d "/dev/net" ] || mkdir -p /dev/net
697+
mknod /dev/net/tun c 10 200
698+
is_ok "fail" "done"
699+
fi
687700
;;
688701
binfmt_misc)
689702
multiarch_support || return 0
690703
local binfmt_dir="/proc/sys/fs/binfmt_misc"
691-
msg -n "${binfmt_dir} ... "
692-
if [ !-e "${binfmt_dir}/register" ];then
704+
if! is_mounted "${binfmt_dir}";then
705+
msg -n "${binfmt_dir} ... "
693706
mount -t binfmt_misc binfmt_misc "${binfmt_dir}"
694707
is_ok "fail" "done"
695-
else
696-
msg "skip"
697708
fi
698709
;;
699710
esac
@@ -706,7 +717,7 @@ container_mount()
706717
[ "${METHOD}" = "chroot" ] || return 0
707718
708719
if [ $# -eq 0 ]; then
709-
container_mount root proc sys selinux dev tty pts shm tun binfmt_misc
720+
container_mount root proc sys selinux dev shm pts fd tty tun binfmt_misc
710721
return $?
711722
fi
712723
@@ -716,7 +727,7 @@ container_mount()
716727
fs_check
717728
is_ok "skip" "done"
718729
719-
msg "Mounting partitions: "
730+
msg "Mounting the container: "
720731
local item
721732
for item in $*
722733
do
@@ -752,9 +763,6 @@ container_umount()
752763
do
753764
local part_name=$(echo ${part} | sed "s|^${CHROOT_DIR%/}/*|/|g")
754765
msg -n "${part_name} ... "
755-
if [ -z "${part_name##*selinux*}" -a -e "/sys/fs/selinux/enforce" -a -e "${TEMP_DIR}/selinux_state" ]; then
756-
cat "${TEMP_DIR}/selinux_state" > /sys/fs/selinux/enforce
757-
fi
758766
for i in 1 2 3
759767
do
760768
umount ${part} && break
@@ -766,12 +774,19 @@ container_umount()
766774
done
767775
[ "${is_mnt}" -eq 1 ]; is_ok " ...nothing mounted"
768776
769-
msg -n "Disassociating loop device ... "
777+
if [ -e "/sys/fs/selinux/enforce" -a -e "${TEMP_DIR}/selinux_state" ]; then
778+
msg -n "Restoring SELinux state ... "
779+
cat "${TEMP_DIR}/selinux_state" > /sys/fs/selinux/enforce &&
780+
rm "${TEMP_DIR}/selinux_state"
781+
is_ok "fail" "done"
782+
fi
783+
770784
local loop=$(losetup -a | grep "${TARGET_PATH%/}" | awk -F: '{print 1ドル}')
771785
if [ -n "${loop}" ]; then
786+
msg -n "Disassociating loop device ... "
772787
losetup -d "${loop}"
788+
is_ok "fail" "done"
773789
fi
774-
is_ok "fail" "done"
775790
776791
return 0
777792
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /