Serverspace Black Friday
DF
Daniil Fedorov
August 4, 2021
Updated May 3, 2023

Adding a Volume and Creating Partitions for Linux Systems

AD Windows

After adding a volume in the control panel, you must make it available in the operating system. Connect to the server with sudo privileges and view all volumes. Enter the following command:

fdisk -l

Example 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 bytes

This instruction will describe how to mount the added 40 GB /dev/vdb storage device and partition it into three volumes:

  • 1 primary partition, 10GB
  • 1 extended partition, 30 GB
  • 1 logical partition inside the extended partition, 20 GB

Only 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/vdb

To add a new partition, use the n command:

Command (m for help): n

Partition type:

p primary (0 primary, 0 extended, 4 free)
e extended

Use the p option to select the primary type:

Select (default p): p

Note: Press Enter to select the default values.

Type in the partition number:
Partition number (1-4, default 1): 1

Enter the first sector:

First sector (2048-83886079, default 2048): 2048

Enter the last sector:

Last sector, +sectors or +size{K, M, G} (2048-83886079, default 83886079): +10G

Next, you need to add an extended (additional) partition by selecting the e option:

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e

Set the partition number:

Partition number (2-4, default 2): 2

To 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): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l

Set 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): +20G

To display added partitions, use p command:

Command (m for help): p
Device 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 Linux

 

Note: 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): w

Now 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/vdb1
mkfs.ext4 /dev/vdb5

Note: 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/volume1
mkdir /mnt/volume2

To change the access mode of the partitions you have to execute the following command:

chmod -R 660 /mnt/volume1
chmod -R 660 /mnt/volume2

To 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/fstab

Add 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 0

To mount partitions use:

mount -a

To print the list of mounted devices and the occupied space, use the command:

df -h
Filesystem Size Used Avail Use% Mounted on
...
/dev/vdb1 9.8G 37M 9.3G 1% /mnt/volume1
/dev/vdb5 20G 45M 19G 1% /mnt/volume2

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.