Skip to content

Instantly share code, notes, and snippets.

@ccy
Last active September 30, 2023 08:28
Show Gist options
  • Save ccy/6d2bfe8585028b88b7dd8a29295462e6 to your computer and use it in GitHub Desktop.
Save ccy/6d2bfe8585028b88b7dd8a29295462e6 to your computer and use it in GitHub Desktop.
KVM installation

Prepare Installation Media on USB

Disk layout

Partition Disk 1 Disk 2 Type Device Mount Point

1

1GB

1GB

mdraid

/dev/md0

/boot/efi

2

1GB

1GB

mdraid

/dev/md1

/boot

3

500GB

500GB

LVM

system/root

/

Useful commands

# Clear mdadm metadata
mdadm --zero-superblock /dev/nvme0n1p[1-4]

# Create metadata 1.0 mdraid device
mdadm --create /dev/md0 --level=1 --raid-device=2 --metadata=1.0 /dev/nvme1n1p1 missing

# Duplicate GPT partition table and re-randomize the partitions' GUID
sgdisk /dev/nvme0n1 -R /dev/nvme1n1
sgdisk -G /dev/nvme1n1

# inform the OS of partition table changes
partprobe

Cockpit

Installation
# Install cockpit
apt install -y cockpit

# Install LVM2 support for udisks2 (utilized by cockpit storaged)
apt install udisks2-lvm2

# Login to cockpit http://ip:9090/

Convert system/root to raid1

LVM

lvconvert --type raid1 -m 1 system/root

Network configuration
# Disable network interface in /etc/network/interfaces
nano /etc/network/interfaces

# Restart NetworkManager service
systemctl restart NetworkManager
Define network bridge in cockpit
  • IP may change

  • May require reboot

KVM via cockpit

# Install cockpit KVM package
apt install cockpit-machines
Example: Windows guest via cockpit
VM=windows
# remove TPM emulator
virt-xml $VM --remove-device --tpm type=emulator

# Add TPM device
virt-xml $VM --add-device --tpm model=tpm-tis,backend.type=emulator,backend.version=2.0,alias.name=tpm0
Example: Windows guest via virt-install
INSTALLER=/mnt/setup/Win11_22H2_English_x64v2-virtio.iso
virt-install \
 --virt-type kvm \
 --graphics vnc \
 --tpm model='tpm-tis',type=emulator,version='2.0' \
 --boot firmware=efi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \
 --vcpus maxvcpus=8,vcpus=8 \
 --memory memory=4096,currentMemory=4096 \
 --disk size=64,bus=virtio \
 --network bridge=bridge0,model=virtio \
 --os-variant=win11 \
 --cdrom=$INSTALLER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment