wiki/gofurther/virt-install.md

212 lines
7.5 KiB
Markdown
Raw Normal View History

2021-11-12 15:27:42 +00:00
---
title: Linux family
description:
published: true
2021-11-26 21:24:20 +00:00
date: 2021-11-26T21:24:17.505Z
2021-11-12 15:27:42 +00:00
tags:
editor: markdown
dateCreated: 2021-11-12T15:27:40.366Z
---
2021-11-26 21:18:11 +00:00
# Use virt-install to deploy RPM-based Linux distributions automatically
2021-11-12 15:45:05 +00:00
2021-11-26 21:06:37 +00:00
`virt-install` is a command-line utility that can be used to create virtual machines. It comes preinstalled with Phyllome OS.
2021-11-12 15:45:05 +00:00
2021-11-26 21:06:37 +00:00
* For Fedora, you can install it using the following command as *root*:
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:06:37 +00:00
dnf install virt-install
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:06:37 +00:00
## Automated installation using an ISO file and a local kickstart file
2021-11-12 15:45:05 +00:00
2021-11-26 21:06:37 +00:00
* Use the following `wget` command to fetch the official Fedora Server ISO file and to put it in the current working directory
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:06:37 +00:00
wget https://download.fedoraproject.org/pub/fedora/linux/releases/35/Server/x86_64/iso/Fedora-Server-dvd-x86_64-35-1.2.iso
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:06:37 +00:00
> Please [verify your download](https://getfedora.org/en/security/) if you intent to use this virtual machine in production
{.is-info}
2021-11-12 15:45:05 +00:00
2021-11-26 21:06:37 +00:00
Move the file to `/var/lib/libvirt/iso`:
```
mv Fedora-Server-dvd-x86_64-35-1.2.iso /var/lib/libvirt/iso
```
* Use the following `wget` command to fetch a standalone kickstart file made to deploy a stripped down desktop based on GNOME Shell, and put it in the working directory
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:06:37 +00:00
wget https://raw.githubusercontent.com/PhyllomeOS/phyllomeos/main/leaves/virtual-desktop.cfg
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:06:37 +00:00
> Please verify the content of the script if you intent to use this virtual machine in production, for instance by using the following command `cat virtual-desktop.cfg`
{.is-info}
> If you use a custom kickstart script, make sure it does include the `cdrom` option.
2021-11-12 15:45:05 +00:00
{.is-warning}
* Deploy a UEFI-based machine with Fedora Server using the relative path of the local kickstart file
2021-11-26 21:17:46 +00:00
> Warning: doesn't work as intended. The kickstart file won't have to be modified to include the `cdrom` option and the ISO would have to include the necessary packages.
2021-11-26 21:12:11 +00:00
{.is-danger}
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:06:37 +00:00
virt-install \
--connect qemu:///session \
--os-variant detect=off \
2021-11-12 15:45:05 +00:00
--virt-type kvm \
--arch x86_64 \
--machine q35 \
2021-11-26 21:06:37 +00:00
--name virtual-desktop \
2021-11-12 15:45:05 +00:00
--boot uefi \
2021-11-26 21:06:37 +00:00
--cpu host-model,topology.sockets=1,topology.cores=2,topology.threads=1 \
--vcpus 2 \
--memory 4096 \
2021-11-12 15:45:05 +00:00
--video virtio \
2021-11-26 21:06:37 +00:00
--graphics spice,listen=none \
2021-11-12 15:45:05 +00:00
--channel spicevmc \
2021-11-26 21:06:37 +00:00
--channel unix,target.type=virtio,target.name=org.qemu.guest_agent.0 \
2021-11-12 15:45:05 +00:00
--autoconsole none \
2021-11-26 21:06:37 +00:00
--console pty,target.type=virtio \
2021-11-12 15:45:05 +00:00
--sound none \
2021-11-26 21:06:37 +00:00
--network type=user,model=virtio \
2021-11-12 15:45:05 +00:00
--controller type=virtio-serial \
--controller type=usb,model=none \
--controller type=scsi,model=virtio-scsi \
--input type=keyboard,bus=virtio \
--input type=tablet,bus=virtio \
--rng /dev/urandom,model=virtio \
2021-11-26 21:24:20 +00:00
--disk path=~/.local/share/libvirt/images/virtual-desktop.img,format=raw,bus=virtio,cache=writeback,size=10 \
2021-11-26 21:06:37 +00:00
--location=/var/lib/libvirt/iso/Fedora-Server-dvd-x86_64-35-1.2.iso \
--initrd-inject virtual-desktop.cfg --extra-args "inst.ks=file:/virtual-desktop.cfg"
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:07:28 +00:00
## Automated installation using a local kickstart file
2021-11-12 15:45:05 +00:00
2021-11-26 21:12:11 +00:00
* Use the following `wget` command to fetch a standalone kickstart file made to deploy a stripped down desktop based on GNOME Shell, and put it in the working directory
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:12:11 +00:00
wget https://raw.githubusercontent.com/PhyllomeOS/phyllomeos/main/leaves/virtual-desktop.cfg
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:12:11 +00:00
> Please verify the content of the script if you intent to use this virtual machine in production, for instance by using the following command `cat virtual-desktop.cfg`
{.is-info}
> If using a custom kickstart script, make sure it includes `repo` information
2021-11-12 15:45:05 +00:00
{.is-warning}
2021-11-26 21:12:18 +00:00
* Deploy a stripped down desktop based on GNOME Shell using a local kickstart file
2021-11-26 21:12:11 +00:00
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:12:11 +00:00
virt-install \
--connect qemu:///session \
--os-variant detect=off \
2021-11-12 15:45:05 +00:00
--virt-type kvm \
--arch x86_64 \
--machine q35 \
2021-11-26 21:12:11 +00:00
--name virtual-desktop \
2021-11-12 15:45:05 +00:00
--boot uefi \
2021-11-26 21:12:11 +00:00
--cpu host-model,topology.sockets=1,topology.cores=2,topology.threads=1 \
--vcpus 2 \
--memory 4096 \
2021-11-12 15:45:05 +00:00
--video virtio \
2021-11-26 21:12:11 +00:00
--graphics spice,listen=none \
2021-11-12 15:45:05 +00:00
--channel spicevmc \
2021-11-26 21:12:11 +00:00
--channel unix,target.type=virtio,target.name=org.qemu.guest_agent.0 \
2021-11-12 15:45:05 +00:00
--autoconsole none \
2021-11-26 21:12:11 +00:00
--console pty,target.type=virtio \
2021-11-12 15:45:05 +00:00
--sound none \
2021-11-26 21:12:11 +00:00
--network type=user,model=virtio \
2021-11-12 15:45:05 +00:00
--controller type=virtio-serial \
--controller type=usb,model=none \
--controller type=scsi,model=virtio-scsi \
--input type=keyboard,bus=virtio \
--input type=tablet,bus=virtio \
--rng /dev/urandom,model=virtio \
2021-11-26 21:24:20 +00:00
--disk path=~/.local/share/libvirt/images/virtual-desktop.img,format=raw,bus=virtio,cache=writeback,size=10 \
2021-11-26 21:12:11 +00:00
--location=https://download.fedoraproject.org/pub/fedora/linux/releases/35/Everything/x86_64/os/ \
--initrd-inject virtual-desktop.cfg --extra-args "inst.ks=file:/virtual-desktop.cfg"
2021-11-12 15:45:05 +00:00
```
2021-11-26 21:17:46 +00:00
## Automated installation using a remote kickstart file
2021-11-12 15:45:05 +00:00
2021-11-26 21:17:46 +00:00
* Alternatively, you can do the same as above but with an Internet-accessible kickstart file. The last line has to be swapped with :
2021-11-12 15:45:05 +00:00
```
virt-install \
2021-11-26 19:51:09 +00:00
--connect qemu:///session \
--os-variant detect=off \
2021-11-12 15:45:05 +00:00
--virt-type kvm \
--arch x86_64 \
--machine q35 \
2021-11-26 20:23:37 +00:00
--name virtual-desktop \
2021-11-12 15:45:05 +00:00
--boot uefi \
2021-11-26 20:24:20 +00:00
--cpu host-model,topology.sockets=1,topology.cores=2,topology.threads=1 \
2021-11-26 20:23:37 +00:00
--vcpus 2 \
--memory 4096 \
2021-11-12 15:45:05 +00:00
--video virtio \
2021-11-26 19:51:09 +00:00
--graphics spice,listen=none \
2021-11-12 15:45:05 +00:00
--channel spicevmc \
2021-11-26 19:51:09 +00:00
--channel unix,target.type=virtio,target.name=org.qemu.guest_agent.0 \
2021-11-12 15:45:05 +00:00
--autoconsole none \
2021-11-26 19:51:09 +00:00
--console pty,target.type=virtio \
2021-11-12 15:45:05 +00:00
--sound none \
2021-11-26 19:51:09 +00:00
--network type=user,model=virtio \
2021-11-12 15:45:05 +00:00
--controller type=virtio-serial \
--controller type=usb,model=none \
--controller type=scsi,model=virtio-scsi \
--input type=keyboard,bus=virtio \
--input type=tablet,bus=virtio \
--rng /dev/urandom,model=virtio \
2021-11-26 21:24:20 +00:00
--disk path=~/.local/share/libvirt/images/virtual-desktop.img,format=raw,bus=virtio,cache=writeback,size=10 \
2021-11-26 19:51:09 +00:00
--location=https://download.fedoraproject.org/pub/fedora/linux/releases/35/Everything/x86_64/os/ \
2021-11-26 20:23:37 +00:00
--extra-args="inst.ks=https://raw.githubusercontent.com/PhyllomeOS/phyllomeos/main/leaves/virtual-desktop.cfg"
2021-11-12 15:45:05 +00:00
```
### Local deployment without installation
2021-11-26 21:17:46 +00:00
The idea here is to define a virtual machine and use the `netboot.xyz.iso` as a way to boot into an installer.
2021-11-12 15:45:05 +00:00
```
virt-install \
2021-11-26 21:17:46 +00:00
--connect qemu:///session \
--os-variant detect=off \
2021-11-12 15:45:05 +00:00
--virt-type kvm \
--arch x86_64 \
--machine q35 \
2021-11-26 21:17:46 +00:00
--name virtual-desktop \
2021-11-12 15:45:05 +00:00
--boot uefi \
2021-11-26 21:17:46 +00:00
--cpu host-model,topology.sockets=1,topology.cores=2,topology.threads=1 \
--vcpus 2 \
--memory 4096 \
2021-11-12 15:45:05 +00:00
--video virtio \
2021-11-26 21:17:46 +00:00
--graphics spice,listen=none \
2021-11-12 15:45:05 +00:00
--channel spicevmc \
2021-11-26 21:17:46 +00:00
--channel unix,target.type=virtio,target.name=org.qemu.guest_agent.0 \
2021-11-12 15:45:05 +00:00
--autoconsole none \
2021-11-26 21:17:46 +00:00
--console pty,target.type=virtio \
2021-11-12 15:45:05 +00:00
--sound none \
2021-11-26 21:17:46 +00:00
--network type=user,model=virtio \
2021-11-12 15:45:05 +00:00
--controller type=virtio-serial \
--controller type=usb,model=none \
--controller type=scsi,model=virtio-scsi \
--input type=keyboard,bus=virtio \
--input type=tablet,bus=virtio \
--rng /dev/urandom,model=virtio \
--disk none \
--cdrom=/var/lib/libvirt/iso/netboot.xyz.iso \
--install no_install=yes
```
### Built-in unattended mode
2021-11-26 21:17:46 +00:00
* `virt-install` can rely on libosinfo's unattended installation support to deploy fedora32 without any user intervention:
2021-11-12 15:45:05 +00:00
`virt-install --install fedora32 --unattended`
### Cloud-init
2021-11-26 21:17:46 +00:00
> Under construction
{.is-warning}
`cloud-init` may be used alongside `virt-install`:
2021-11-12 15:45:05 +00:00
`virt-install --install fedora34,cloud=yes --cloud-init root-password-generate=on ssh-key=/home/user/.ssh/test_rsa.pub disable=on`