Partitioning and Mounting
Sometimes, after creating an instance, you need to give it more space, or you may need a separate space for backups. This article explains how to partition disks in Linux-based and Windows operating systems.
How to Partition and Mount a Disk in Linux-Based Operating Systems
After creating a new disk, in the instance selection section, select the instance you want to add the new space to and click Attach to Instance.
After attaching the disk to the instance, connect to your instance. Note that all commands in this article must be run with root access.
Use the following command to make sure the new space was added. In the output of this command, this space is usually at the end of the list and has no partition assigned to it.
lsblk
Now there are two ways to use this new disk: turning the whole space into one file system, or partitioning it.
- Method 1: Turning the whole new disk into one file system
To do this, use the following command:
mkfs.ext4 /dev/yourdiskname
Note that after doing this, the whole space of the new disk becomes one file system, and if you want to partition it in the future, the data stored on it will be lost.
Next, you need to mount this formatted space on a directory to use it. To do this, use the following commands (replace youredirectoryname with a name of your choice, for example sample):
mkdir /youredirectoryname
mount /dev/vdb / youredirectoryname
To make sure this space is mounted on the created directory, you can use the following command:
df -h
- Method 2: Partitioning the new space
With this method, you can divide the newly added disk into several partitions and store different data in each partition as needed. To do this, use the following command:
fdisk /dev/yourdiskname
Next, use the n option to create a partition.
Next, you can specify the partition type (primary or extended). For example, with the p option, a primary partition is created. Next, set a number for the partition.
In the next two steps, you can set how much space to allocate to this partition. If you want to allocate the whole added disk to just one partition, skip the next two steps by pressing Enter. Finally, in the last step, use the w option to write the changes.
Now that the partition is created, you need to format it. To do this, use the following command:
mkfs.ext4 /dev/yourpartitionname
The last step is mounting this new partition on a directory. To do this, first create the directory, then mount the created partition on it:
mkdir /youredirectoryname
mount /dev/yourpartitionname / youredirectoryname
Finally, to make sure this space is mounted on the directory, use the following command:
df –h
How to Partition a Disk in Windows
After creating a new disk, in the instance selection section, select the instance you want to add the new space to and click Attach to Instance.
After adding a new disk and attaching it to a Windows-based instance, you can use the new space by following these steps:
Right-click Start and select Disk Management (or press the Windows and R keys together to open the Run window and type diskmgmt.msc).
After the Disk Management window opens, the new disk should be added at the end of the list. Right-click it and select Online.
Next, right-click the disk again and select Initialize Disk.
In the Initialize Disk window, select MBR and click OK.
Next, right-click the new disk again and select New Simple Volume.
After selecting this option, the New Simple Volume Wizard opens. Click Next to go to the next step. In the following steps, you can set how much of this disk to allocate to a new drive, as well as the drive's name and the disk format. After making these settings, in the last step review them and, if they're correct, click Finish.
After completing these steps, the new drive is added to the list of drives in Disk Management and in My Computer.