summaryrefslogtreecommitdiff
path: root/root_image
diff options
context:
space:
mode:
Diffstat (limited to 'root_image')
-rwxr-xr-xroot_image179
1 files changed, 87 insertions, 92 deletions
diff --git a/root_image b/root_image
index 7e393cf..992b1dc 100755
--- a/root_image
+++ b/root_image
@@ -3,8 +3,6 @@
# Create a VM image suitable for running automated tests
# Output: vm_image
-# Dec 2019: requires additional validation via https://github.com/koalaman/shellcheck
-
set -o nounset
set -o errexit
set -o errtrace
@@ -12,9 +10,9 @@ set -o errtrace
ktest_dir=$(dirname "$(readlink -f "$0")")
debootstrap=$ktest_dir/debootstrap/debootstrap
-source "$ktest_dir/lib/util.sh" || exit 1
+. "$ktest_dir/lib/util.sh"
-if [[ $(id -u) != 0 ]]; then
+if [[ $(id -u) != 0 ]] ; then
echo this script must be run as root
exit 1
fi
@@ -23,9 +21,10 @@ checkdep fallocate util-linux
checkdep mkfs.ext4 e2fsprogs
IMAGE_SIZE="4G"
-MIRROR=http://cdn-fastly.deb.debian.org/debian
+MIRROR=http://ftp.us.debian.org/debian/
-usage() {
+usage()
+{
echo "root_image: create/update virtual machine root images for ktest"
echo "Usage: root_image cmd [options]"
echo " create Create a new image"
@@ -35,10 +34,10 @@ usage() {
echo " -h Display this help and exit"
echo " -a <arch> Architecture for vm image"
echo " -m <mirror> Debian mirror"
- echo " -i <image> Image to create/update, defaults to /var/lib/ktest/root.arch"
+ echo ' -i <image> Image to create/update, defaults to /var/lib/ktest/root.$arch'
}
-if [[ $# == 0 ]]; then
+if [[ $# = 0 ]]; then
usage
exit 1
fi
@@ -49,22 +48,22 @@ shift
while getopts "ha:m:i:" arg; do
case $arg in
- h)
- usage
- exit 0
- ;;
- a)
- ktest_arch=$OPTARG
- ;;
- m)
- MIRROR=$OPTARG
- ;;
- i)
- ktest_image=$OPTARG
- ;;
+ h)
+ usage
+ exit 0
+ ;;
+ a)
+ ktest_arch=$OPTARG
+ ;;
+ m)
+ MIRROR=$OPTARG
+ ;;
+ i)
+ ktest_image=$OPTARG
+ ;;
esac
done
-shift $((OPTIND - 1))
+shift $(( OPTIND - 1 ))
parse_arch "$ktest_arch"
@@ -72,24 +71,20 @@ parse_arch "$ktest_arch"
mkdir -p "$(dirname "$ktest_image")"
-PACKAGES=(kexec-tools less psmisc openssh-server
- build-essential make gcc g++
- autoconf automake pkg-config libtool-bin
- gdb strace ltrace linux-perf blktrace sysstat
- hdparm btrfs-progs mdadm lvm2 aoetools vblade
+PACKAGES=(kexec-tools less psmisc openssh-server \
+ build-essential make gcc g++ \
+ autoconf automake pkg-config libtool-bin \
+ gdb strace ltrace linux-perf blktrace sysstat \
+ hdparm btrfs-progs mdadm lvm2 aoetools vblade \
bc attr gawk acl rsync)
# stress testing:
PACKAGES+=(fio dbench bonnie++ fsmark)
-# FUSE:
-PACKAGES+=(libfuse3-3 libfuse3-dev libpcre2-32-0 libpcre2-dev libpcre2-posix0)
-PACKAGES+=(libselinux1-dev libsepol1-dev fuse3)
-
# bcachefs-tools build dependencies:
PACKAGES+=(libblkid-dev uuid-dev libscrypt-dev libsodium-dev)
PACKAGES+=(libkeyutils-dev liburcu-dev zlib1g-dev libattr1-dev)
-PACKAGES+=(libaio-dev libzstd-dev liblz4-dev valgrind)
+PACKAGES+=(libaio-dev libzstd-dev liblz4-dev libfuse3-dev valgrind)
# xfstests:
PACKAGES+=(xfsprogs xfslibs-dev quota libcap2-bin)
@@ -106,31 +101,31 @@ PACKAGES+=(cryptsetup)
PACKAGES+=(multipath-tools sg3-utils srptools)
# suspend testing:
-[[ $KERNEL_ARCH == x86 ]] && PACKAGES+=(uswsusp)
+[[ $KERNEL_ARCH = x86 ]] && PACKAGES+=(uswsusp)
-EXCLUDE=(dmidecode nano rsyslog logrotate cron
- iptables nfacct
+EXCLUDE=(dmidecode nano rsyslog logrotate cron \
+ iptables nfacct \
debconf-i18n info gnupg libpam-systemd)
-SYSTEMD_MASK=(dev-hvc0.device
- getty.target
- getty-static.service
- avahi-daemon.service
- crond.service
- kdump.service
- hdparm.service
- cdrom.mount
- mdadm-raid.service
- lvm2-activation-early.service
- aoetools.service
- sysstat.service
- kexec-load.service
- kexec.service
- systemd-ask-password-console.path
- systemd-ask-password-wall.path
- systemd-update-utmp-runlevel.service
- systemd-update-utmp.service
- time-sync.target
+SYSTEMD_MASK=(dev-hvc0.device \
+ getty.target \
+ getty-static.service \
+ avahi-daemon.service \
+ crond.service \
+ kdump.service \
+ hdparm.service \
+ cdrom.mount \
+ mdadm-raid.service \
+ lvm2-activation-early.service \
+ aoetools.service \
+ sysstat.service \
+ kexec-load.service \
+ kexec.service \
+ systemd-ask-password-console.path \
+ systemd-ask-password-wall.path \
+ systemd-update-utmp-runlevel.service \
+ systemd-update-utmp.service \
+ time-sync.target \
multipathd.service)
export DEBIAN_FRONTEND=noninteractive
@@ -139,11 +134,13 @@ export LC_ALL=C
export LANGUAGE=C
export LANG=C
-_chroot() {
+_chroot()
+{
PATH=/usr/sbin:/usr/bin:/sbin:/bin chroot "$@"
}
-update_files() {
+update_files()
+{
install -m0644 "$ktest_dir/lib/fstab" "$MNT/etc/fstab"
install -m0755 "$ktest_dir/lib/rc.local" "$MNT/etc/rc.local"
@@ -165,19 +162,16 @@ update_files() {
#_chroot "$MNT" systemctl mask "${SYSTEMD_MASK[@]}"
for i in "${SYSTEMD_MASK[@]}"; do
- (
- cd "$MNT/etc/systemd/system"
- ln -sf /dev/null "$i"
- )
+ (cd "$MNT/etc/systemd/system"; ln -sf /dev/null "$i")
done
- cat >"$MNT/etc/systemd/journald.conf" <<-ZZ
+ cat > "$MNT/etc/systemd/journald.conf" <<-ZZ
[Journal]
Storage=none
ZZ
mkdir -p "$MNT/etc/network"
- cat >"$MNT/etc/network/interfaces" <<-ZZ
+ cat > "$MNT/etc/network/interfaces" <<-ZZ
auto lo
iface lo inet loopback
@@ -196,40 +190,44 @@ ZZ
rm -f "$MNT/lib/udev/rules.d/*btrfs*"
rm -f "$MNT/lib/udev/rules.d/*hdparm*"
- echo "$(hostname)"-kvm >"$MNT/etc/hostname"
+ echo $(hostname)-kvm >"$MNT/etc/hostname"
}
-update_packages() {
+update_packages()
+{
_chroot "$MNT" apt update
_chroot "$MNT" apt upgrade -y
_chroot "$MNT" apt install -y "${PACKAGES[@]}"
rm -f "$MNT/var/cache/apt/archives/*.deb"
}
-trim_image() {
+trim_image()
+{
e2fsck -f "$ktest_image"
- resize2fs -M "$ktest_image" # shrinks the file
- resize2fs "$ktest_image" "$IMAGE_SIZE" # re-grows as sparse
+ resize2fs -M "$ktest_image" # shrinks the file
+ resize2fs "$ktest_image" "$IMAGE_SIZE" # re-grows as sparse
}
-umount_image() {
+umount_image()
+{
# Unmount everything under $MNT
- awk '{print $2}' /proc/mounts |
- grep "^$MNT" |
- sort -r |
- xargs umount
+ awk '{print $2}' /proc/mounts|
+ grep "^$MNT"|
+ sort -r|
+ xargs umount
rmdir "$MNT"
trap '' EXIT
}
-cmd_update() {
+cmd_update()
+{
if [[ ! -e $ktest_image ]]; then
- echo "$ktest_image does not exist"
- exit 1
+ echo "$ktest_image does not exist"
+ exit 1
fi
- MNT=$(mktemp --tmpdir -d "$(basename "$0")"-XXXXXXXXXX)
+ MNT=$(mktemp --tmpdir -d $(basename "$0")-XXXXXXXXXX)
trap 'umount_image' EXIT
mount "$ktest_image" "$MNT"
@@ -241,32 +239,29 @@ cmd_update() {
trim_image
}
-cmd_create() {
+cmd_create()
+{
if [[ -e $ktest_image ]]; then
- echo "$ktest_image already exists"
- exit 1
+ echo "$ktest_image already exists"
+ exit 1
fi
- (
- cd "$ktest_dir"
- rm -fr debootstrap
- git clone https://salsa.debian.org/installer-team/debootstrap.git
- )
+ (cd "$ktest_dir"; git submodule update --init debootstrap)
- MNT=$(mktemp --tmpdir -d "$(basename "$0")"-XXXXXXXXXX)
+ MNT=$(mktemp --tmpdir -d $(basename "$0")-XXXXXXXXXX)
trap 'umount_image; rm "$ktest_image"' EXIT
fallocate -l "$IMAGE_SIZE" "$ktest_image"
mkfs.ext4 -F "$ktest_image"
mount "$ktest_image" "$MNT"
- DEBOOTSTRAP_DIR=$ktest_dir/debootstrap $debootstrap \
- --no-check-gpg \
- --arch="$DEBIAN_ARCH" \
- --include="$(join_by , "${PACKAGES[@]}")" \
- --exclude="$(join_by , "${EXCLUDE[@]}")" \
- --foreign \
- buster "$MNT" "$MIRROR"
+ DEBOOTSTRAP_DIR=$ktest_dir/debootstrap $debootstrap \
+ --no-check-gpg \
+ --arch="$DEBIAN_ARCH" \
+ --include=$(join_by , "${PACKAGES[@]}") \
+ --exclude=$(join_by , "${EXCLUDE[@]}") \
+ --foreign \
+ sid "$MNT" "$MIRROR"
update_files