Add btrfs COW option.

Signed-off-by: prudy <prudy@protonmail.com>
pull/3163/head
prudy 1 year ago
parent 9ba59e0b56
commit 8ac11a62b8
  1. 53
      vm/haos-vm.sh

@ -370,6 +370,19 @@ function start_script() {
fi fi
} }
function btrfs_cow() {
if [ -z "$DISK_CACHE" ]; then
BTRFS_COW="disabled"
else
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "BTRFS COW" --yesno "Disable COW?" --defaultno 10 58); then
BTRFS_COW="disabled"
else
BTRFS_COW=""
fi
fi
msg_ok "Btrfs COW: ${CL}${BL}${BTRFS_COW:-default}${CL}"
}
check_root check_root
arch_check arch_check
pve_check pve_check
@ -405,21 +418,6 @@ else
done done
fi fi
msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location." msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location."
msg_ok "Virtual Machine ID is ${CL}${BL}$VMID${CL}."
msg_info "Retrieving the URL for Home Assistant ${BRANCH} Disk Image"
if [ "$BRANCH" == "$dev" ]; then
URL=https://os-artifacts.home-assistant.io/${BRANCH}/haos_ova-${BRANCH}.qcow2.xz
else
URL=https://github.com/home-assistant/operating-system/releases/download/${BRANCH}/haos_ova-${BRANCH}.qcow2.xz
fi
sleep 2
msg_ok "${CL}${BL}${URL}${CL}"
wget -q --show-progress $URL
echo -en "\e[1A\e[0K"
FILE=$(basename $URL)
msg_ok "Downloaded ${CL}${BL}haos_ova-${BRANCH}.qcow2.xz${CL}"
msg_info "Extracting KVM Disk Image"
unxz $FILE
STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}')
case $STORAGE_TYPE in case $STORAGE_TYPE in
nfs | dir) nfs | dir)
@ -434,8 +432,24 @@ btrfs)
DISK_IMPORT="-format raw" DISK_IMPORT="-format raw"
FORMAT=",efitype=4m" FORMAT=",efitype=4m"
THIN="" THIN=""
btrfs_cow
;; ;;
esac esac
msg_ok "Virtual Machine ID is ${CL}${BL}$VMID${CL}."
msg_info "Retrieving the URL for Home Assistant ${BRANCH} Disk Image"
if [ "$BRANCH" == "$dev" ]; then
URL=https://os-artifacts.home-assistant.io/${BRANCH}/haos_ova-${BRANCH}.qcow2.xz
else
URL=https://github.com/home-assistant/operating-system/releases/download/${BRANCH}/haos_ova-${BRANCH}.qcow2.xz
fi
sleep 2
msg_ok "${CL}${BL}${URL}${CL}"
wget -q --show-progress $URL
echo -en "\e[1A\e[0K"
FILE=$(basename $URL)
msg_ok "Downloaded ${CL}${BL}haos_ova-${BRANCH}.qcow2.xz${CL}"
msg_info "Extracting KVM Disk Image"
unxz $FILE
for i in {0,1}; do for i in {0,1}; do
disk="DISK$i" disk="DISK$i"
eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-} eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-}
@ -447,6 +461,15 @@ qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios ovmf${CPU_TYPE}
-name $HN -tags proxmox-helper-scripts -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -name $HN -tags proxmox-helper-scripts -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null
qm importdisk $VMID ${FILE%.*} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null
if [ "${BTRFS_COW:-}" == "disabled" ]; then
DISK1_PATH=$(pvesm path ${DISK1_REF})
mv ${DISK1_PATH} ${DISK1_PATH}-cow
touch ${DISK1_PATH}
chattr +C ${DISK1_PATH}
cp --reflink=never ${DISK1_PATH}-cow ${DISK1_PATH}
chmod o-r ${DISK1_PATH}
rm ${DISK1_PATH}-cow
fi
qm set $VMID \ qm set $VMID \
-efidisk0 ${DISK0_REF}${FORMAT} \ -efidisk0 ${DISK0_REF}${FORMAT} \
-scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=32G \ -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=32G \

Loading…
Cancel
Save