How to add a disk and create a partition in Linux

  • Last update: Apr 3, 2024
  • Views: 40
  • Author: Admin
How to add a disk and create a partition in Linux

Hello colleagues.

In this article, we will talk about how to add a new disk to a server in Linux, namely how to detect a new disk and partition it. All actions in this article you must perform with privileged rights, best of all from under root. In our robot, we will use the fdisk utility .

 

Before starting work, you should make sure that the disk exists in the system. Available disks are checked with the command:

$. fdisk -l

linux adding disk

As you can see in the screenshot, there are 2 disks in the system - sda and sdb , sda - 50GB, sdb - 16GB. We will work with the second disk (sdb).

It is very important to remember that in Linux it is possible to damage a disk by incorrectly specifying a disk name, such as the system one, so you should carefully check and recheck the choice of media. The fact that the new disk does not have a file system and partitions comes to our aid. In our case, the sda ​​disk has /dev/sda1,  /dev/sda2,  /dev/sda3 partitions, while the sdb disk has no partition structure.


 

In the next steps, we need to partition the sdb disk into partitions, and we will use the same fdisk utility. To partition a disk, you need to run the fdisk utility with the absolute path to the disk.

$. fdisk /dev/sdb

linux adding disk

The disk management utility has started.

 

By pressing “ m ” and confirming the input with the Enter key, the program will provide a list of available commands for managing the disk.

linux adding disk

 

Usually everyone uses the fdisk subcommands :

  • n - Create partition
  • p - Print partition table
  • d - Delete section
  • q - Quit without saving changes
  • w - Write changes and exit.

 

Since we will create a simple partition and will use all the disk space, we press the “ n ” key and then Enter .

linux adding disk

 

Next, the utility will ask you about the partition type, select (primary) - primary and press Enter.

linux adding disk

 

Next, the utility will ask you to specify the first and last sector, enter 1 or leave the default and press Enter .

linux adding disk

This also applies to specifying sectors, so we leave it by default and press  Enter .

linux adding disk

This also applies to specifying sectors, so we leave it by default and press  Enter .

 

Next, the utility created a partition for us and now we need to save it, enter “ w ” and press  Enter .

linux adding disk


 

Check.

$. fdisk -l

linux adding disk

As you can see from the screenshot, everything worked out for us, and we successfully created the sdb1 partition with a size of 16GB.


 

Thank you all, I hope my article was of some help to you.

SIMILAR ARTICLES