-
Notifications
You must be signed in to change notification settings - Fork 151
/
overlayfs-multi-upper.sh
executable file
·102 lines (100 loc) · 2.1 KB
/
overlayfs-multi-upper.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
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
#!/usr/bin/env bash
# On Ubuntu 18.04, Linux kernel 18.04, if you run as:
#
# ./overlayfs-multi-upper.sh 1
#
# then the third mount fails with:
#
# wrong fs type, bad option, bad superblock on none, missing codepage or helper program, or other error.
#
# and dmesg contains:
#
# overlayfs: maximum fs stacking depth exceeded
#
# The kernel cannot handle more than 2 overlayfs in daisy chain.
#
# Layer 2 works normally however.
set -eux
if [ $# -gt 0 ]; then
layer3=true
else
layer3=false
fi
top=overlayfs-multi-upper.tmp
rm -rf "$top"
mkdir -p "$top"
cd "$top"
dd if=/dev/zero of=lower.ext4 bs=1024 count=102400
mkfs -t ext4 lower.ext4
cp lower.ext4 upper1.ext4
cp lower.ext4 upper2.ext4
cp lower.ext4 upper3.ext4
sudo mount lower.ext4 lower
sudo mount upper1.ext4 upper1
sudo mount upper2.ext4 upper2
sudo mount upper3.ext4 upper3
sudo chown "$USER:$USER" \
lower \
upper1 \
upper2 \
upper3 \
;
mkdir \
upper1/upper1 \
upper1/work1 \
upper2/upper2 \
upper2/work2 \
upper3/upper3 \
upper3/work3 \
;
printf 'lower-content' > lower/lower-file
printf 'upper-content-1' > upper1/upper1/upper-file-1
printf 'upper-content-2' > upper2/upper2/upper-file-2
printf 'upper-content-3' > upper3/upper3/upper-file-3
sudo mount \
-t overlay \
-o lowerdir=lower,upperdir=upper1/upper1,workdir=upper1/work1 \
none \
overlay1 \
;
sudo mount \
-t overlay \
-o lowerdir=overlay1,upperdir=upper2/upper2,workdir=upper2/work2 \
none \
overlay2 \
;
if "$layer3"; then
sudo mount \
-t overlay \
-o lowerdir=overlay2,upperdir=upper3/upper3,workdir=upper3/work3 \
none \
overlay3 \
;
fi
printf 'overlay-content' > overlay1/overlay-file-1
printf 'overlay-content' > overlay2/overlay-file-2
printf 'overlay-content' > overlay3/overlay-file-3
ls \
lower \
upper1/upper1 \
upper1/work1 \
upper2/upper2 \
upper2/work2 \
overlay1 \
overlay2 \
overlay3 \
;
if "$layer3"; then
sudo umount overlay3
fi
sudo umount overlay2 overlay1
ls \
lower \
upper1/upper1 \
upper1/work1 \
upper2/upper2 \
upper2/work2 \
upper3/upper3 \
upper3/work3 \
;
sudo umount upper3 upper2 upper1 lower