xref: /freebsd/sys/contrib/openzfs/.github/workflows/scripts/qemu-1-setup.sh (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
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# /etc/ksmtuned.conf - Configuration file for ksmtuned
22# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/virtualization_tuning_and_optimization_guide/chap-ksm
23KSM_MONITOR_INTERVAL=60
24
25# Millisecond sleep between ksm scans for 16Gb server.
26# Smaller servers sleep more, bigger sleep less.
27KSM_SLEEP_MSEC=30
28
29KSM_NPAGES_BOOST=0
30KSM_NPAGES_DECAY=0
31KSM_NPAGES_MIN=1000
32KSM_NPAGES_MAX=25000
33
34KSM_THRES_COEF=80
35KSM_THRES_CONST=8192
36
37LOGFILE=/var/log/ksmtuned.log
38DEBUG=1
39EOF
40sudo systemctl restart ksm
41sudo systemctl restart ksmtuned
42
43# not needed
44sudo systemctl stop docker.socket
45sudo systemctl stop multipathd.socket
46
47# remove default swapfile and /mnt
48sudo swapoff -a
49sudo umount -l /mnt
50DISK="/dev/disk/cloud/azure_resource-part1"
51sudo sed -e "s|^$DISK.*||g" -i /etc/fstab
52sudo wipefs -aq $DISK
53sudo systemctl daemon-reload
54
55sudo modprobe loop
56sudo modprobe zfs
57
58# partition the disk as needed
59DISK="/dev/disk/cloud/azure_resource"
60sudo sgdisk --zap-all $DISK
61sudo sgdisk -p \
62 -n 1:0:+16G -c 1:"swap" \
63 -n 2:0:0    -c 2:"tests" \
64$DISK
65sync
66sleep 1
67
68# swap with same size as RAM
69sudo mkswap $DISK-part1
70sudo swapon $DISK-part1
71
72# 60GB data disk
73SSD1="$DISK-part2"
74
75# 10GB data disk on ext4
76sudo fallocate -l 10G /test.ssd1
77SSD2=$(sudo losetup -b 4096 -f /test.ssd1 --show)
78
79# adjust zfs module parameter and create pool
80exec 1>/dev/null
81ARC_MIN=$((1024*1024*256))
82ARC_MAX=$((1024*1024*512))
83echo $ARC_MIN | sudo tee /sys/module/zfs/parameters/zfs_arc_min
84echo $ARC_MAX | sudo tee /sys/module/zfs/parameters/zfs_arc_max
85echo 1 | sudo tee /sys/module/zfs/parameters/zvol_use_blk_mq
86sudo zpool create -f -o ashift=12 zpool $SSD1 $SSD2 \
87  -O relatime=off -O atime=off -O xattr=sa -O compression=lz4 \
88  -O mountpoint=/mnt/tests
89
90# no need for some scheduler
91for i in /sys/block/s*/queue/scheduler; do
92  echo "none" | sudo tee $i > /dev/null
93done
94