github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/.ci/containerd_devmapper_setup.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2021 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 set -o errexit 9 set -o nounset 10 set -o pipefail 11 12 KATA_HYPERVISOR="${KATA_HYPERVISOR:-qemu}" 13 14 containerd_config_dir="/etc/containerd" 15 containerd_config_file="${containerd_config_dir}/config.toml" 16 17 if [ "$KATA_HYPERVISOR" != "firecracker" ]; then 18 echo "WARNING: Devicemapper configuration is only for Firecracker. Exiting" 19 exit 0 20 fi 21 22 sudo rm -rf /var/lib/containerd/devmapper/data-disk.img 23 sudo rm -rf /var/lib/containerd/devmapper/meta-disk.img 24 sudo mkdir -p /var/lib/containerd/devmapper 25 sudo truncate --size 10G /var/lib/containerd/devmapper/data-disk.img 26 sudo truncate --size 10G /var/lib/containerd/devmapper/meta-disk.img 27 28 sudo mkdir -p /etc/systemd/system 29 30 cat<<EOT | sudo tee /etc/systemd/system/containerd-devmapper.service 31 [Unit] 32 Description=Setup containerd devmapper device 33 DefaultDependencies=no 34 After=systemd-udev-settle.service 35 Before=lvm2-activation-early.service 36 Wants=systemd-udev-settle.service 37 [Service] 38 Type=oneshot 39 RemainAfterExit=true 40 ExecStart=-/sbin/losetup /dev/loop20 /var/lib/containerd/devmapper/data-disk.img 41 ExecStart=-/sbin/losetup /dev/loop21 /var/lib/containerd/devmapper/meta-disk.img 42 [Install] 43 WantedBy=local-fs.target 44 EOT 45 46 sudo systemctl daemon-reload 47 sudo systemctl enable --now containerd-devmapper 48 49 # Time to setup the thin pool for consumption. 50 # The table arguments are such. 51 # start block in the virtual device 52 # length of the segment (block device size in bytes / Sector size (512) 53 # metadata device 54 # block data device 55 # data_block_size Currently set it 512 (128KB) 56 # low_water_mark. Copied this from containerd snapshotter test setup 57 # no. of feature arguments 58 # Skip zeroing blocks for new volumes. 59 sudo dmsetup create contd-thin-pool \ 60 --table "0 20971520 thin-pool /dev/loop21 /dev/loop20 512 32768 1 skip_block_zeroing" 61 62 sudo mkdir -p "$containerd_config_dir" 63 if [ -f "$containerd_config_file" ] 64 then 65 sudo sed -i 's|^\(\[plugins\]\).*|\1\n \[plugins.devmapper\]\n pool_name = \"contd-thin-pool\"\n base_image_size = \"4096MB\"|' "$containerd_config_file" 66 sudo sed -i 's|\(\[plugins.cri.containerd\]\).*|\1\n snapshotter = \"devmapper\"|' "$containerd_config_file" 67 else 68 cat<<EOT | sudo tee $containerd_config_file 69 [plugins] 70 [plugins.devmapper] 71 pool_name = "contd-thin-pool" 72 base_image_size = "4096MB" 73 [plugins.cri] 74 [plugins.cri.containerd] 75 snapshotter = "devmapper" 76 EOT 77 fi 78 79 sudo systemctl restart containerd