Skip to content

Commit

Permalink
Make dom0 snapshot before upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
marmarta committed Jul 31, 2023
1 parent 985fe78 commit ce27676
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions qubes-dist-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ shutdown_nonessential_vms() {
fi
}


get_root_volume_name() {
local root_dev root_volume
root_dev=$(df --output=source / | tail -1)
case "$root_dev" in (/dev/mapper/*) ;; (*) return;; esac
root_volume=$(lvs --no-headings --separator=/ -o vg_name,lv_name "$root_dev" | tr -d ' ')
case "$root_volume" in (*/) return;; esac
echo "$root_volume"
}

get_root_group_name() {
local root_dev root_volume
root_dev=$(df --output=source / | tail -1)
case "$root_dev" in (/dev/mapper/*) ;; (*) return;; esac
root_group=$(lvs --no-headings -o vg_name "$root_dev" | tr -d ' ')
echo "$root_group"
}


#-----------------------------------------------------------------------------#

if [[ $EUID -ne 0 ]]; then
Expand Down Expand Up @@ -179,6 +198,16 @@ if [ "$assumeyes" == "1" ] || confirm "-> Launch upgrade process?"; then
# Shutdown nonessential VMs
shutdown_nonessential_vms

root_vol_name=$(get_root_volume_name)
root_group_name=$(get_root_group_name)
if [ -z "$root_vol_name" ]; then
echo "---> (STAGE 0) Skipping dom0 snapshot - no LVM volume found"
elif [ "$assumeyes" == "1" ] || confirm "---> (STAGE 0) Do you want to make a dom0 snapshop?"; then
# make a dom0 snapshot
lvcreate -n Qubes41UpgradeBackup -s "$root_vol_name"
echo "--> If upgrade to 4.2 fails, you can restore your dom0 snapshot after booting from a bootable device and using sudo lvconvert --merge $root_group_name/Qubes41UpgradeBackup. Reboot after restoration."
fi

if [ "$update" = "1" ] && [ "$(rpm -q --qf='%{VERSION}' qubes-release)" = "4.2" ]; then
echo "---> (STAGE 1) Updating dom0... already done, skipping"
update=
Expand Down Expand Up @@ -375,6 +404,12 @@ if [ "$assumeyes" == "1" ] || confirm "-> Launch upgrade process?"; then
qubes-prefs default-kernel "$new_kernel"
fi

root_vol_name=$(get_root_volume_name)
if [ "$root_vol_name" ]; then
root_group_name=$(get_root_group_name)
lvremove "$root_group_name/Qubes41UpgradeBackup"

fi
exit 0
fi
fi

0 comments on commit ce27676

Please sign in to comment.