Lab 34.4. Recovering from GPT
Hi,
My Ubuntu VM is setup with a GPT partition table and LVM. This is what my system partitions look like:
alu@ubuntu-dt-vm:~$ lsblk | grep -v loop NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 5.8G 0 rom /media/alu/Ubuntu 24.04.1 LTS amd64 vda 253:0 0 128G 0 disk \u251c\u2500vda1 253:1 0 1M 0 part \u251c\u2500vda2 253:2 0 2G 0 part /boot \u2514\u2500vda3 253:3 0 126G 0 part \u2514\u2500ubuntu--vg-ubuntu--lv 252:0 0 126G 0 lvm /
So I made backups form the GPT configuration from either fdisk and also gdisk. I saved the configs to a USB stick, as I could not access the backups anymore after destroying the GPT patition table.
So I destroyed the GPT by creating a new table in gdisk without any partitions. I'm not sure that was the right way to go though. After rebooting into the install media, I was able to recover the GPT partition table with the backups, but the system did not boot anyway. However, the partitions are back and I can mount and access the original root filesystem again.
Any Idea how to proceed with recovering GPT?
Thanks,
Urs
Comments
-
Hi Urs,
Can you put here all the commands you ran for items 1, 2 and 4, please? I think you used 'vda' instead 'sda', as shown in the guide.
Regards,
Luis.0 -
Hi Luis,
The vda is the main paravirualized disk of this VM which runs on KVM. It was automatically created like this during the installation of Ubuntu. So there is no sda disk, only this single vda. But the disk type should not matter I guess.
I did not run either of the commands from step 1, 2 or 4 as these commands are related to the MBR partition (dump of the first couple of bytes on the disk with dd). So I only mad backups of the GPT partition table and destroyed it afterwards. This is what I meant when I mentioned that I don't know if that is the right way to go. Do I have to follow the steps 1, 2 and 4 and dump/destroy/recover the MBR partition with dd even if the VM's disk is configured with GPT?
Regards,
Urs0 -
Sorry, this was the wrong topic. Can you please delete my last post?
Thanks,
Urs0 -
Wrong post deleted.
0 -
Hi Luis,
Thanks for deleting the post. Would be nice, if you could follow up on my last post from November 25.
Regards,
Urs0 -
Hi Urs, I see it now.
So, if you have a GPT partition you need to use the 'sgdisk' tool, as you can see in the man sgdisk(8) page:
-b, --backup=file
Save partition data to a backup file. You can back up your current in-memory partition table to a disk file using this option. The resulting file is a binary file consisting of the protective MBR, the main GPT header, the backup GPT header, and one copy of the partition table, in that order. Note that the backup is of the current in-memory data structures, so if you launch the program, make changes, and then use this option, the backup will reflect your changes. If the GPT data structures are damaged, the backup may not accurately reflect the damaged state; instead, they will reflect GPT fdisk's first-pass interpretation of the GPT.And then:
-l, --load-backup=file
Load partition data from a backup file. This option is the reverse of the -b option. Note that restoring partition data from anything but the original disk is not recommended. This option will work even if the disk's original partition table is bad; however, most other options on the same command line will be ignored.From this:
So I made backups form the GPT configuration from either fdisk and also gdisk.
I see you already ran gdisk and made a backup, perhaps with something like this, right?
sgdisk --backup=gptsave
So, that file generated before by the sgdisk command is the one that you should load with 'sgdisk --load-backup=gspsave' '.
Regards,
Luis.0 -
Hi Luis,
Thanks, now I got it. Not sure what the issue was the last time. I guess it was just a typo or I forgot to save the restored GPT tables in interactive mode. However, with sgdisk it worked like a charm. I'd suggest to update the according chapter and Lab to cover also the process of backup and recovery of GPT. In case someone will have difficultis too, here are all the steps which I went through:
- Backup GPT to a USB thumb drive with sgdisk:
root@ubuntu-dt-vm:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 4K 1 loop /snap/bare/5 loop1 7:1 0 74.3M 1 loop /snap/core22/1564 loop2 7:2 0 73.9M 1 loop /snap/core22/1663 loop3 7:3 0 269.8M 1 loop /snap/firefox/4793 loop4 7:4 0 273M 1 loop /snap/firefox/5273 loop5 7:5 0 10.7M 1 loop /snap/firmware-updater/127 loop6 7:6 0 11.1M 1 loop /snap/firmware-updater/147 loop7 7:7 0 505.1M 1 loop /snap/gnome-42-2204/176 loop8 7:8 0 91.7M 1 loop /snap/gtk-common-themes/1535 loop9 7:9 0 10.5M 1 loop /snap/snap-store/1173 loop10 7:10 0 38.8M 1 loop /snap/snapd/21759 loop11 7:11 0 500K 1 loop /snap/snapd-desktop-integration/178 loop12 7:12 0 568K 1 loop /snap/snapd-desktop-integration/253 loop13 7:13 0 10.7M 1 loop /snap/snap-store/1218 loop14 7:14 0 150.3M 1 loop /snap/thunderbird/546 loop15 7:15 0 150.3M 1 loop /snap/thunderbird/562 loop16 7:16 0 44.3M 1 loop /snap/snapd/23258 sda 8:0 1 57.3G 0 disk \u2514\u2500sda1 8:1 1 57.3G 0 part /media/alu/ed845a58-3e7c-4652-a256-261e29f1e792 sr0 11:0 1 5.8G 0 rom /media/alu/Ubuntu 24.04.1 LTS amd64 vda 253:0 0 128G 0 disk \u251c\u2500vda1 253:1 0 1M 0 part \u251c\u2500vda2 253:2 0 2G 0 part /boot \u2514\u2500vda3 253:3 0 126G 0 part \u2514\u2500ubuntu--vg-ubuntu--lv 252:0 0 126G 0 lvm / root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# sgdisk -b /media/alu/ed845a58-3e7c-4652-a256-261e29f1e792/sgdisk_gpt.bak /dev/vda The operation has completed successfully. root@ubuntu-dt-vm:~# ls -l /media/alu/ed845a58-3e7c-4652-a256-261e29f1e792/sgdisk_gpt.bak -rw-r--r-- 1 root root 17920 Dec 1 11:47 /media/alu/ed845a58-3e7c-4652-a256-261e29f1e792/sgdisk_gpt.bak root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# umount /dev/sda1 root@ubuntu-dt-vm:~#
- Destroy GPT partition table and reboot
root@ubuntu-dt-vm:~# sgdisk --print-mbr /dev/vda Disk size is 268435456 sectors (128.0 GiB) MBR disk identifier: 0x00000000 MBR partitions: Number Boot Start Sector End Sector Status Code 1 1 268435455 primary 0xEE root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# sgdisk --print /dev/vda Disk /dev/vda: 268435456 sectors, 128.0 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 4472920E-CC02-4ACE-894D-ADBED8562A6E Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 2048, last usable sector is 268435422 Partitions will be aligned on 2048-sector boundaries Total free space is 2015 sectors (1007.5 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 4095 1024.0 KiB EF02 2 4096 4198399 2.0 GiB 8300 3 4198400 268433407 126.0 GiB 8300 root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# sgdisk -d 1 /dev/vda Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. root@ubuntu-dt-vm:~# sgdisk -d 2 /dev/vda Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. root@ubuntu-dt-vm:~# sgdisk -d 3 /dev/vda Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# sgdisk --print /dev/vda Disk /dev/vda: 268435456 sectors, 128.0 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 4472920E-CC02-4ACE-894D-ADBED8562A6E Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 2048, last usable sector is 268435422 Partitions will be aligned on 2048-sector boundaries Total free space is 268433375 sectors (128.0 GiB) Number Start (sector) End (sector) Size Code Name root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# root@ubuntu-dt-vm:~# reboot
- Normal boot fails. Hence, boot from rescue media and restore GPT with sgdisk:
root@ubuntu:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 1.6G 1 loop /rofs loop1 7:1 0 471M 1 loop loop2 7:2 0 874.4M 1 loop loop3 7:3 0 4K 1 loop /snap/bare/5 loop4 7:4 0 74.3M 1 loop /snap/core22/1564 loop5 7:5 0 269.8M 1 loop /snap/firefox/4793 loop6 7:6 0 10.7M 1 loop /snap/firmware-updater/127 loop7 7:7 0 505.1M 1 loop /snap/gnome-42-2204/176 loop8 7:8 0 91.7M 1 loop /snap/gtk-common-themes/1535 loop9 7:9 0 10.5M 1 loop /snap/snap-store/1173 loop10 7:10 0 38.8M 1 loop /snap/snapd/21759 loop11 7:11 0 500K 1 loop /snap/snapd-desktop-integration/178 loop12 7:12 0 149.6M 1 loop /snap/thunderbird/507 loop13 7:13 0 116.8M 1 loop /snap/ubuntu-desktop-bootstrap/237 sda 8:0 1 57.3G 0 disk └─sda1 8:1 1 57.3G 0 part sr0 11:0 1 5.8G 0 rom /cdrom vda 253:0 0 128G 0 disk root@ubuntu:~# root@ubuntu:~# root@ubuntu:~# mount /dev/sda1 /mnt root@ubuntu:~# cd /mnt root@ubuntu:/mnt# ls -l sgdisk_gpt.bak -rw-r--r-- 1 root root 17920 Dec 1 10:47 sgdisk_gpt.bak root@ubuntu:/mnt# root@ubuntu:/mnt# root@ubuntu:/mnt# sgdisk -l /mnt/sgdisk_gpt.bak /dev/vda Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. root@ubuntu:/mnt# root@ubuntu:/mnt# root@ubuntu:/mnt# sgdisk -p /dev/vda Disk /dev/vda: 268435456 sectors, 128.0 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 4472920E-CC02-4ACE-894D-ADBED8562A6E Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 2048, last usable sector is 268435422 Partitions will be aligned on 2048-sector boundaries Total free space is 2015 sectors (1007.5 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 4095 1024.0 KiB EF02 2 4096 4198399 2.0 GiB 8300 3 4198400 268433407 126.0 GiB 8300 root@ubuntu:/mnt# root@ubuntu:/mnt# root@ubuntu:/mnt# reboot
So, that's it.
Thanks again Louis for your support.
Regards,
Urs1 -
Hi Urs,
I'd suggest to update the according chapter and Lab to cover also the process of backup and recovery of GPT.
Ok, it's a good suggestion, thanks.
Thanks again Louis for your support.
It's a pleasure! I'm glad that you are progressing in the course.
Many regards,
Luis.0
Categories
- All Categories
- 217 LFX Mentorship
- 217 LFX Mentorship: Linux Kernel
- 791 Linux Foundation IT Professional Programs
- 353 Cloud Engineer IT Professional Program
- 178 Advanced Cloud Engineer IT Professional Program
- 82 DevOps Engineer IT Professional Program
- 147 Cloud Native Developer IT Professional Program
- 137 Express Training Courses
- 137 Express Courses - Discussion Forum
- 6.2K Training Courses
- 47 LFC110 Class Forum - Discontinued
- 71 LFC131 Class Forum
- 42 LFD102 Class Forum
- 226 LFD103 Class Forum
- 18 LFD110 Class Forum
- 38 LFD121 Class Forum
- 18 LFD133 Class Forum
- 7 LFD134 Class Forum
- 18 LFD137 Class Forum
- 71 LFD201 Class Forum
- 4 LFD210 Class Forum
- 5 LFD210-CN Class Forum
- 2 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum - Discontinued
- 2 LFD233 Class Forum
- 4 LFD237 Class Forum
- 24 LFD254 Class Forum
- 697 LFD259 Class Forum
- 111 LFD272 Class Forum
- 4 LFD272-JP クラス フォーラム
- 12 LFD273 Class Forum
- 148 LFS101 Class Forum
- 1 LFS111 Class Forum
- 3 LFS112 Class Forum
- 2 LFS116 Class Forum
- 4 LFS118 Class Forum
- LFS120 Class Forum
- 7 LFS142 Class Forum
- 5 LFS144 Class Forum
- 4 LFS145 Class Forum
- 2 LFS146 Class Forum
- 3 LFS147 Class Forum
- 1 LFS148 Class Forum
- 15 LFS151 Class Forum
- 2 LFS157 Class Forum
- 29 LFS158 Class Forum
- 7 LFS162 Class Forum
- 2 LFS166 Class Forum
- 4 LFS167 Class Forum
- 3 LFS170 Class Forum
- 2 LFS171 Class Forum
- 3 LFS178 Class Forum
- 3 LFS180 Class Forum
- 2 LFS182 Class Forum
- 5 LFS183 Class Forum
- 31 LFS200 Class Forum
- 737 LFS201 Class Forum - Discontinued
- 3 LFS201-JP クラス フォーラム
- 18 LFS203 Class Forum
- 134 LFS207 Class Forum
- 2 LFS207-DE-Klassenforum
- 1 LFS207-JP クラス フォーラム
- 302 LFS211 Class Forum
- 56 LFS216 Class Forum
- 52 LFS241 Class Forum
- 48 LFS242 Class Forum
- 38 LFS243 Class Forum
- 15 LFS244 Class Forum
- 2 LFS245 Class Forum
- LFS246 Class Forum
- 48 LFS250 Class Forum
- 2 LFS250-JP クラス フォーラム
- 1 LFS251 Class Forum
- 152 LFS253 Class Forum
- 1 LFS254 Class Forum
- 1 LFS255 Class Forum
- 7 LFS256 Class Forum
- 1 LFS257 Class Forum
- 1.3K LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 118 LFS260 Class Forum
- 159 LFS261 Class Forum
- 42 LFS262 Class Forum
- 82 LFS263 Class Forum - Discontinued
- 15 LFS264 Class Forum - Discontinued
- 11 LFS266 Class Forum - Discontinued
- 24 LFS267 Class Forum
- 22 LFS268 Class Forum
- 30 LFS269 Class Forum
- LFS270 Class Forum
- 202 LFS272 Class Forum
- 2 LFS272-JP クラス フォーラム
- 1 LFS274 Class Forum
- 4 LFS281 Class Forum
- 9 LFW111 Class Forum
- 259 LFW211 Class Forum
- 181 LFW212 Class Forum
- 13 SKF100 Class Forum
- 1 SKF200 Class Forum
- 1 SKF201 Class Forum
- 795 Hardware
- 199 Drivers
- 68 I/O Devices
- 37 Monitors
- 102 Multimedia
- 174 Networking
- 91 Printers & Scanners
- 85 Storage
- 758 Linux Distributions
- 82 Debian
- 67 Fedora
- 17 Linux Mint
- 13 Mageia
- 23 openSUSE
- 148 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 353 Ubuntu
- 468 Linux System Administration
- 39 Cloud Computing
- 71 Command Line/Scripting
- Github systems admin projects
- 93 Linux Security
- 78 Network Management
- 102 System Management
- 47 Web Management
- 63 Mobile Computing
- 18 Android
- 33 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 371 Off Topic
- 114 Introductions
- 174 Small Talk
- 22 Study Material
- 805 Programming and Development
- 303 Kernel Development
- 484 Software Development
- 1.8K Software
- 261 Applications
- 183 Command Line
- 3 Compiling/Installing
- 987 Games
- 317 Installation
- 97 All In Program
- 97 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)