Repair GPT Table: Difference between revisions

From WikiMLT
mNo edit summary
m Text replacement - "mlw-continue" to "code-continue"
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>{{ContentArticleHeader/Linux_Server|toc=off}}{{ContentArticleHeader/Linux_Desktop}}</noinclude>
<noinclude>{{ContentArticleHeader/Linux_Server|toc=off}}{{ContentArticleHeader/Linux_Desktop}}</noinclude>
Gere is presented a list of the steps that I've applied to repair the GPT table of one of my devices.


=== Поправяне на GPT таблицата на /dev/sda1 ===
== Create a Backup of the Partition Table ==
 
First things first - create a backup copy of the partition table.
Първао е създаден бекъп на таблицата на един от другите дискове:
<syntaxhighlight lang="shell" line="1">
<syntaxhighlight lang="shell" line="1">
sudo sfdisk -d /dev/sda > /mnt/backups/PT_sda.txt
sudo sfdisk -d /dev/sda > /mnt/backups/gpt_table_sda_cx250.txt
</syntaxhighlight>
</syntaxhighlight>
След това, с помощщта на <code>gdisk</code>, чрез използване на командите <code>p</code> '''print the partition table''', <code>v</code> '''verify disk''' и <code>w</code> '''write table to disk and exit''', таблицата е презаписана от ''вграденото'' бекъп копие:


== Repair the GPT Partition Table ==
Here I'm using the <code>[https://manpages.ubuntu.com/manpages/xenial/man8/gdisk.8.html gdisk]</code> tool but  for similar tasks there is a plenty of [https://manpages.ubuntu.com/manpages/xenial/man8/gdisk.8.html#see%20also other tolls] is available. As final result the partition table is repaired and also a backup copy is written to the disk. In the listing below are used the following <code>gdisk</code>'s commands:
* <code>p</code> print the partition table,
* <code>v</code> verify disk,
* <code>w</code> write table to disk and exit.
<syntaxhighlight lang="shell" line="1">
<syntaxhighlight lang="shell" line="1">
sudo gdisk /dev/sda
sudo gdisk /dev/sda
</syntaxhighlight>
</syntaxhighlight>


<syntaxhighlight lang="text">
<syntaxhighlight lang="yaml" class="code-continue">
GPT fdisk (gdisk) version 1.0.5
GPT fdisk (gdisk) version 1.0.5


Line 24: Line 29:
Found valid GPT with protective MBR; using GPT.
Found valid GPT with protective MBR; using GPT.


</syntaxhighlight>
<syntaxhighlight lang="bash" class="code-continue">
Command (? for help): ?
Command (? for help): ?
</syntaxhighlight>
<syntaxhighlight lang="shell-session" class="code-continue">
b      back up GPT data to a file
b      back up GPT data to a file
c      change a partition's name
c      change a partition's name
Line 41: Line 52:
x      extra functionality (experts only)
x      extra functionality (experts only)
?      print this menu
?      print this menu
</syntaxhighlight>


<syntaxhighlight lang="bash" class="code-continue">
Command (? for help): p
Command (? for help): p
</syntaxhighlight>
<syntaxhighlight lang="terraform" class="code-continue">
Disk /dev/sda: 488397168 sectors, 232.9 GiB
Disk /dev/sda: 488397168 sectors, 232.9 GiB
Model: CT250MX500SSD1
Model: CT250MX500SSD1
Line 56: Line 72:
   1            2048        1050623  512.0 MiB  EF00
   1            2048        1050623  512.0 MiB  EF00
   2        1050624      488394751  232.4 GiB  8300
   2        1050624      488394751  232.4 GiB  8300
</syntaxhighlight>


<syntaxhighlight lang="bash" class="code-continue">
Command (? for help): v
Command (? for help): v
</syntaxhighlight>


<syntaxhighlight lang="terraform" class="code-continue">
No problems found. 4397 free sectors (2.1 MiB) available in 2
No problems found. 4397 free sectors (2.1 MiB) available in 2
segments, the largest of which is 2383 (1.2 MiB) in size.
segments, the largest of which is 2383 (1.2 MiB) in size.
</syntaxhighlight>


<syntaxhighlight lang="bash" class="code-continue">
Command (? for help): w
Command (? for help): w
</syntaxhighlight>


