Update haos-vm-v3.sh

This commit is contained in:
tteckster 2022-05-21 19:33:55 -04:00 committed by GitHub
parent d1fb13f5aa
commit 46e8dc3d29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -309,7 +309,6 @@ case $STORAGE_TYPE in
btrfs|nfs|dir) btrfs|nfs|dir)
DISK_EXT=".qcow2" DISK_EXT=".qcow2"
DISK_REF="$VMID/" DISK_REF="$VMID/"
IMPORT_OPT="-format qcow2"
esac esac
for i in {0,1}; do for i in {0,1}; do
disk="DISK$i" disk="DISK$i"
@ -322,45 +321,14 @@ msg_info "Creating HAOS VM"
qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN \ qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN \
-onboot 1 -ostype l26 -scsihw virtio-scsi-pci -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null
qm importdisk $VMID ${FILE%.*} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE 1>&/dev/null
qm set $VMID \ qm set $VMID \
-efidisk0 ${DISK0_REF},size=128K \ -efidisk0 ${DISK0_REF},size=128K \
-scsi0 ${DISK1_REF},size=32G >/dev/null -scsi0 ${DISK1_REF},size=32G >/dev/null
qm set $VMID \ qm set $VMID \
-boot order=scsi0 >/dev/null -boot order=scsi0 >/dev/null
set +o errtrace
(
msg_ok "Created HAOS VM ${CL}${BL}${VM_NAME}" msg_ok "Created HAOS VM ${CL}${BL}${VM_NAME}"
msg_info "Adding Serial Port and Configuring Console"
trap '
echo -e "Unable to configure serial port. VM is still functional."
if [ "$(qm config $VMID | sed -n ''/serial0/p'')" != "" ]; then
qm set $VMID --delete serial0 >/dev/null
fi
exit
' ERR
msg_ok "Added Serial Port and Configured Console"
if [ "$(command -v kpartx)" = "" ]; then
msg_info "Installing kpartx"
apt-get update >/dev/null
apt-get -qqy install kpartx &>/dev/null
msg_ok "Installed kpartx"
fi
DISK1_PATH="$(pvesm path $DISK1_REF)"
DISK1_PART1="$(kpartx -al $DISK1_PATH | awk 'NR==1 {print $1}')"
DISK1_PART1_PATH="/dev/mapper/$DISK1_PART1"
TEMP_MOUNT="${TEMP_DIR}/mnt"
trap '
findmnt $TEMP_MOUNT >/dev/null && umount $TEMP_MOUNT
command -v kpartx >/dev/null && kpartx -d $DISK1_PATH
' EXIT
kpartx -a $DISK1_PATH
mkdir $TEMP_MOUNT
mount $DISK1_PART1_PATH $TEMP_MOUNT
sed -i 's/$/ console=ttyS0/' ${TEMP_MOUNT}/cmdline.txt
qm set $VMID -serial0 socket >/dev/null
)
if [ "$START_VM" == "yes" ]; then if [ "$START_VM" == "yes" ]; then
msg_info "Starting Home Assistant OS VM" msg_info "Starting Home Assistant OS VM"
qm start $VMID qm start $VMID