-
Notifications
You must be signed in to change notification settings - Fork 151
/
overlayfs-multi-lower.sh
executable file
·66 lines (64 loc) · 1.44 KB
/
overlayfs-multi-lower.sh
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
#!/usr/bin/env bash
# Multiple lowers works fine, but not uppers are more limited: overlayfs-multi-upper.sh.
#
# - https://stackoverflow.com/questions/31044982/how-to-use-multiple-lower-layers-in-overlayfs
# - https://unix.stackexchange.com/questions/341138/can-overlayfs-support-more-than-two-layers
# - https://askubuntu.com/questions/143176/overlayfs-reload-with-multiple-layers-migration-away-from-aufs
set -eux
top=overlayfs-multi-lower.tmp
rm -rf "$top"
mkdir -p "$top"
cd "$top"
dd if=/dev/zero of=lower1.ext4 bs=1024 count=102400
mkfs -t ext4 lower1.ext4
cp lower1.ext4 lower2.ext4
cp lower1.ext4 lower3.ext4
cp lower1.ext4 upper.ext4
mkdir \
lower1 \
lower2 \
lower3 \
upper \
overlay \
;
sudo mount lower1.ext4 lower1
sudo mount lower2.ext4 lower2
sudo mount lower3.ext4 lower3
sudo mount upper.ext4 upper
sudo chown "$USER:$USER" \
lower1 \
lower2 \
lower3 \
upper \
;
mkdir \
upper/upper \
upper/work \
;
printf 'lower-content-1' > lower1/lower-file-1
printf 'lower-content-2' > lower2/lower-file-2
printf 'lower-content-3' > lower3/lower-file-3
printf 'upper-content' > upper/upper/upper-file
sudo mount \
-t overlay \
-o lowerdir=lower1:lower2:lower3,upperdir=upper/upper,workdir=upper/work \
none \
overlay \
;
ls \
lower1 \
lower2 \
lower3 \
upper/upper \
upper/work \
overlay \
;
sudo umount overlay
ls \
lower1 \
lower2 \
lower3 \
upper/upper \
upper/work \
;
sudo umount upper lower3 lower2 lower1