12 May 2016

Partitionen anzeigen, erstellen und Partitionstabellen kopieren

Oft möchte man eine Partitionstabelle von einer Festplatte auf eine andere Festplatte kopieren. Dazu wird bei Festplatten bis 2 TB im Allgemeinen der MBR als Partitionstabelle verwendet. Bei Festplatten größer als 2 TB wird meist die GUID-Partitionstabelle, kurz GPT, verwendet.

  • Anzeigen der MBR-Partitionstabelle
# sfdisk -l /dev/sda
Disk /dev/sda: 233.8 GiB, 251058462208 bytes, 490348559 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000862e8

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1            2048   1050623   1048576  512M 83 Linux
/dev/sda2         1050624 197070847 196020224 93.5G 83 Linux
/dev/sda3       197070848 364843007 167772160   80G 83 Linux
/dev/sda4       364843008 490348558 125505551 59.9G  5 Extended
/dev/sda5       364845056 398399487  33554432   16G 82 Linux swap / Solaris
/dev/sda6       398401536 490348558  91947023 43.9G 83 Linux
  • Kopieren einer MBR-Partitionstabelle auf eine andere Festplatte:
# sfdisk -d /dev/sda | sfdisk /dev/sdb
  • Anzeigen einer GPT-Partitionstabelle
# sgdisk -p /dev/sda
Disk /dev/sda: 5860533168 sectors, 2.7 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 614CF767-B34F-4881-BC99-1EC61018C359
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 5860533134
Partitions will be aligned on 2048-sector boundaries
Total free space is 391390061 sectors (186.6 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02 
   2            4096          395263   191.0 MiB   8300 
   3          395264      5469145087   2.5 TiB     8300  
  • Kopieren einer GPT-Partitionstabelle von sda auf sdb. Die Reihenfolge der Angabe sda/sdb unbedingt beachten!
  • die Option -G erzeugt eine neue, zufällige GUID. Wichtig, für den Einsatz in einem RAID-Verbund
root@server:~# sgdisk -R /dev/sdb /dev/sda
The operation has completed successfully.
root@server:~# sgdisk -G /dev/sdb
The operation has completed successfully.