MadPopo Best WordPress Hosting Solution

Need Help ?  Call Us 24/7 : +91 7039 003 001

Changing the Partition Layout of Your VPS after OS Installation

What are Partitions?

Picture a laptop equipped with a 500 GB disk running the Windows operating system. By default, Windows occupies the entire 500 GB disk. But what if you want to run both Windows and Linux on the same machine? This is where partitions play a crucial role. For instance, you can allocate a 400 GB partition for Windows and reserve a 100 GB partition for Linux on your 500 GB disk. This transforms your physical disk into two distinct entities, allowing you to install Windows on one partition and Linux on the other.
In essence, partitions are logically segregated segments on a hard drive, functioning as if they were independent hard drives. This means each partition can host its own file system and even be encrypted.”

And Why Do I Need to Partition My Server?

Upon receiving your server, it typically comes with a default partition layout and pre-installed OS, which suffices for many users. However, there are instances where customizing this setup becomes necessary.

Here are some reasons prompting customization of the partition layout:

1.Security: To avoid server failure due to a full file system, you can create a separate partition for your /home directory. This ensures that a full /home partition doesn’t impact your OS partition.

2.Encryption: The default OS partition cannot be encrypted later. To encrypt your data, create a separate partition for your /home directory and encrypt this new partition.

3.Backups: Certain backup tools require a dedicated partition as a destination. Therefore, custom partitions are essential for these tools. Remember, while partitions are logically separated, they are still on the same hard drive. Store backups on a different hard drive to mitigate data loss in case of drive failure.


4.Changes in Virtual Machine Storage Size: Following an upgrade, your server may not utilize all available disk space. Manually extend existing partitions to incorporate the new space. Some hosting providers, like madpopo using cloud-init, automate this process.

This guide will walk you through assessing your current partition layout, extending existing partitions, and creating new ones.


Please be advised to perform a backup of all important data before proceeding! Changes to the partition table always bear the risk of a complete data loss

Linux

Expand the Existing Partition

If you’ve increased your virtual machine’s storage capacity, the common approach is to extend the current partition to encompass the additional space. Debian and Ubuntu users can accomplish this by utilizing the cloud-utils package:

sudo apt install cloud-utils -y

“With the installation of cloud-utils complete, we must now determine the name of the current partition. Execute the following command to search for a partition mounted at “/”:”

mount | grep ' / '

Example Output

/dev/sda1 on / type ext4 (rw,relatime,discard,errors=remount-ro)

Take note of the initial part (e.g., “/dev/sda1” in the provided example). To enlarge the partition, employ the following commands:

sudo growpart /dev/sda 1
sudo resize2fs /dev/sda1

And that’s all it takes to expand your existing partition on Debian and Ubuntu.

Customize the Partition Layout

“To implement these changes, the server must be in the rescue system. Boot your server into this system before proceeding. If you’re a Madpopo customer, access your services in the Customer Control Panel, click “Manage” next to your server, and choose “Rescue System.” Select a password, and your server will boot into the rescue system.

Connect to your server via VNC, log in as “root” using the rescue system password. If you’re unfamiliar with VNC, refer to this guide.

Once connected with VNC, use the command f’startxfce4′ to initiate the GUI (graphical user interface).

The software we’ll utilize for adjusting the partition layout is “GParted.” Open it by clicking “Applications” in the top-left corner, then select “Run program.” Type “GParted” and click “Launch.”

Here, you get an overview of all the server partitions. In this instance, there is no available space, requiring us to shrink a partition first. Please be aware that LVM partitions, default in CentOS, cannot be reduced.


Choose the partition you intend to shrink, right-click, and opt for “Resize/Move.”

A new window will emerge, allowing you to define the desired size of the partition. For instance, you can reduce the size to create 20 GB of available space for a new partition.

To validate the adjustments, select “Resize/Move,” and you’ll observe 20 GB of unallocated disk space.

Right-click on the unallocated disk space, choose “New” to generate a new partition. Now, you should see an additional partition in the list:


Up to this point, no modifications have been applied to your hard drive. To implement the changes, click the green checkmark symbol. A confirmation window will appear, cautioning that data loss is possible. As emphasized earlier, alterations to the partition layout carry the risk of complete data loss. Ensure you have a comprehensive backup of all your data.

