Powiększenie live partycji root GPT na linuxie

Aby powiększyć partycję root na GPT live, należy ( w przykładzie posłużę się, że partycja root to partycja sda):

Należy na początku partycję GPT przenieść na sam koniec za pomocą polecenia:

sgdisk -e /dev/sda

usunąć partycję gdiskiem i utworzyć ją od nowa z tym samym początkowym sektorem – tutaj mamy przykład gdzie na dysku jest partycja root oraz partycją SWAP:

root@SERVER:~# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.8

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

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sda: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 06AD32B9-B564-4EED-B535-4F83F6708FAD
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 1-sector boundaries
Total free space is 104867836 sectors (50.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              63        88070143   42.0 GiB    8300  Linux filesystem
   2        88070144       104847359   8.0 GiB     8200  Linux swap

Command (? for help): d
Partition number (1-2): 2

Command (? for help): d
Using 1

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-209715166, default = 34) or {+-}size{KMGTP}: 63
Last sector (63-209715166, default = 209715166) or {+-}size{KMGTP}: +91G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sda: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 06AD32B9-B564-4EED-B535-4F83F6708FAD
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 1-sector boundaries
Total free space is 18874301 sectors (9.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              63       190840894   91.0 GiB    8300  Linux filesystem

Command (? for help): n
Partition number (2-128, default 2): 
First sector (34-209715166, default = 190840895) or {+-}size{KMGTP}: 
Last sector (190840895-209715166, default = 209715166) or {+-}size{KMGTP}: +8G\
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8200
Changed type of partition to 'Linux swap'

Command (? for help): p
Disk /dev/sda: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 06AD32B9-B564-4EED-B535-4F83F6708FAD
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 1-sector boundaries
Total free space is 2097085 sectors (1024.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              63       190840894   91.0 GiB    8300  Linux filesystem
   2       190840895       207618110   8.0 GiB     8200  Linux swap

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.
The operation has completed successfully.

Następnie robimy partprobe, aby kernel rozpoznał nowy układ partycji:

root@SERVER:~# partprobe

Następnie należy powiększyć filesystem:

root@SERVER:~# resize2fs /dev/sda1

Teraz cieszymy się powiększonym filesystemem 🙂