Before resizing your server’s storage disks, there are a couple things you need to consider. While increasing storage size is safe to do on an existing disk, and can even be done while the disk is mounted in the operating system, decreasing the storage disk is not as straight forward. Imagine shrinking a disk too much and accidentally erasing part of your data. The storage resizing instructions in this guide will help you perform these operations safely.

Safely increasing storage size

Increasing a disk size is a two-phase operation. First, you will need to reserve the additional storage space at your UpCloud Control Panel by expanding your current storage device, then execute certain commands at the operating system level to allow your cloud server to take the advantage of the added disk space.

We highly recommend making a backup of your server before resizing storage.

Start by increasing the disk size in UpCloud Control Panel, you will need to shut down your cloud server before you can change the storage configuration. When your server is powered down, open your Server settings and go to the Disks -tab. Click the Change size -button on the storage device you wish to expand, then either use the appearing slider or type in the desired disk size. Afterwards just click the Set -button to confirm the change.

Once you have increased your storage size to match your requirements, boot up your cloud server again, and perform the following operations at the OS-level.

Linux operations

First, check your disk and partition names with this command

lsblk -io KNAME,TYPE,SIZE
KNAME TYPE SIZE
vda   disk  50G
vda1  part  30G

Commonly you would be resizing the primary disk, which is usually called vda, while any secondary disk would have another dev-name like vdb, or vdc. You will notice that only the disk size is showing the whole storage space you set in the control panel, like 50 GB in the example output above. Follow through with the rest of this section to get the partition extended to use the whole disk space.

Before making any changes, you should save the current partition table by using the command below. Note that you need to replace <disk> in the examples with the disk name you are resizing as shown in the output of the previous command e.g vda.

sudo sfdisk -d /dev/<disk> > ~/part_table_backup.txt

After backing up the partition table, you will need to repartition the disk. Check the information of the current partition.

sudo sfdisk -uS -d /dev/<disk>

Look for the start sector (probably 2048) and partition ID (probably 83) in the first partition, then use those values in the following command in place of the bolded numbers. Note that these values are not constants, and may be different in your case, see the output of the above command for your system’s correct values.

sudo echo "2048,,83,-" | sudo sfdisk --force -uS /dev/<disk>

Afterwards, reboot your server before continuing.

sudo reboot

Finish the operation by running resize2fs. Notice that the <partition> means the part on the disk you are expanding. Check the output of the lsblk -command if you are unsure. For example, if your disk is called vda, then your partition is probably named vda1.

sudo resize2fs /dev/<partition>

Some distributions like CentOS 7 might be using XFS file system instead of EXT4. On these servers, you will need to use xfs_growfs to expand the partition. Install the following utility if it cannot already be found.

sudo yum install xfsprogs

Then use the command below to resize your partition. Make sure to include the “/” in the command as it indicates the root directory required for the operation.

sudo xfs_growfs /

With the resizing complete, reboot your server again.

sudo reboot

You are now done, and the disk should be using all of the space allocated at the control panel. You can verify by checking the disk’s size with the command below.

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G  2.1G   46G   6% /

The example output above is from a single 30GB storage drive server extended to 50GB, such as you would when upgrading your cloud server from a 1024MB / 1CPU  preconfigured to the 2048MB / 2CPU package, which comes with the added 20GB of disk space.

Windows operations

Start by open the Disk Management -panel with typing diskmgmt.msc in search or run and then pressing enter.

The management panel will show the unallocated space available on your disk in black colour. Right-click the partition you wish to resize and select Extend volume.

Extend Volume

In the wizard, the default values will extend the partition to use up all of the unallocated storage, simply click Next on first and second window unless you wish to only extend a certain amount. On the last screen check that the values are correct and click Finish to confirm the changes.

Extend Volume Wizard Screen 2

Once the requested operation is complete, the Disk Management panel will update to show the partition you extended now occupying the space previously unallocated. You are then done and can close the Disk Management -window, the added storage space is ready to use with no additional restarts required.

Safely decreasing storage size

Decreasing a storage size involves creating a new storage disk with the desired size, transferring all data from the old drive to the new one, and then deleting the old storage drive. This way all data is kept secure during the operation and everything gets safely copied as long as it can fit in the target space.

We highly recommend making a backup of your server before resizing storage.

Start by creating a new disk with a preferred size in the UpCloud Control Panel, note that your server must be powered down before the required options become available. Go to the Disks -tab in your Server settings, click the row underneath your existing storage drive to Add new disk. Give the new disk the required size and a name, then click Accept to confirm. After the attaching process is complete, start your server up again.

Once your server is up and running you can continue the resizing process at the OS level.

Linux operations

Check the name of the newly added storage disk using the following command.

lsblk -io KNAME,TYPE,SIZE
KNAME TYPE SIZE
vda   disk  50G
vda1  part  50G
vdb   disk  30G

The disk you are looking for is usually the last on the list, and will not have partitions on it like vdb in the example above. Create a new partition on the new disk using fdisk by replacing the <disk> in the command below with the new disk name.

sudo fdisk /dev/<disk>

The utility will open its own command prompt showing Command (m for help): instead of the usual [email protected]:/$. The following one letter commands will be entered in there.

First, start the new partition wizard with n. Use default values by just pressing enter on each of the options, or type in the required parameter if no default value is given.

> n
# Primary p, partition 1, start sector 2048, end sector at disk end.

With the partition created, make it bootable with the command a.

> a
# Partition 1 if asked.

Afterwards, you can check that the partition was configured properly and is marked bootable with p, it should show something along the lines of the example underneath.

> p
   Device  Boot  Start  End       Blocks    Id  System
/dev/vdb1  *     2048   62914559  31456256  83  Linux

