How to Add a Volume and Create Partitions on Linux Servers – Step-by-Step Guide
After adding a new volume via the control panel, you need to make it accessible within your operating system. Connect to your server with a user that has sudo privileges and list all available storage devices by running the following command:
fdisk -lExample result:
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 775D7B55-7C02-4DAE-AC79-B81AAA1BECE3
Device Start End Sectors Size Type
/dev/vda1 2048 104447 102400 50M EFI System
/dev/vda2 104448 52428766 52324319 25G Linux filesystem
Disk /dev/vdb: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytesOnly 4 primary partitions can be created on a single physical hard disk. An extended partition is a special type of partition which contains "free space" where more than four primary partitions can be created. Partitions created within an extended partition are called logical partitions.
Run the fdisk utility to create partitions:
fdisk /dev/vdbTo add a new partition, use the n command:
Command (m for help): nPartition type:
p primary (0 primary, 0 extended, 4 free)e extendedUse the p option to select the primary type:
Select (default p): pNote: Press Enter to select the default values.
Type in the partition number:Partition number (1-4, default 1): 1Enter the first sector:
First sector (2048-83886079, default 2048): 2048Enter the last sector:
Last sector, +sectors or +size{K, M, G} (2048-83886079, default 83886079): +10GNext, you need to add an extended (additional) partition by selecting the e option:
Command (m for help): nPartition type:p primary (1 primary, 0 extended, 3 free)e extendedSelect (default p): eSet the partition number:
Partition number (2-4, default 2): 2To make second partition size to take up all remaining disk space, you may leave it at its default value by pressing Enter:
First sector (2099200-83886079, default 2099200): <Enter>Last sector, +sectors or +size{K, M, G} (2099200-83886079, default 83886079): <Enter>Next, you need to create a logical partition inside the extended partition (the logical partition will be defined automatically). To do this, enter the command n in the fdisk utility, then select the logical partition using the l option:
Command (m for help): nPartition type:p primary (1 primary, 1 extended, 2 free)l logical (numbered from 5)Select (default p): lSet the beginning on the sector by default, press Enter:
First sector (2101248-83886079, default 2101248): <Enter>
Enter the last sector according to your desired logical partition size:
Last sector, +sectors or +size{K, M, G} (2101248-83886079, default 83886079): +20GTo display added partitions, use p command:
Command (m for help): pDevice Boot Start End Sectors Size Id Type/dev/vdb1 2048 20973567 20971520 10G 83 Linux/dev/vdb2 20973568 83886079 62912512 30G 5 Extended/dev/vdb5 20975616 62918655 41943040 20G 83 LinuxNote: The extended partition has 10 GB of free space where you can create more logical partitions.
Use the w command to save your changes:
Command (m for help): wNow create a file system on the primary and the logical partition using the mkfs utility, specifying the file system type after the dot.
mkfs.ext4 /dev/vdb1mkfs.ext4 /dev/vdb5Note: the extended partition cannot be formatted with file systems like ext3, FAT, or NTFS, and cannot directly hold data.
Next you need to create a mount point for each partition:
Note:
- Usually, the mount point is created in the /mnt or /media directories;
- You do not need to create a mount point for an extended partition.
mkdir /mnt/volume1mkdir /mnt/volume2To change the access mode of the partitions you have to execute the following command:
chmod -R 660 /mnt/volume1chmod -R 660 /mnt/volume2To mount partitions automatically after the server restart, make changes in /etc/fstab file. Use a text editor like nano or vi to open this file:
nano /etc/fstabAdd the following lines to the file that opens and save the changes:
/dev/vdb1 /mnt/volume1 ext4 defaults 0 0/dev/vdb5 /mnt/volume2 ext4 defaults 0 0To mount partitions use:
mount -aTo print the list of mounted devices and the occupied space, use the command:
df -hFilesystem Size Used Avail Use% Mounted on.../dev/vdb1 9.8G 37M 9.3G 1% /mnt/volume1/dev/vdb5 20G 45M 19G 1% /mnt/volume2
700
300
700
300
700
300