Debian Codegraph @

src/tests/lxc-test-rootfs

raw
1 #!/bin/bash
2
3 # SPDX-License-Identifier: LGPL-2.1+
4
5 # lxc: linux Container library
6
7 set -ex
8
9 cleanup() {
10 set +e
11 lxc-destroy -n lxc-test-rootfs -f
12 sed -i '/^root:910000:10000/d' /etc/subuid /etc/subgid
13 if [ $PHASE != "done" ]; then
14 echo "rootfs test failed at $PHASE"
15 exit 1
16 fi
17 echo "rootfs test passed"
18 exit 0
19 }
20
21 PHASE=setup
22 trap cleanup EXIT
23
24 lxc-destroy -n lxc-test-rootfs -f || true
25 lxc-create -t busybox -n lxc-test-rootfs
26
27 PHASE=ro_rootfs
28 echo "Starting phase $PHASE"
29 config=/var/lib/lxc/lxc-test-rootfs/config
30 sed -i '/lxc.rootfs.options/d' $config
31 echo "lxc.rootfs.options = ro" >> $config
32
33 lxc-start -n lxc-test-rootfs
34 pid=$(lxc-info -n lxc-test-rootfs -p -H)
35 ro=0
36 mkdir /proc/$pid/root/rotest || ro=1
37 [ $ro -ne 0 ]
38
39 lxc-stop -n lxc-test-rootfs -k
40 PHASE=rw_rootfs
41 echo "Starting phase $PHASE"
42 sed -i '/lxc.rootfs.options/d' $config
43 echo "lxc.rootfs.options = rw" >> $config
44 lxc-start -n lxc-test-rootfs
45 pid=$(lxc-info -n lxc-test-rootfs -p -H)
46 ro=0
47 mkdir /proc/$pid/root/rwtest || ro=1
48 [ $ro -ne 1 ]
49 rmdir /proc/$pid/root/rwtest
50 ro=0
51
52 lxc-stop -n lxc-test-rootfs -k
53 PHASE=idmapped_rootfs
54 echo "Starting phase $PHASE"
55 usermod -v 910000-919999 -w 910000-919999 root
56 sed -i '/lxc.rootfs.options/d' $config
57 echo "lxc.idmap = u 0 910000 9999" >> $config
58 echo "lxc.idmap = g 0 910000 9999" >> $config
59 echo "lxc.rootfs.options = idmap=container" >> $config
60 lxc-start -n lxc-test-rootfs
61 pid=$(lxc-info -n lxc-test-rootfs -p -H)
62 ro=0
63 lxc-attach -n lxc-test-rootfs -- mkdir /rwtest || ro=1
64 [ $ro -ne 1 ]
65 rmdir /proc/$pid/root/rwtest
66 ro=0
67
68 PHASE=done