1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
From 319ac79c47f191e8c0aa2db4ea0eb248b8011bf3 Mon Sep 17 00:00:00 2001
From: David P <megver83@parabola.nu>
Date: Fri, 2 Jul 2021 22:51:20 -0400
Subject: [PATCH] Create mount points if mountpoint exit code is different to
zero
This is better than checking if the exit code equals to 1, as mountpoint will
exit with code 32 if the directory exists but it's not a mount point.
Plus, in the manpage says:
EXIT STATUS
Zero if the directory or file is a mountpoint, non-zero if not.
Signed-off-by: David P <megver83@parabola.nu>
---
chroot-nspawn | 50 +++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/chroot-nspawn b/chroot-nspawn
index 2e1fd8b..d4bc896 100755
--- a/chroot-nspawn
+++ b/chroot-nspawn
@@ -1126,7 +1126,7 @@ unset _SET_PRIVATE_NETWORK
# Mount a fake "/" file system
mountpoint -q $_SET_DIRECTORY
-[ $? = 1 ] && mount -B $_SET_DIRECTORY $_SET_DIRECTORY
+[ $? != 0 ] && mount -B $_SET_DIRECTORY $_SET_DIRECTORY
mount --make-slave $_SET_DIRECTORY
# Bind directories
@@ -1156,24 +1156,24 @@ unshare -Cfimpu $_UNSHARE_NETWORK --mount-proc --setgroups allow -- chroot $_SET
# Mount "/dev", "/proc", "/run", "/sys" and "/tmp" file systems
mountpoint -q /dev
- [ $? = 1 ] && mount -t tmpfs tmpfs \
+ [ $? != 0 ] && mount -t tmpfs tmpfs \
-o rw,nosuid,mode=755 \
/dev
mountpoint -q /proc
- [ $? = 1 ] && mount -t proc proc \
+ [ $? != 0 ] && mount -t proc proc \
-o rw,nosuid,nodev,noexec,relatime \
/proc
mountpoint -q /run
- [ $? = 1 ] && mount -t tmpfs tmpfs \
+ [ $? != 0 ] && mount -t tmpfs tmpfs \
-o rw,nosuid,nodev,mode=755 \
/run
mountpoint -q /sys
- [ $? = 1 ] && mount -t sysfs sysfs \
+ [ $? != 0 ] && mount -t sysfs sysfs \
-o ro,nosuid,nodev,noexec,relatime \
/sys
mountpoint -q /tmp
- [ $? = 1 ] && mount -t tmpfs tmpfs \
+ [ $? != 0 ] && mount -t tmpfs tmpfs \
-o rw \
/tmp
@@ -1225,43 +1225,43 @@ unshare -Cfimpu $_UNSHARE_NETWORK --mount-proc --setgroups allow -- chroot $_SET
# Mount needed file systems
# mountpoint -q /dev/console
-# [ $? = 1 ] && mount -t devpts devpts \
+# [ $? != 0 ] && mount -t devpts devpts \
# -o rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 \
# /dev/console
mountpoint -q /dev/pts
- [ $? = 1 ] && mount -t devpts devpts \
+ [ $? != 0 ] && mount -t devpts devpts \
-o rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666 \
/dev/pts
mountpoint -q /dev/shm
- [ $? = 1 ] && mount -t tmpfs tmpfs \
+ [ $? != 0 ] && mount -t tmpfs tmpfs \
-o rw,nosuid,nodev \
/dev/shm
# mountpoint -q /proc/kmsg
-# [ $? = 1 ] && mount -t tmpfs tmpfs \
+# [ $? != 0 ] && mount -t tmpfs tmpfs \
# -o rw,nosuid,nodev,mode=755 \
# /proc/kmsg
# mountpoint -q /proc/sys
-# [ $? = 1 ] && mount -t proc proc \
+# [ $? != 0 ] && mount -t proc proc \
# -o ro,nosuid,nodev,noexec,relatime \
# /proc/sys
# mountpoint -q /proc/sys/kernel/random/boot_id
-# [ $? = 1 ] && mount -t tmpfs tmpfs \
+# [ $? != 0 ] && mount -t tmpfs tmpfs \
# -o ro,nosuid,nodev,mode=755 \
# /proc/sys/kernel/random/boot_id
# mountpoint -q /proc/sys/kernel/random/boot_id
-# [ $? = 1 ] && mount -t tmpfs tmpfs \
+# [ $? != 0 ] && mount -t tmpfs tmpfs \
# -o rw,nosuid,nodev,mode=755 \
# /proc/sys/kernel/random/boot_id
# mountpoint -q /proc/sysrq-trigger
-# [ $? = 1 ] && mount -t proc proc \
+# [ $? != 0 ] && mount -t proc proc \
# -o ro,nosuid,nodev,noexec,relatime \
# /proc/sysrq-trigger
mountpoint -q /run/systemd/nspawn/incoming
- [ $? = 1 ] && mount -t tmpfs tmpfs \
+ [ $? != 0 ] && mount -t tmpfs tmpfs \
-o ro,relatime,mode=755 \
/run/systemd/nspawn/incoming
mountpoint -q /sys/fs/cgroup
- [ $? = 1 ] && mount -t tmpfs tmpfs \
+ [ $? != 0 ] && mount -t tmpfs tmpfs \
-o rw,nosuid,nodev,noexec,mode=755 \
/sys/fs/cgroup
@@ -1299,39 +1299,39 @@ unshare -Cfimpu $_UNSHARE_NETWORK --mount-proc --setgroups allow -- chroot $_SET
-o remount,ro \
/sys/fs/cgroup
mountpoint -q /sys/fs/cgroup/blkio
- [ $? = 1 ] && mount -t cgroup cgroup \
+ [ $? != 0 ] && mount -t cgroup cgroup \
-o ro,nosuid,nodev,noexec,relatime,blkio \
/sys/fs/cgroup/blkio
# mountpoint -q /sys/fs/cgroup/cpu,cpuacct
-# [ $? = 1 ] && mount -t cgroup cgroup \
+# [ $? != 0 ] && mount -t cgroup cgroup \
# -o ro,nosuid,nodev,noexec,relatime,cpu,cpuacct \
# /sys/fs/cgroup/cpu,cpuacct
mountpoint -q /sys/fs/cgroup/cpuset
- [ $? = 1 ] && mount -t cgroup cgroup \
+ [ $? != 0 ] && mount -t cgroup cgroup \
-o ro,nosuid,nodev,noexec,relatime,cpuset \
/sys/fs/cgroup/cpuset
mountpoint -q /sys/fs/cgroup/devices
- [ $? = 1 ] && mount -t cgroup cgroup \
+ [ $? != 0 ] && mount -t cgroup cgroup \
-o ro,nosuid,nodev,noexec,relatime,devices \
/sys/fs/cgroup/devices
mountpoint -q /sys/fs/cgroup/freezer
- [ $? = 1 ] && mount -t cgroup cgroup \
+ [ $? != 0 ] && mount -t cgroup cgroup \
-o ro,nosuid,nodev,noexec,relatime,freezer \
/sys/fs/cgroup/freezer
mountpoint -q /sys/fs/cgroup/memory
- [ $? = 1 ] && mount -t cgroup cgroup \
+ [ $? != 0 ] && mount -t cgroup cgroup \
-o ro,nosuid,nodev,noexec,relatime,memory \
/sys/fs/cgroup/memory
# mountpoint -q /sys/fs/cgroup/net_cls,net_prio
-# [ $? = 1 ] && mount -t cgroup cgroup \
+# [ $? != 0 ] && mount -t cgroup cgroup \
# -o ro,nosuid,nodev,noexec,relatime,net_cls,net_prio \
# /sys/fs/cgroup/net_cls,net_prio
mountpoint -q /sys/fs/cgroup/pids
- [ $? = 1 ] && mount -t cgroup cgroup \
+ [ $? != 0 ] && mount -t cgroup cgroup \
-o ro,nosuid,nodev,noexec,relatime,pids \
/sys/fs/cgroup/pids
# mountpoint -q /sys/fs/cgroup/systemd
-# [ $? = 1 ] && mount -t cgroup cgroup \
+# [ $? != 0 ] && mount -t cgroup cgroup \
# -o rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd \
# /sys/fs/cgroup/systemd
--
2.32.0
|