+partprobe ${rootdev}
+is_esp_partition_present "${rootdev}"
+rootdev_has_uefi=$?
+
+# For UEFI systems (which imply using a GPT partition table), fix the GPT backup
+# data structures by moving them to the end of the disk; rootfs partition will
+# have index 3 (1=ESP, 2=boot, 3=rootfs), unlike BIOS/MBR layout where it has 1.
+if [ "${rootdev_has_uefi}" -eq 0 ]; then
+ sgdisk -e "${rootdev}"
+ sleep 5
+ rootpartno=3
+else
+ rootpartno=1
+fi
+