Last active
July 18, 2023 12:04
-
-
Save mastier/77e529a08dc3bc0039e82c678571b6ed to your computer and use it in GitHub Desktop.
lxc-create-windows-vm.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "$#" != "1" ]]; then | |
echo "Provide the original image ISO" | |
exit 1 | |
fi | |
sudo snap install distrobuilder --classic | |
sudo apt install -y libguestfs-tools wimtools genisoimage | |
IMAGE="$1" | |
if [[ ! -f "$IMAGE-distrobuilder.iso" ]]; then | |
sudo distrobuilder repack-windows "$IMAGE" "$IMAGE-distrobuilder.iso" | |
fi | |
# In case the default profile is not configured | |
if [[ "$(lxc storage list --format csv)" == "" ]]; then | |
lxc storage create default dir | |
fi | |
if [[ "$(lxc profile device list default)" == "" ]]; then | |
lxc profile device add default root disk path=/ pool=default | |
lxc profile device add default net nic nictype=bridged parent=virbr0 | |
fi | |
VM_NAME="win11-$(date +%s)" | |
echo "[Create empty VM $VM_NAME]" | |
lxc init "$VM_NAME" --empty --vm -c security.secureboot=false | |
echo "[Set root device for $VM_NAME]" | |
lxc config device override "$VM_NAME" root size=30GiB | |
echo "[Set CPU and RAM for $VM_NAME]" | |
lxc config set "$VM_NAME" limits.cpu=4 limits.memory=8GiB | |
echo "[Set TPM device for $VM_NAME]" | |
lxc config device add "$VM_NAME" vtpm tpm path=/dev/tpm0 | |
echo "[Add ISO for $VM_NAME]" | |
lxc config device add "$VM_NAME" iso disk source="$PWD/$IMAGE-distrobuilder.iso" boot.priority=10 | |
# Then | |
# - start vm : lxc start <vm_name> | |
# - connect to the console : lxc console -t vga |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment