Extend a Disk Partition and Filesystem


After you increase a disk's size in the dashboard, extend its partition and filesystem so the OS can use the new space. The process is different depending on whether you resized the main disk or an additional disk.

Create a backup before you start.

Extend the Main Disk
Copy link

Step 1. Boot the Server in Recovery Mode
Copy link

See Boot Mode. 

Step 2. Check the Disk Name
Copy link

Go to the Console tab and run:

lsblk

Example output:

NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda       8:0    0   30G  0 disk 
├─sda1    8:1    0   10G  0 part /
├─sda2    8:2    0   4G  0 part 
├─sda14   8:14   0    4M  0 part 
├─sda15   8:15   0  106M  0 part /boot/efi
└─sda16 259:0    0  913M  0 part /boot
vda     253:0    0    1M  1 disk 

In this example, sda is the system disk. On older servers, it may be called vda.

Step 3. Review the Partition Table
Copy link

Start parted with the system disk name:

parted /dev/sda

Run:

print

On the first run, you may see this message:

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 31457280 blocks) or continue
with the current setting? 
Fix/Ignore?

Enter Fix. This updates the GPT table so the system can use all free disk space.

The output of print lists the partitions.

7ed673b6 A2a5 4f0b A475 087f9c353782.png

  • To extend the last partition into the free space, go to Step 4a.
  • To create a new partition, go to Step 4b.

Creating several new partitions is beyond the scope of this article.

To delete a partition, run rm with the partition number:

rm <partition_number>

Step 4a. Extend the Last Partition
Copy link

Run resizepart with the partition number and the new end of the partition. Enter 100% to use all available space:

resizepart <partition_number> 100%

Check the result:

print

Enter q to exit parted and go to Step 5.

Step 4b. Create a New Partition
Copy link

Run mkpart with the partition type (primary or extended), its number, and its size. Enter 100% to use all available space: 

mkpart primary <partition_number> 100%

Enter yes to confirm the new partition size.

Check the result:

print

Enter q to exit parted.

Create a filesystem on the new partition, specifying its name:

mkfs.ext4 /dev/sda3

Step 5. Check the Filesystem
Copy link

Run e2fsck on the partition from Step 4 (/dev/sda2, /dev/sda3, and so on):

e2fsck -yf /dev/sda2

10e9e2a0 F362 4314 Be34 65e4bec2eecd

Step 6. Resize the File System
Copy link

Specify the partition name:

resize2fs /dev/sda2

82049b53 F718 48ac 907b 81e7ddca35d1

Step 7. Verify the New Size
Copy link

Mount the partition you modified (/dev/sda2, /dev/sda3, and so on):

mount /dev/sda2 /mnt

Check the size:

df -h

7dc701d2 2ddc 447f B8c7 F40f5f1ea16d

If the size hasn't change, go back to Step 1 and repeat the procedure.

If the size has changed, unmount the partition:

umount /mnt

Step 8. Boot the Server in Standard Mode
Copy link

See Boot Mode.

Extend an Additional Disk
Copy link

After you resize the disk in the dashboard, check its new size:

lsblk

Example output:

NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda       8:0    0   25G  0 disk
├─sda1    8:1    0 24.9G  0 part /
├─sda14   8:14   0    4M  0 part
└─sda15   8:15   0  106M  0 part /boot/efi
sdb       8:16   0   20G  0 disk
└─sdb1    8:17   0   10G  0 part
vda     252:0    0    1M  1 disk

Here, sdb has grown to 20 GB, but the sdb1 partition is still 10 GB. You need to extend the partition and then the filesystem.

Step 1. Unmount the Disk
Copy link

If the disk is mounted through /etc/fstab, comment out its entry first so it isn't mounted automatically:

nano /etc/fstab

Find the line for /dev/sdb1 (or its UUID) and add # at the beginning.

Before unmounting, check which processes are using the disk:

lsof /mnt/disk2

If the command returns no output, the disk is safe to unmount. Otherwise, stop the processes or close the applications that use it.

Unmount the disk:

sudo umount -l /mnt/disk2

Step 2. Extend the Partition
Copy link

Start fdisk:

fdisk /dev/sdb

Then:

  1. Enter d to delete the existing partition. If the disk has only one partition, as in this example, it's selected automatically. The data isn't affected.
  2. Enter n to create a new partition.
  3. Select the same partition type as before (for example, p for primary).
  4. Keep the default starting sector. It must match the previous value.
  5. Keep the default ending sector to use the maximum available size.

When prompted:

Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o:

Enter N to keep your data.

Enter w to write the changes.

After you exit fdisk, update the partition table in the kernel. This way, the system recognizes the changes without a reboot:

partprobe /dev/sdb

If the command succeeds, it prints nothing.

Run lsblk again to verify that the partition now uses the full size:

lsblk

Example output:

NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda       8:0    0   25G  0 disk
├─sda1    8:1    0 24.9G  0 part /
├─sda14   8:14   0    4M  0 part
└─sda15   8:15   0  106M  0 part /boot/efi
sdb       8:16   0   20G  0 disk
└─sdb1    8:17   0   20G  0 part
vda     252:0    0    1M  1 disk

Step 3. Extend the Filesystem
Copy link

Check the filesystem:

e2fsck -f /dev/sdb1

Resize it:

resize2fs /dev/sdb1

Step 4. Mount the Disk Again
Copy link

Mount the disk:

mount -o barrier=0 /dev/sdb1 /mnt/disk2

Then uncomment its entry in /etc/fstab:

nano /etc/fstab

Verify the new size:

df -h

Example output:

Filesystem      Size  Used Avail Use% Mounted on
tmpfs            96M  728K   96M   1% /run
/dev/sda1        25G  2.6G   22G  11% /
tmpfs           479M     0  479M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/sda15      105M  6.1M   99M   6% /boot/efi
tmpfs            96M     0   96M   0% /run/user/0
/dev/sdb1        20G   24K   19G   1% /mnt/disk2

The disk is ready for use.