From b5520a3ef7032918fdc73a91f48c0aa58b34e43b Mon Sep 17 00:00:00 2001 From: Jeevitha Kannan K S Date: Sun, 13 Oct 2024 09:51:39 +0530 Subject: [PATCH 1/6] Add Arch virtualization setup script --- core/tabs/system-setup/arch/virtualization.sh | 106 ++++++++++++++++++ core/tabs/system-setup/tab_data.toml | 6 + docs/userguide.md | 1 + 3 files changed, 113 insertions(+) create mode 100755 core/tabs/system-setup/arch/virtualization.sh diff --git a/core/tabs/system-setup/arch/virtualization.sh b/core/tabs/system-setup/arch/virtualization.sh new file mode 100755 index 00000000..49757b2e --- /dev/null +++ b/core/tabs/system-setup/arch/virtualization.sh @@ -0,0 +1,106 @@ +#!/bin/sh -e + +. ../../common-script.sh + +installQEMUDesktop() { + if ! command_exists qemu-img; then + printf "%b\n" "${YELLOW}Installing QEMU.${RC}" + "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm qemu-desktop + else + printf "%b\n" "${GREEN}QEMU is already installed.${RC}" + fi + checkKVM +} + +installQEMUEmulators() { + if ! pacman -Q | grep -q "qemu-emulators-full "; then + printf "%b\n" "${YELLOW}Installing QEMU-Emulators.${RC}" + "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm qemu-emulators-full swtpm + else + printf "%b\n" "${GREEN}QEMU-Emulators already installed.${RC}" + fi +} + +installVirtManager() { + if ! command_exists virt-manager; then + printf "%b\n" "${YELLOW}Installing Virt-Manager.${RC}" + "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm virt-manager + else + printf "%b\n" "${GREEN}Virt-Manager already installed.${RC}" + fi +} + +checkKVM() { + hardware_avail="$(grep -E 'vmx|svm|0xc0f' /proc/cpuinfo)" + kernel_avail="$(zgrep CONFIG_KVM= /proc/config.gz | cut -d '=' -f 2)" + modules_avail="$(lsmod | grep kvm)" + if [ -z "$hardware_avail" ] || [ -z "$modules_avail" ] || { [ "$kernel_avail" != "m" ] && [ "$kernel_avail" != "y" ]; }; then + printf "%b\n" "${RED}KVM is not avaiable please refer https://wiki.archlinux.org/title/KVM for more information.${RC}" + else + "$ESCALATION_TOOL" usermod "$USER" -aG kvm + fi +} + +setupLibvirt() { + printf "%b\n" "${YELLOW}Configuring Libvirt.${RC}" + if pacman -Q | grep -q "iptables "; then + "$ESCALATION_TOOL" "$PACKAGER" -Rdd --noconfirm iptables + fi + + "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm dnsmasq iptables-nft + "$ESCALATION_TOOL" sed -i 's/^#\?firewall_backend\s*=\s*".*"/firewall_backend = "iptables"/' "/etc/libvirt/network.conf" + + if systemctl is-active --quiet polkit; then + "$ESCALATION_TOOL" sed -i 's/^#\?auth_unix_ro\s*=\s*".*"/auth_unix_ro = "polkit"/' "/etc/libvirt/libvirtd.conf" + "$ESCALATION_TOOL" sed -i 's/^#\?auth_unix_rw\s*=\s*".*"/auth_unix_rw = "polkit"/' "/etc/libvirt/libvirtd.conf" + fi + + "$ESCALATION_TOOL" usermod "$USER" -aG libvirt + + for value in libvirt libvirt_guest; do + if ! grep -wq "$value" /etc/nsswitch.conf;then + "$ESCALATION_TOOL" sed -i "/^hosts:/ s/$/ ${value}/" /etc/nsswitch.conf + fi + done + + "$ESCALATION_TOOL" systemctl enable --now libvirtd.service + "$ESCALATION_TOOL" virsh net-autostart default + + checkKVM +} + +installLibvirt() { + if ! command_exists libvirtd; then + "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm libvirt dmidecode + else + printf "%b\n" "${GREEN}Libvirt is already installed.${RC}" + fi + setupLibvirt +} + +main() { + printf "%b\n" "${YELLOW}Choose what to install:${RC}" + printf "%b\n" "1. ${YELLOW}QEMU${RC}" + printf "%b\n" "2. ${YELLOW}QEMU-Emulators ( Extended architectures )${RC}" + printf "%b\n" "3. ${YELLOW}Libvirt${RC}" + printf "%b\n" "4. ${YELLOW}Virtual-Manager${RC}" + printf "%b\n" "5. ${YELLOW}All${RC}" + printf "%b" "Enter your choice [1-5]: " + read -r CHOICE + case "$CHOICE" in + 1) installQEMUDesktop ;; + 2) installQEMUEmulators ;; + 3) installLibvirt ;; + 4) installVirtManager ;; + 5) installQEMUDesktop + installQEMUEmulators + installLibvirt + installVirtManager + ;; + *) printf "%b\n" "${RED}Invalid choice.${RC}" && exit 1 ;; + esac +} + +checkEnv +checkEscalationTool +main \ No newline at end of file diff --git a/core/tabs/system-setup/tab_data.toml b/core/tabs/system-setup/tab_data.toml index 080c06d9..8d49c00e 100644 --- a/core/tabs/system-setup/tab_data.toml +++ b/core/tabs/system-setup/tab_data.toml @@ -21,6 +21,12 @@ description = "Paru is your standard pacman wrapping AUR helper with lots of fea script = "arch/paru-setup.sh" task_list = "I" +[[data.entries]] +name = "Virtualization" +description = "QEMU, Libvirt, Virt-Manager installation and configuration." +script = "arch/virtualization.sh" +task_list = "FM I SS RP" + [[data.entries]] name = "Yay AUR Helper" description = "Yet Another Yogurt - An AUR Helper Written in Go.\nTo know more about AUR helpers visit: https://wiki.archlinux.org/title/AUR_helpers" diff --git a/docs/userguide.md b/docs/userguide.md index 2b7ad82b..c15000ff 100644 --- a/docs/userguide.md +++ b/docs/userguide.md @@ -103,6 +103,7 @@ For more information visit: https://christitus.com/linux-security-mistakes - **Arch Server Setup**: This command installs a minimal arch server setup under 5 minutes. - **Paru AUR Helper**: Paru is your standard pacman wrapping AUR helper with lots of features and minimal interaction. To know more about AUR helpers visit: https://wiki.archlinux.org/title/AUR_helpers +- **Virtualization**: QEMU, Libvirt, Virt-Manager installation and configuration. - **Yay AUR Helper**: Yet Another Yogurt - An AUR Helper Written in Go. To know more about AUR helpers visit: https://wiki.archlinux.org/title/AUR_helpers From 9a4ed01e966678d87a35c26b5ce14a0c87eb96cd Mon Sep 17 00:00:00 2001 From: Jeevitha Kannan K S Date: Sun, 13 Oct 2024 10:02:11 +0530 Subject: [PATCH 2/6] Replace hardcoded pacman --- core/tabs/system-setup/arch/virtualization.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/tabs/system-setup/arch/virtualization.sh b/core/tabs/system-setup/arch/virtualization.sh index 49757b2e..1454aba1 100755 --- a/core/tabs/system-setup/arch/virtualization.sh +++ b/core/tabs/system-setup/arch/virtualization.sh @@ -13,7 +13,7 @@ installQEMUDesktop() { } installQEMUEmulators() { - if ! pacman -Q | grep -q "qemu-emulators-full "; then + if ! "$PACKAGER" -Q | grep -q "qemu-emulators-full "; then printf "%b\n" "${YELLOW}Installing QEMU-Emulators.${RC}" "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm qemu-emulators-full swtpm else @@ -43,7 +43,7 @@ checkKVM() { setupLibvirt() { printf "%b\n" "${YELLOW}Configuring Libvirt.${RC}" - if pacman -Q | grep -q "iptables "; then + if "$PACKAGER" -Q | grep -q "iptables "; then "$ESCALATION_TOOL" "$PACKAGER" -Rdd --noconfirm iptables fi From 1ee60ff5613d45a9106576c60a112e58ebeb378a Mon Sep 17 00:00:00 2001 From: JEEVITHA KANNAN K S Date: Sun, 13 Oct 2024 10:55:49 +0530 Subject: [PATCH 3/6] Update core/tabs/system-setup/arch/virtualization.sh Co-authored-by: Adam Perkowski --- core/tabs/system-setup/arch/virtualization.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tabs/system-setup/arch/virtualization.sh b/core/tabs/system-setup/arch/virtualization.sh index 1454aba1..0520ec10 100755 --- a/core/tabs/system-setup/arch/virtualization.sh +++ b/core/tabs/system-setup/arch/virtualization.sh @@ -35,7 +35,7 @@ checkKVM() { kernel_avail="$(zgrep CONFIG_KVM= /proc/config.gz | cut -d '=' -f 2)" modules_avail="$(lsmod | grep kvm)" if [ -z "$hardware_avail" ] || [ -z "$modules_avail" ] || { [ "$kernel_avail" != "m" ] && [ "$kernel_avail" != "y" ]; }; then - printf "%b\n" "${RED}KVM is not avaiable please refer https://wiki.archlinux.org/title/KVM for more information.${RC}" + printf "%b\n" "${RED}KVM is not available. Please refer https://wiki.archlinux.org/title/KVM for more information.${RC}" else "$ESCALATION_TOOL" usermod "$USER" -aG kvm fi From 8e400f726b73ebc0c9c0e70469d9d7a2622823b2 Mon Sep 17 00:00:00 2001 From: JEEVITHA KANNAN K S Date: Sun, 13 Oct 2024 19:44:22 +0530 Subject: [PATCH 4/6] Update virtualization.sh Co-authored-by: Adam Perkowski --- core/tabs/system-setup/arch/virtualization.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/tabs/system-setup/arch/virtualization.sh b/core/tabs/system-setup/arch/virtualization.sh index 0520ec10..78f33826 100755 --- a/core/tabs/system-setup/arch/virtualization.sh +++ b/core/tabs/system-setup/arch/virtualization.sh @@ -35,7 +35,7 @@ checkKVM() { kernel_avail="$(zgrep CONFIG_KVM= /proc/config.gz | cut -d '=' -f 2)" modules_avail="$(lsmod | grep kvm)" if [ -z "$hardware_avail" ] || [ -z "$modules_avail" ] || { [ "$kernel_avail" != "m" ] && [ "$kernel_avail" != "y" ]; }; then - printf "%b\n" "${RED}KVM is not available. Please refer https://wiki.archlinux.org/title/KVM for more information.${RC}" + printf "%b\n" "${RED}KVM is not available. Make sure you have CPU virtualization support enabled in your BIOS/UEFI settings. Please refer https://wiki.archlinux.org/title/KVM for more information.${RC}" else "$ESCALATION_TOOL" usermod "$USER" -aG kvm fi @@ -103,4 +103,4 @@ main() { checkEnv checkEscalationTool -main \ No newline at end of file +main From 41ff081ee024fe749e338564ab23abd422a3bdc4 Mon Sep 17 00:00:00 2001 From: JEEVITHA KANNAN K S Date: Mon, 14 Oct 2024 22:49:16 +0530 Subject: [PATCH 5/6] Update core/tabs/system-setup/arch/virtualization.sh Co-authored-by: Liam <33645555+lj3954@users.noreply.github.com> --- core/tabs/system-setup/arch/virtualization.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/tabs/system-setup/arch/virtualization.sh b/core/tabs/system-setup/arch/virtualization.sh index 78f33826..5dbe2af6 100755 --- a/core/tabs/system-setup/arch/virtualization.sh +++ b/core/tabs/system-setup/arch/virtualization.sh @@ -31,10 +31,7 @@ installVirtManager() { } checkKVM() { - hardware_avail="$(grep -E 'vmx|svm|0xc0f' /proc/cpuinfo)" - kernel_avail="$(zgrep CONFIG_KVM= /proc/config.gz | cut -d '=' -f 2)" - modules_avail="$(lsmod | grep kvm)" - if [ -z "$hardware_avail" ] || [ -z "$modules_avail" ] || { [ "$kernel_avail" != "m" ] && [ "$kernel_avail" != "y" ]; }; then + if [ ! -e "/dev/kvm" ]; then printf "%b\n" "${RED}KVM is not available. Make sure you have CPU virtualization support enabled in your BIOS/UEFI settings. Please refer https://wiki.archlinux.org/title/KVM for more information.${RC}" else "$ESCALATION_TOOL" usermod "$USER" -aG kvm From 2891ccdd3a01780cfaa49838c065181bab245ed6 Mon Sep 17 00:00:00 2001 From: Jeevitha Kannan K S Date: Wed, 6 Nov 2024 22:03:42 +0530 Subject: [PATCH 6/6] chore: formatting --- core/tabs/system-setup/arch/virtualization.sh | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/tabs/system-setup/arch/virtualization.sh b/core/tabs/system-setup/arch/virtualization.sh index 5dbe2af6..e7543abc 100755 --- a/core/tabs/system-setup/arch/virtualization.sh +++ b/core/tabs/system-setup/arch/virtualization.sh @@ -55,7 +55,7 @@ setupLibvirt() { "$ESCALATION_TOOL" usermod "$USER" -aG libvirt for value in libvirt libvirt_guest; do - if ! grep -wq "$value" /etc/nsswitch.conf;then + if ! grep -wq "$value" /etc/nsswitch.conf; then "$ESCALATION_TOOL" sed -i "/^hosts:/ s/$/ ${value}/" /etc/nsswitch.conf fi done @@ -70,7 +70,7 @@ installLibvirt() { if ! command_exists libvirtd; then "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm libvirt dmidecode else - printf "%b\n" "${GREEN}Libvirt is already installed.${RC}" + printf "%b\n" "${GREEN}Libvirt is already installed.${RC}" fi setupLibvirt } @@ -85,16 +85,17 @@ main() { printf "%b" "Enter your choice [1-5]: " read -r CHOICE case "$CHOICE" in - 1) installQEMUDesktop ;; - 2) installQEMUEmulators ;; - 3) installLibvirt ;; - 4) installVirtManager ;; - 5) installQEMUDesktop - installQEMUEmulators - installLibvirt - installVirtManager + 1) installQEMUDesktop ;; + 2) installQEMUEmulators ;; + 3) installLibvirt ;; + 4) installVirtManager ;; + 5) + installQEMUDesktop + installQEMUEmulators + installLibvirt + installVirtManager ;; - *) printf "%b\n" "${RED}Invalid choice.${RC}" && exit 1 ;; + *) printf "%b\n" "${RED}Invalid choice.${RC}" && exit 1 ;; esac }