<syntaxhighlight lang="shell-session" class="code-continue">
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
PARTITIONS!!
</syntaxhighlight>


<syntaxhighlight lang="bash" class="code-continue">
Do you want to proceed? (Y/N): y
Do you want to proceed? (Y/N): y
</syntaxhighlight>
<syntaxhighlight lang="shell-session" class="code-continue">
OK; writing new GUID partition table (GPT) to /dev/sda.
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
Warning: The kernel is still using the old partition table.
Line 75: Line 104:
</syntaxhighlight>
</syntaxhighlight>


Референции
== References ==
* Ask Ubuntu: [https://askubuntu.com/a/386802/566421 Fixing corrupt backup GPT table?]
* Ask Ubuntu: [https://askubuntu.com/a/386802/566421 Fixing corrupt backup GPT table?]
* [[Linux Basic Partitioning]]


<noinclude>
<noinclude>
Line 83: Line 113:
  | Прндл  = Linux Server
  | Прндл  = Linux Server
  | Прндл1 = Linux Desktop
  | Прндл1 = Linux Desktop
  | Стадий = 3
  | Стадий = 6
  | Фаза  = Разработване
  | Фаза  = Утвърждаване
  | Статус = Разработван
  | Статус = Утвърден
  | ИдтПт  = Spas
  | ИдтПт  = Spas
  | РзбПт  = {{REVISIONUSER}}
  | РзбПт = Spas
| АвтПт  = Spas
| УтвПт = {{REVISIONUSER}}
  | ИдтДт  = 25.07.2022
  | ИдтДт  = 25.07.2022
  | РзбДт  = {{Today}}
  | РзбДт = 24.09.2022
| АвтДт  = 24.09.2022
| УтвДт = {{Today}}
  | ИдтРв  = [[Special:Permalink/29406|29406]]
  | ИдтРв  = [[Special:Permalink/29406|29406]]
  | РзбРв  = {{REVISIONID}}
  | РзбРв = [[Special:Permalink/31758|31758]]
| АвтРв  = [[Special:Permalink/31762|31762]]
| УтвРв = {{REVISIONID}}
}}
}}
</div>
</div>
</noinclude>
</noinclude>

Latest revision as of 07:29, 26 September 2022

Gere is pre­sent­ed a list of the steps that I've ap­plied to re­pair the GPT ta­ble of one of my de­vices.

Cre­ate a Back­up of the Par­ti­tion Ta­ble

First things first – cre­ate a back­up copy of the par­ti­tion ta­ble.

sudo sfdisk -d /dev/sda > /mnt/backups/gpt_table_sda_cx250.txt

Re­pair the GPT Par­ti­tion Ta­ble

Here I'm us­ing the gdisk tool but for sim­i­lar tasks there is a plen­ty of oth­er tolls is avail­able. As fi­nal re­sult the par­ti­tion ta­ble is re­paired and al­so a back­up copy is writ­ten to the disk. In the list­ing be­low are used the fol­low­ing gdisk's com­mands:

  • p print the par­ti­tion ta­ble,
  • v ver­i­fy disk,
  • w write ta­ble to disk and ex­it.
sudo gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.5

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Command (? for help): ?
b       back up GPT data to a file
c       change a partition's name
d       delete a partition
i       show detailed information on a partition
l       list known partition types
n       add a new partition
o       create a new empty GUID partition table (GPT)
p       print the partition table
q       quit without saving changes
r       recovery and transformation options (experts only)
s       sort partitions
t       change a partition's type code
v       verify disk
w       write table to disk and exit
x       extra functionality (experts only)
?       print this menu
Command (? for help): p
Disk /dev/sda: 488397168 sectors, 232.9 GiB
Model: CT250MX500SSD1
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 0AC2B894-BAE7-4790-80F9-1934C8F84E24
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 488397134
Partitions will be aligned on 2048-sector boundaries
Total free space is 4397 sectors (2.1 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1050623   512.0 MiB   EF00
   2         1050624       488394751   232.4 GiB   8300
Command (? for help): v
No problems found. 4397 free sectors (2.1 MiB) available in 2
segments, the largest of which is 2383 (1.2 MiB) in size.
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
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.

Ref­er­ences