-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmount_stuff_into_chroot
More file actions
executable file
·55 lines (47 loc) · 1.23 KB
/
mount_stuff_into_chroot
File metadata and controls
executable file
·55 lines (47 loc) · 1.23 KB
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
#!/bin/bash
help() {
echo 'usage: mount_stuff_into_chroot [--umount] path_to_chroot'
echo ' mount_stuff_into_chroot --help'
echo
echo ' Mounts /proc /sys and /dev into chroot'
echo ' and makes sure /tmp is correctly set up.'
echo
echo ' With --umount: umounts all those filesystems'
echo ' again, that were previously mounted into'
echo ' the chroot.'
echo
exit 1
}
[ "$1" == "--help" ] && help
if [ "$1" == "--umount" ]; then
MOUNT_OR_UMOUNT=umount
shift
else
MOUNT_OR_UMOUNT=mount
fi
if [ "$1" == "" ]; then
echo "ABORTING: chroot path not given" >&2
exit 1
else
CHROOT="$1"
fi
set -e # stop on error
set -u # stop on undefined variable
set -o pipefail # stop part of pipeline failing
if [ "$MOUNT_OR_UMOUNT" == "mount" ]; then
for fs in proc sys dev tmp; do
if [ ! -d "${CHROOT}/${fs}/" ]; then
sudo mkdir "${CHROOT}/${fs}/"
fi
done
sudo mount -t proc /proc "${CHROOT}/proc/"
sudo mount -t sysfs /sys "${CHROOT}/sys/"
sudo mount --bind /dev "${CHROOT}/dev/"
# /tmp
chmod ugo+rwx "${CHROOT}/tmp/"
chmod +t "${CHROOT}/tmp/"
else
sudo umount -l "${CHROOT}/dev/"
sudo umount "${CHROOT}/sys/"
sudo umount "${CHROOT}/proc/"
fi