|
| 1 | +title: Resizing a disk |
| 2 | +date: 2021-11-11 |
| 3 | +category: linux |
| 4 | +tags: linux |
| 5 | + |
| 6 | + |
| 7 | +First off, check the status of the `/` partition that we want to give |
| 8 | +more space: |
| 9 | + |
| 10 | +```text |
| 11 | +# df -h / |
| 12 | +Filesystem Size Used Avail Use% Mounted on |
| 13 | +/dev/sda4 144G 70G 67G 52% / |
| 14 | +``` |
| 15 | + |
| 16 | +We've then expanded the disk on the hosting platform (Linode, AWS, KVM++) and want to make use of that extra space. For this, we use the partition tool GNU Parted: |
| 17 | + |
| 18 | + |
| 19 | +```text |
| 20 | +# parted /dev/sda |
| 21 | +GNU Parted 3.2 |
| 22 | +Using /dev/sda |
| 23 | +Welcome to GNU Parted! Type 'help' to view a list of commands. |
| 24 | +(parted) p |
| 25 | +Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 734003200 blocks) or continue with the current setting? |
| 26 | +Fix/Ignore? Fix |
| 27 | +Model: VMware Virtual disk (scsi) |
| 28 | +Disk /dev/sda: 537GB |
| 29 | +Sector size (logical/physical): 512B/512B |
| 30 | +Partition Table: gpt |
| 31 | +Disk Flags: |
| 32 | +
|
| 33 | +Number Start End Size File system Name Flags |
| 34 | + 1 1049kB 2097kB 1049kB bios_grub |
| 35 | + 2 2097kB 1076MB 1074MB ext4 |
| 36 | + 3 1076MB 3223MB 2147MB linux-swap(v1) |
| 37 | + 4 3223MB 161GB 158GB ext4 |
| 38 | +
|
| 39 | +(parted) resizepart 4 |
| 40 | +Warning: Partition /dev/sda4 is being used. Are you sure you want to continue? |
| 41 | +Yes/No? yes |
| 42 | +End? [161GB]? 537GB |
| 43 | +``` |
| 44 | + |
| 45 | +Now we can ask `parted` to print the new partition table to verify |
| 46 | +it's what we'd expect it to be: |
| 47 | + |
| 48 | +```text |
| 49 | +(parted) p |
| 50 | +Model: VMware Virtual disk (scsi) |
| 51 | +Disk /dev/sda: 537GB |
| 52 | +Sector size (logical/physical): 512B/512B |
| 53 | +Partition Table: gpt |
| 54 | +Disk Flags: |
| 55 | +
|
| 56 | +Number Start End Size File system Name Flags |
| 57 | + 1 1049kB 2097kB 1049kB bios_grub |
| 58 | + 2 2097kB 1076MB 1074MB ext4 |
| 59 | + 3 1076MB 3223MB 2147MB linux-swap(v1) |
| 60 | + 4 3223MB 537GB 534GB ext4 |
| 61 | +
|
| 62 | +(parted) q |
| 63 | +Information: You may need to update /etc/fstab. |
| 64 | +``` |
| 65 | + |
| 66 | +## Resize the file system to use the new space |
| 67 | + |
| 68 | +```text |
| 69 | +# df -h / |
| 70 | +Filesystem Size Used Avail Use% Mounted on |
| 71 | +/dev/sda4 144G 70G 67G 52% / |
| 72 | +``` |
| 73 | + |
| 74 | +Then resize it: |
| 75 | +```text |
| 76 | +# resize2fs /dev/sda4 |
| 77 | +resize2fs 1.44.1 (24-Mar-2018) |
| 78 | +Filesystem at /dev/sda4 is mounted on /; on-line resizing required |
| 79 | +old_desc_blocks = 19, new_desc_blocks = 63 |
| 80 | +The filesystem on /dev/sda4 is now 130285051 (4k) blocks long. |
| 81 | +``` |
| 82 | + |
| 83 | +Now, verify that the space is actually used as intended: |
| 84 | +```text |
| 85 | +# df -h / |
| 86 | +Filesystem Size Used Avail Use% Mounted on |
| 87 | +/dev/sda4 489G 70G 397G 15% / |
| 88 | +``` |
| 89 | + |
| 90 | +Now that's a much larger disk! |
| 91 | + |
| 92 | +## Checking /etc/fstab |
| 93 | + |
| 94 | +```text |
| 95 | +# cat /etc/fstab |
| 96 | +UUID=86935d45-9ba5-11e8-877f-0050569be994 none swap sw 0 0 |
| 97 | +UUID=87b2c106-9ba5-11e8-877f-0050569be994 / ext4 defaults 0 0 |
| 98 | +UUID=86935d44-9ba5-11e8-877f-0050569be994 /boot ext4 defaults 0 0 |
| 99 | +``` |
| 100 | + |
| 101 | +Verify that the UUID of the `/` partition that we resized somehow hasn't changed: |
| 102 | +```text |
| 103 | +# blkid | grep sda4 |
| 104 | +/dev/sda4: UUID="87b2c106-9ba5-11e8-877f-0050569be994" TYPE="ext4" PARTUUID="09fa4b97-c549-44d6-b498-a3117264b445" |
| 105 | +``` |
| 106 | + |
| 107 | +As you can see, the `UUID` corresponds to what it's in `/etc/fstab`. |
| 108 | + |
| 109 | + |
0 commit comments