Home Resize root filesystem on a GPT partition
Post
Cancel

Resize root filesystem on a GPT partition

So, here is how I resized my ext4 root partition (sda2) using gdisk and resize2fs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$ gdisk /dev/sda

Print information (i<enter>2)
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: 7FAC4BC8-6186-4CDF-B6CA-EB73D7C942D1
First sector: 206848 (at 101.0 MiB)
Last sector: 109051903 (at 52.0 GiB)
Partition size: 108845056 sectors (51.9 GiB)
Attribute flags: 0000000000000000
Partition name: ''
Delete the partition (d<enter>2<enter>)
Command (? for help): d
Partition number (1-4): 2
Recreate a new, large partition (n<enter>2<enter>….)
on my setup, gdisk guessed the right first sector. The end sector was also guessed right, since I wanted to fill it up all remaining space
Command (? for help): n
Partition number (2-128, default 2): 
First sector (34-500118158, default = 206848) or {+-}size{KMGTP}: 
Last sector (206848-336072703, default = 336072703) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'
Now copy the old Partition unique GUID to the new partition (x<enter>c<enter>2<enter>)
Command (? for help): x
Expert command (? for help): c

Partition number (1-4): 2
Enter the partition's new unique GUID ('R' to randomize): 7FAC4BC8-6186-4CDF-B6CA-EB73D7C942D1
New GUID is 7FAC4BC8-6186-4CDF-B6CA-EB73D7C942D1
At this point one can verify everything again, after pressing w (to safe the partition), your data might be lost if you did not do this carefully…  
    Just be warned.

Reread your block device partition ($ partprobe)

1
sudo resize2fs /dev/sda2

output

1
2
3
4
resize2fs 1.42.8 (20-Jun-2013)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 11
The filesystem on /dev/sda2 is now 41983232 blocks long.
This post is licensed under CC BY 4.0 by the author.