Extension of a partition on a VPS


After a VPS upgrade, the RAM and the CPU will be automatically upgraded following a simple reboot. However, even though a reboot upgrade the amount of disk space available, the partition on it is not automatically extended. This part will have to be done manually. Please note that the output of the commands may slightly differ than yours. Also, if you reinstall your VPS, the partition will be automatically extended.

Backuping your data

As the attempt of the extension of the partition may result in data loss, it is HIGHLY recommended to backup all of your data on your VPS.


OVH is not responsible for any lost data that resulted after the attempt of the extension of your partition.

Rebooting in Rescue Mode

Reboot your VPS in Rescue Mode by clicking on Rescue Mode in the VPS page of your Control Panel. Wait a couple of minutes, you will receive your Rescue Mode credentials by email. After that, connect to your VPS by SSH or by using the KVM in your Control Panel.

Unmounting the partition

Once you’re connected to your VPS in Rescue Mode, your partition will be automatically mounted. In order to resize it, you will need to unmount it. If you know the name of your device (most likely to be /dev/vdb1 in Rescue Mode), you can skip this step. If you don’t know its name, enter the following command:


This will give you the current partitions on your VPS. The first is the Rescue Mode partition, the second one, the one actually containing your data. The output will look like this:

vda 254:0 0 10G 0 disk
└─vda1 254:1 0 10G 0 part /
vdb 254:16 0 25G 0 disk
└─vdb1 254:17 0 25G 0 part /mnt/vdb1

To unmount your partition, enter the command:

umount /dev/vdb1

Executing a filesystem check

Next, it is recommended that a filesystem check is made on the partition to correct any error currently present. The command is:

e2fsck -yf /dev/vdb1
e2fsck 1.42.9 (4-Feb-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1: 37870/1310720 files (0.2% non-contiguous), 313949/5242462 blocks


If you see a “bad magic number in superblock” error, do not continue further. A way to fix this is explained at the bottom of this guide.

Opening the fdisk application

After that, open the fdisk application. Here, you have to give the name of the disk and not the name of the partition as a parameter. If your partition is sdb1 instead of vdb1, for example, then the name of the disk shall be /dev/sdb.

fdisk -u /dev/vdb


This application comes with many built-in subcommands which you can list with the “m” command.

Deleting the old partition

Before we can delete the old partition, it is recommended to retrieve the partition start sector. You can get this information with the “p” command. It is indicated under “Start”. Keep this number with you for later.

Command (m for help): p
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
54 heads, 49 sectors/track, 15851 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000132ff
Device      Boot    Start  End        Blocks    Id  System
/dev/vdb1   *       *2048*   41941745   20969849  83  Linux

Then, delete the partition with the “d” command:


This is the point of no return if you haven’t backuped your data yet.

Command (m for help): d
Selected partition 1

The sole partition on the disk is automatically deleted.

Creating a new partition

Then, create a new partition with the “n” command. It is recommanded to use the default values.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 41943039

On the line First sector, verify that the number shown is the same as your previous partition’s first sector, just in case. If they mismatch, enter the number you noted earlier.

Making the partition bootable

Then, you must make that partition bootable. You can do so with the “a” command.

Command (m for help): a
Partition number (1-4): 1

Saving the changes and quitting the fdisk application

In order to save your changes and quit the application, simply use the “w” command.

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Extending the filesystem on the partition

The partition has been extended, but its filesystem still takes the previous designed space. In order to extend it as well, please enter the following command:

resize2fs /dev/vdb1
resize2fs 1.42.9 (4-Feb-2014)
Resizing the filesystem on /dev/vdb1 to 5242624 (4k) blocks.
The filesystem on /dev/vdb1 is now 5242624 blocks long.

Checking the results

In order to check your results, you can mount the newly created partition and check its size.

mount /dev/vdb1 /mnt
df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1       991M  793M  132M  86% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            1.9G   12K  1.9G   1% /dev
tmpfs           386M  360K  386M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            1.9G     0  1.9G   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/vdb1        50G  842M   48G   2% /mnt

Under size, you will see the newly increased size.

How to fix “bad magic number in superblock” errors

If the e2fsck command returns the “bad magic number in superblock” error message, you will need to check and fix the filesystem by using a backup superblock. In order to know what are the available backup superblocks, enter the command:

dumpe2fs /dev/vdb1 | grep superblock
Primary superblock at 0, Group descriptors at 1-6
Backup superblock at 32768, Group descriptors at 32769-32774
Backup superblock at 98304, Group descriptors at 98305-98310
Backup superblock at 163840, Group descriptors at 163841-163846
Backup superblock at 229376, Group descriptors at 229377-229382
Backup superblock at 294912, Group descriptors at 294913-294918
Backup superblock at 819200, Group descriptors at 819201-819206
Backup superblock at 884736, Group descriptors at 884737-884742
Backup superblock at 1605632, Group descriptors at 1605633-1605638
Backup superblock at 2654208, Group descriptors at 2654209-2654214
Backup superblock at 4096000, Group descriptors at 4096001-4096006
Backup superblock at 7962624, Group descriptors at 7962625-7962630
Backup superblock at 11239424, Group descriptors at 11239425-11239430
Backup superblock at 20480000, Group descriptors at 20480001-20480006
Backup superblock at 23887872, Group descriptors at 23887873-23887878

Then, use the first backup superblock to check and fix the filesystem.

fsck -b 32768 /dev/sda2

If it fixed the issue, you can then go on.