If you are prepared, select “Apply,” and the modifications will be enacted on your hard drive. The duration of this process may vary depending on the volume of data on your server.

After the changes are implemented, proceed to restart your server. Utilize the following command to display all block devices, including the recently created partition:

sudo lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda       8:0    0   200G  0 disk
|-sda1    8:1    0 179.9G  0 part /
|-sda2    8:2    0    20G  0 part
|-sda14   8:14   0     3M  0 part
`-sda15   8:15   0   124M  0 part /boot/efi

Here you can see the partition “sda2” we just created with a size of 20 GB.

Additional Steps for LVM

If you’re overseeing partition management through Logical Volume Management (LVM), it’s imperative not only to increase the size of the partition but also that of the Logical Volume (LV).
First, make sure to activate the volume:

sudo lvchange -a y <LV_Name>

You can check the available space with the following command:

sudo vgs

Example result:

  VG        #PV #LV #SN Attr   VSize   VFree
testgroup   1   1   0 wz--n- <20.00g <8.00g

First, make sure to activate the volume:

sudo lvchange -a y <LV_Name>

You can check the available space with the following command:

sudo vgs

Example result:

  VG        #PV #LV #SN Attr   VSize   VFree
testgroup   1   1   0 wz--n- <20.00g <8.00g

In this illustration, the Volume Group (VG) ‘testgroup’ has 8 GB of unused storage capacity, as the Logical Volume (LV) currently consumes 12 GB, while 20 GB is accessible. Let’s expand it to utilize the entire available space:

Example output:

This will extend your volume to use all the available storage space. If you run sudo vgs again, you can see that there is no space left (because the LV takes up all the available space):

VG        #PV #LV #SN Attr   VSize   VFree
testgroup   1   1   0 wz--n- <20.00g    0

Once finished with the LV configuration, resize the filesystem to the size of the LV we’ve just extended:

sudo resize2fs <LV_Name>

And that’s all there is if you’re using LVM.
Learn more about mounting additional drives on Linux here.

Windows

If your server is running Windows, connect to your server with RDP.

To access the Disk Management tool, simply right-click on the Windows logo located in the bottom left corner. From the menu, choose “Disk Management.” Here, you’ll find a comprehensive view of all current partitions and connected hard drives. In this instance, a single 200 GB hard drive is visible, which is standard for a Virtual Private Server (VPS). Dedicated servers may feature multiple connected hard drives.

Expand Existing Partitions

To begin, right-click on the specific partition you wish to enlarge and opt for “Extend Volume.” If you haven’t modified the partition layout and have solely upgraded the storage, the default Windows partition is typically labeled as “Windows (C:).”

Now, choose the disk from which you intend to expand your partition. In this illustration, there’s a single disk featuring 50 GB of unallocated space, and this is the space we want the existing partition to utilize, so we’ll select that option.

Alternatively, you have the option to adjust the amount of megabytes (MB) you wish to allocate to the partition. By default, the tool typically utilizes all available space.

Click “Next” and then “Finish” to finalize the process. Upon checking Disk Management, you’ll observe that the previously unallocated space is now integrated, and the partition has been expanded accordingly.

Modify Existing Partitions

To change the partition layout, right click the partition you want to change. For this example, we’ll first shrink the existing partition and then create a new one. Select “Shrink Volume” and in a new window you can choose how much space you want to free up.

In this example, we’ll free up 50 GB of space which means that we have 50 GB unallocated space on our hard drive after this operation.

Select “Shrink” to validate the modifications.

Subsequently, you’ll observe the presence of 50 GB of unallocated space on the hard drive.

Creating New Partitions


To generate a new partition, simply right-click on the unallocated space within the disk overview and choose “New Simple Volume.”


You’ll be prompted to specify the space allocation, and in this instance, we’ll opt to utilize all the available space (50 GB).

You have the option to tailor the settings for the new partition in the subsequent windows. Following the completion of the Setup Wizard, you can observe the newly created partition in the Disk Manager:

Learn more about mounting drives on Windows here.

Sanyog Shelar

passionate about programming and system architecture design, and he uses his deep knowledge to help clients achieve their goals. He also shares his expertise on various cybersecurity issues and offers practical advice on how to protect against common threats. In addition to his technical skills, Sanyog is an expert in server management and is able to provide expert advice on how to manage web applications at the server level.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.