xref: /freebsd/sys/contrib/openzfs/.github/workflows/scripts/qemu-1-setup.sh (revision 96190b4fef3b4a0cc3ca0606b0c4e3e69a5e6717)
1#!/usr/bin/env bash
2
3######################################################################
4# 1) setup qemu instance on action runner
5######################################################################
6
7set -eu
8
9# install needed packages
10export DEBIAN_FRONTEND="noninteractive"
11sudo apt-get -y update
12sudo apt-get install -y axel cloud-image-utils daemonize guestfs-tools \
13  ksmtuned virt-manager linux-modules-extra-$(uname -r) zfsutils-linux
14
15# generate ssh keys
16rm -f ~/.ssh/id_ed25519
17ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -q -N ""
18
19# we expect RAM shortage
20cat << EOF | sudo tee /etc/ksmtuned.conf > /dev/null
21# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/virtualization_tuning_and_optimization_guide/chap-ksm
22KSM_MONITOR_INTERVAL=60
23
24# Millisecond sleep between ksm scans for 16Gb server.
25# Smaller servers sleep more, bigger sleep less.
26KSM_SLEEP_MSEC=10
27KSM_NPAGES_BOOST=300
28KSM_NPAGES_DECAY=-50
29KSM_NPAGES_MIN=64
30KSM_NPAGES_MAX=2048
31
32KSM_THRES_COEF=25
33KSM_THRES_CONST=2048
34
35LOGFILE=/var/log/ksmtuned.log
36DEBUG=1
37EOF
38sudo systemctl restart ksm
39sudo systemctl restart ksmtuned
40
41# not needed
42sudo systemctl stop docker.socket
43sudo systemctl stop multipathd.socket
44
45# remove default swapfile and /mnt
46sudo swapoff -a
47sudo umount -l /mnt
48DISK="/dev/disk/cloud/azure_resource-part1"
49sudo sed -e "s|^$DISK.*||g" -i /etc/fstab
50sudo wipefs -aq $DISK
51sudo systemctl daemon-reload
52
53sudo modprobe loop
54sudo modprobe zfs
55
56# partition the disk as needed
57DISK="/dev/disk/cloud/azure_resource"
58sudo sgdisk --zap-all $DISK
59sudo sgdisk -p \
60 -n 1:0:+16G -c 1:"swap" \
61 -n 2:0:0    -c 2:"tests" \
62$DISK
63sync
64sleep 1
65
66# swap with same size as RAM
67sudo mkswap $DISK-part1
68sudo swapon $DISK-part1
69
70# 60GB data disk
71SSD1="$DISK-part2"
72
73# 10GB data disk on ext4
74sudo fallocate -l 10G /test.ssd1
75SSD2=$(sudo losetup -b 4096 -f /test.ssd1 --show)
76
77# adjust zfs module parameter and create pool
78exec 1>/dev/null
79ARC_MIN=$((1024*1024*256))
80ARC_MAX=$((1024*1024*512))
81echo $ARC_MIN | sudo tee /sys/module/zfs/parameters/zfs_arc_min
82echo $ARC_MAX | sudo tee /sys/module/zfs/parameters/zfs_arc_max
83echo 1 | sudo tee /sys/module/zfs/parameters/zvol_use_blk_mq
84sudo zpool create -f -o ashift=12 zpool $SSD1 $SSD2 \
85  -O relatime=off -O atime=off -O xattr=sa -O compression=lz4 \
86  -O mountpoint=/mnt/tests
87
88# no need for some scheduler
89for i in /sys/block/s*/queue/scheduler; do
90  echo "none" | sudo tee $i > /dev/null
91done
92