Resizing partition after an upgrade

The procedure is roughly:

  1. Backup your data
  2. Start the rescue system from within our control panel
  3. Resize the partitition

Method A: growpart (preferred for xfs)

Method A is the preferred method to resize your partition. During our tests we experienced no problems with xfs filesystems. On ext4 filesystems this method didn’t work even though ext4 is supported. For this you need to install and use the growpart utility on your VPS. Don’t forget to make a backup of your data.

Installation on CentOS or RedHat-based Systems

yum install epel-release
yum install cloud-utils-growpart gdisk

Installation on Ubuntu or Debian-based Systems

apt-get install cloud-initramfs-growroot

Usage on xfs filesystems

Resizing xfs filesystems is pretty easy. With lsblk you will see, that the disk got the new size, but the partition and filesystem not:

$ lsblk
sr0     11:0    1 1024M  0 rom
vda    253:0    0   10G  0 disk
├─vda1 253:1    0  500M  0 part /boot
├─vda2 253:2    0    1G  0 part [SWAP]
└─vda3 253:3    0  8,5G  0 part /
vdb    253:16   0   50G  0 disk
└─vdb1 253:17   0   30G  0 part /data

Now you use growpart to resize the partition:

growpart /dev/vdb 1

The first Partition of /dev/vdb is now resized. You can see the changes with lsblk:

$ lsblk
sr0     11:0    1 1024M  0 rom
vda    253:0    0   10G  0 disk
├─vda1 253:1    0  500M  0 part /boot
├─vda2 253:2    0    1G  0 part [SWAP]
└─vda3 253:3    0  8,5G  0 part /
vdb    253:16   0   50G  0 disk
└─vdb1 253:17   0   50G  0 part /data

After that you can use xfs_grow to alter the file system size:

xfs_growfs /data

Usage on ext4 filesystems

Can be used the same way as on xfs filesystems. In our tests we experienced issues. Changes were applied, but with ‘df -h’ the old size was shown. Therefore we recommend using ‘resize2fs’ with ext4 filesystems.

Method B: Resizing manually

Have you backed up your data? If not, you should do it now to prevent any data loss in case something goes wrong.

Resizing your partition

You need to resize your partition first. Use ‘parted’ as following:

# parted /dev/vdb
GNU Parted 2.3
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: The backup GPT table is not at the end of the disk, as it should be.
This might mean that another operating system believes the disk is smaller.
Fix, by moving the backup to the end (and removing the old backup)?
Fix/Ignore/Cancel? f
Warning: Not all of the space available to /dev/vdb appears to be used, you can
fix the GPT to use all of the space (an extra 104857600 blocks) or continue with
the current setting?
Fix/Ignore? f
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  53.7GB  53.7GB  ext4         primary

# parted /dev/vdb rm 1
# parted -a optimal /dev/vdb mkpart primary 17.4kB 100%

Resizing your filesystem

After you have resized the partition, the filesystem needs to be resized, too. For ExtFS (Extended Filesystem) you can use the following commands:

# e2fsck -f /dev/vdb1
# resize2fs /dev/vdb1

For XFS you can use:

# xfs_growfs /dev/vdb1

Please refer to you distribution’s and filesystem’s documentation for further information.

Merging vda and vdb

You can use any high level volume manager to merge both partitions. However, you cannot make use of our templates and need to install the operating system manually.

Mounting folder via mount bind

In this example we use /home and a default VPS installation.

Per default /home is located on vda. To use the vdb partition for /home you can use mount –bind.

$ mkdir /data/home
$ cp -a /home/* /data/home/
$ mount --bind /data/home /home

Now the folder is mounted and data is stored on vdb. To make this persistent you need to paste the following line to your /etc/fstab file.

/data/home      /home           none    bind        0 0