How to Expand Your Linux VPS Root Partition After Disk Space Upgrade

Leave a comment on How to Expand Your Linux VPS Root Partition After Disk Space Upgrade

At RackNerd, we understand the need for increasing storage space in your VPS environments. When you upgrade your VPS disk space allotment or upgrade to a larger VPS package, you might be wondering how to upgrade your partition size, particularly the / root partition. By the way, if you need help with processing any upgrades for your existing VPS service with us, feel free to open a ticket with our Sales Team, and we would be more than happy to assist you with some upgrade options.

Prerequisite

Follow this tutorial only after you have upgraded your VPS package or disk space allotment. Also, please keep in mind that this tutorial assumes you have a decent understanding of Linux systems and commands. If you do not, please consult with an experienced Linux systems administrator before performing such a procedure.

As with any Linux operations that entail modifying a partition, it’s highly recommended to create a backup of crucial data prior to proceeding with these steps. Once you’ve taken a backup of any important data, and upgraded your VPS, then come back to this tutorial to follow the steps in order to resize your / (root) partition.

Disclaimer: RackNerd is not responsible for any data loss or damage resulting from user error in applying the instructions provided in this guide. This tutorial is designed merely as a guideline and may not be entirely applicable to all Linux environments, as they can differ significantly. It is essential to understand your system configuration and proceed with due caution.

Quick Method

The simplest and quickest way to adjust your VPS’s disk size, if you do not have any important data to retain, is to perform a OS reinstall. This can be easily accomplished by logging into the SolusVM control panel at https://nerdvm.racknerd.com/. Once logged in, simply click on the ‘Reinstall’ button and select your desired OS to initiate the process and set up your VPS with the updated disk space allocation. However, if reinstalling isn’t an option for you, then proceed to the below steps in order to learn how to expand your Linux VPS root partition after a disk space upgrade.

How to Expand Your Linux VPS Root Partition Tutorial

Reboot your Server

To start, first, log into the SolusVM control panel at https://nerdvm.racknerd.com/ and then click on the “Reboot” button. This is necessary so that the recently upgraded disk space is recognized by the Virtual Machine. Do *not* reboot from the OS level, make sure to log into the SolusVM control panel and click the Reboot button. If you are not sure how to access the SolusVM control panel, please watch this video in order to learn how to do so.

Once you have hit the “Reboot” button from within SolusVM, log into your server via SSH and make sure you’re logged in as root.

Temporarily Deactivate Your Swap Space

Before we begin with any resizing operations, it’s necessary to temporarily deactivate your swap space. Keep in mind that your system will run without swap space for a few minutes. You can do that by executing the “swapoff -a” command within SSH as follows:

root@racknerd:~# swapoff -a

Verify Partition and Swap locations

In the below example, our root partition is running on /dev/vda1 and our swap partition is on /dev/vda2. Please note that the vda device numbers may vary depending on Linux distribution, custom configurations, etc. You can run the “cat /etc/fstab” command in SSH in order to verify which vda device number your root (/) partition is located on, as well as your swap partition. In most cases, it should be root (/) on /dev/vda1 and swap on /dev/vda2.

Restructure the Partitions Using Fdisk

Next, we’re going to restructure the partitions using fdisk. Our first task is to remove the existing partitions. If done correctly, this should not result in any data loss. To do this, we input fdisk /dev/vda, then utilize the d command to erase partition 2, followed by partition 1, as illustrated below:

root@racknerd:~# fdisk /dev/vda

Command (m for help): d
Partition number (1,2, default 2):
Partition 2 has been deleted.

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Recreate Primary Partition

Now it’s time to recreate our partitions. Assume we’ve allocated 3 GB for swap space. We must ensure that this amount of space remains available for the new swap partition. This tutorial assumes we upgraded our VPS disk space to a total of 200 GB. So in this case, if we want to allocate 3 GB for swap, we need to create a root partition size of 197 GB (as 200 – 3 = 197). Again, feel free to adjust these values based upon your desired swap size and your new, total disk space allotment post upgrade.