If everything is in order, write partition changes to the disk with command w. In case there was a mistake in the setup, delete the faulty partition by entering the command d and then create a new one again with command n.

> w

Once fdisk has finished writing the partition table to the disk it will exit and return you to the usual command prompt. Check that the new partition shows up using the lsblk -command.

lsblk -io KNAME,TYPE,SIZE
KNAME TYPE SIZE
vda   disk  50G
vda1  part  50G
vdb   disk  30G
vdb1  part  30G

You should see both disks and their partitions with their correct sizes, disks will be named like vda or vdb and their partitions with the added partition identifier number e.g. vda1 or vdb1. Notice that some of the commands below require you to enter the disk name while others use the partitions.

Set up the partition with a file system type appropriate for your server. Ubuntu and other Debian variants should use EXT4, while CentOS 7 machines might prefer using XFS instead.

# Creating an EXT4 file system on Debian, Ubuntu or CentOS 6.5
# Check your current disk's UUID.
sudo cat /etc/fstab
# Replace the <UUID> in the next command with it.
sudo mkfs.ext4 -U <UUID> /dev/<partition>
# Creating an XFS file system on CentOS 7.0
sudo mkfs.xfs /dev/<partition>

Afterwards, mount the new storage disk on your system so that you can copy the files over.

sudo mount /dev/<partition> /mnt

We recommend using rsync to copy such large amounts of files that your operating system might contain. It provides convenient options for copying all the files from your current disk to the new one, while also keeping track of the copy process allowing you to continue from where you left off if you have to cancel the copying for some reason.

Install rsync if you do not already have it with

sudo apt-get install rsync
sudo yum install rsync

The rsync command here uses the options for verbose output so that you can easily see what is getting copied. However, having a large amount of output on the display might slow down the process with a larger number of small files.

You can disable the printout by omitting the parameter –v from the command, or having the output redirected to a file by adding ‘> ~/filename.txt‘ to the end of the command.

sudo rsync -avxHAX / /mnt

Once the copy process has finished, check the disk space usage to see that everything was copied. The used space will not be exactly the same, but the difference should be fairly minor.

df

Lastly, install a boot manager on the new disk so that you can start up again with it as the main storage device. You might need to install a different version of GRUB depending on your system. Commonly Ubuntu and Debian use the first version, while at least the newer CentOS and other Red Hat variants opt for the version two.

sudo grub-install /dev/<disk> --root-directory=/mnt --recheck
sudo grub2-install /dev/<disk>

You should see confirmation like the example output below

Installing for i386-pc platform.
Installation finished. No error reported.

Once the installation is complete, unmount the new disk with

sudo umount /mnt

CentOS 7 users should now set the UUID for the new disk, check it from the /etc/fstab with the following command, and then replace <UUID> in the next command with it while selecting the new disk partition.

sudo cat /etc/fstab
sudo xfs_admin -U <UUID> /dev/<partition>

After that, shut down your server either with the Shutdown request at your UpCloud Control Panel or by using the following command in your server terminal

sudo shutdown -h now

With your server powered down, go to the Disk -tab again and click Detach -button on the former main disk, then start up your server. Confirm that all of your data was copied successfully and is available on the new disk. Afterwards, you can delete the old disk at your UpCloud Control Panel in the My disk resources -section under Disks -menu.

Windows operations

Start by open the Disk Management -panel with typing diskmgmt.msc in search or run and then pressing enter.

Initiate the newly attached disk by selecting MBR and clicking OK. If the initialization popup does not appear, the disk is probably listed as Offline, right-click the disk and select Online to enable the new disk.

Next, you will need to reduce the partition size of your larger disk small enough to fit on the new smaller disk. Right-click the partition and select Shrink Volume.

Shrink Volume

In the wizard enter the required amount to shrink to the editable field. By default, the amount shows an estimate of the maximum available space to shrink, but the value might be too large. Adjust the number so that the total size after shrinking in the last field shows at least a couple of GB less than the total size of the newly attached disk. For example, if your current disk is 50GB total and the new disk is 30GB, enter the amount to shrink somewhere between 30000MB and 22000MB, then click the Shrink -button to confirm. If the operation fails, try again by entering a smaller amount to shrink.

Shrink Volume Wizard

Once your current partition is small enough to fit on the new disk you will need to copy the files over. An easy way to accomplish this is to take advantage of the mirroring feature in Disk Manager. Simply first right click the System Reserve -partition and select Add Mirror. In the next window, select the new disk and click the Add Mirror -button to create the mirror.

Add Mirror

When asked, confirm the disk conversion from Basic to Dynamic by clicking Yes.

Repeat the mirroring for your main partition, then wait for the files to get copied over. This is indicated by the resynchronizing percentage.

While the partitions are syncing, open your cloud server’s System Properties by typing in the search or run sysdm.cpl and pressing enter. Change to the Advanced -tab and click the Settings -button under Startup and Recovery.

In the Startup and Recovery -settings change the default OS to the secondary plex and unselect the Time to display list of operating systems.

Startup and Recovery Settings

When the partition mirrors have finished the resynchronization, shut down your server.

With your server powered down, go to the Disk -tab again and click Detach -button on the former main disk, then start up your server. Confirm that all of your data was copied successfully and is available on the new disk.

Open the Disk Management panel again. Right-click the partitions on the second disk that is labelled Missing and select Remove Mirror to clear the error messages.

Remove Mirror

After this, you can extend the new main partition by following instructions for increasing storage size on Windows as described in an earlier part of this article.

Once you are certain your cloud server is working as it should you can delete the old disk at your UpCloud Control Panel in the My disk resources -section under Disks -menu.