forked from kata-containers/tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
containerd_devmapper_setup.sh
executable file
·82 lines (70 loc) · 2.47 KB
/
containerd_devmapper_setup.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
#!/bin/bash
#
# Copyright (c) 2021 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
cidir=$(dirname "$0")
source "${cidir}/../lib/common.bash"
USE_DEVMAPPER="${USE_DEVMAPPER:-false}"
containerd_config_dir="/etc/containerd"
containerd_config_file="${containerd_config_dir}/config.toml"
if [ "$USE_DEVMAPPER" != "true" ]; then
echo "WARNING: Devicemapper configuration was not explicitly required. Exiting"
exit 0
fi
sudo rm -rf /var/lib/containerd/devmapper/data-disk.img
sudo rm -rf /var/lib/containerd/devmapper/meta-disk.img
sudo mkdir -p /var/lib/containerd/devmapper
sudo truncate --size 10G /var/lib/containerd/devmapper/data-disk.img
sudo truncate --size 10G /var/lib/containerd/devmapper/meta-disk.img
sudo mkdir -p /etc/systemd/system
cat<<EOF | sudo tee /etc/systemd/system/containerd-devmapper.service
[Unit]
Description=Setup containerd devmapper device
DefaultDependencies=no
After=systemd-udev-settle.service
Before=lvm2-activation-early.service
Wants=systemd-udev-settle.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=-/sbin/losetup /dev/loop20 /var/lib/containerd/devmapper/data-disk.img
ExecStart=-/sbin/losetup /dev/loop21 /var/lib/containerd/devmapper/meta-disk.img
[Install]
WantedBy=local-fs.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now containerd-devmapper
# Time to setup the thin pool for consumption.
# The table arguments are such.
# start block in the virtual device
# length of the segment (block device size in bytes / Sector size (512)
# metadata device
# block data device
# data_block_size Currently set it 512 (128KB)
# low_water_mark. Copied this from containerd snapshotter test setup
# no. of feature arguments
# Skip zeroing blocks for new volumes.
sudo dmsetup create contd-thin-pool \
--table "0 20971520 thin-pool /dev/loop21 /dev/loop20 512 32768 1 skip_block_zeroing"
sudo mkdir -p "$containerd_config_dir"
if [ -f "$containerd_config_file" ]
then
sudo sed -i 's|^\(\[plugins\]\).*|\1\n \[plugins.devmapper\]\n pool_name = \"contd-thin-pool\"\n base_image_size = \"4096MB\"|' "$containerd_config_file"
sudo sed -i 's|\(\[plugins.cri.containerd\]\).*|\1\n snapshotter = \"devmapper\"|' "$containerd_config_file"
else
cat<<EOF | sudo tee $containerd_config_file
[plugins]
[plugins.devmapper]
pool_name = "contd-thin-pool"
base_image_size = "4096MB"
[plugins.cri]
[plugins.cri.containerd]
snapshotter = "devmapper"
EOF
fi
restart_containerd_service