Start with /dev/vda1. Press n to create a new partition and p to make it a primary partition. Accept the default value of 2048 for the first sector by pressing Enter. Then, specify the partition size – for instance, if you’re expanding the disk to 200 GB and you’re reserving 3 GB for swap, enter +197G for a 197 GB root partition which we will do in the below example:

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

Created a new partition 1 of type ‘Linux’ and of size 197 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

Recreate SWAP

Now we’re going to recreate the swap partition in a similar way. Press n and p again to create another primary partition. Accept the default values for “First sector” and “Last sector” by pressing Enter. You do not need to specify the size, just press Enter and it will automatically allocate the remaining space accordingly to swap, which in this case, is 3 GB as described earlier.

Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (413140992-419430399, default 413140992):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (413140992-419430399, default 419430399):

Created a new partition 2 of type ‘Linux’ and of size 3 GiB.

Since we’re planning to use the second partition for swap space, we need to change the partition type. To do this, press t at the fdisk prompt, then press 2 to select the second partition. You can view all available partition types by pressing L, or directly input 82 to select “Linux swap / Solaris”, which we will do in the below example:

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 82

Changed type of partition ‘Linux’ to ‘Linux swap / Solaris’.

Command (m for help): w
The partition table has been altered.
Syncing disks.

Saving Changes

After these changes, save and exit fdisk using the “w” command. You should receive a message saying:

Command (m for help): w
The partition table has been altered.
Syncing disks.

Apply Changes

To avoid rebooting, we’ll use partprobe to notify the kernel about the new partitions by running the “partprobe” command. If this results in a “command not found” please skip this step.

root@racknerd:~# partprobe

Resize Filesystem

At this point, it’s time to resize our filesystem on /dev/vda1 by running the “resize2fs /dev/vda1” command as follows:

root@racknerd:~# resize2fs /dev/vda1
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 6, new_desc_blocks = 25
The filesystem on /dev/vda1 is now 51642368 (4k) blocks long.

Initialize the new swap location

Following this, initialize the new swap location on /dev/vda2 by running the “mkswap /dev/vda2” command as follows:

root@racknerd:~# mkswap /dev/vda2
Setting up swapspace version 1, size = 3 GiB (3220172800 bytes)
no label, UUID=a6b5f570-e932-4ba4-ab93-a8a2a3c2d884

To activate swap again, use the “swapon -a” command:

root@racknerd:~# swapon -a

You can confirm your new expanded disk size by running the command: “df -h” in SSH. You can verify the swap is active by running “free -m” in SSH.

Confirm your setup is correct

As a last step, view your /etc/fstab file by running the below command in order to verify that the root partition (/) is referencing the correct vda device number, and that swap is referencing the correct vda device number. In most cases, /etc/fstab does not need to be updated, but it’s worth double checking to ensure it is correct to avoid any issues upon the next system reboot.

cat /etc/fstab

That’s it! You’ve successfully expanded the available disk space on your Linux VPS.

Conclusion

In conclusion, expanding the root partition of your Linux VPS after a disk space upgrade can be achieved by following the steps outlined in this tutorial. However, it is important to note that this process should only be undertaken if you have a good understanding of Linux systems and commands. Additionally, it is crucial to back up your data before proceeding and to consult with an experienced Linux systems administrator if needed. RackNerd provides assistance with VPS upgrades and offers an option for a simple OS reinstall if you don’t have important data to retain. Remember to exercise caution and understand your system configuration before making any changes to avoid data loss or damage. By following the instructions provided in this guide, you can successfully expand the disk space on your Linux VPS and optimize your storage capabilities.

Server Hosting Solutions by RackNerd:

Shared Hosting
cPanel Web Hosting in US, Europe, and Asia datacenters
Logo
Reseller Hosting
Create your new income stream today with a reseller account
Logo
VPS (Virtual Private Server)
Fast and Affordable VPS services - Instantly Deployed
Logo
Dedicated Servers
Bare-metal servers, ideal for the performance-demanding use case.
Logo

Leave a comment

Your email address will not be published. Required fields are marked *