# Formating & Mounting a Disk on Linux

* On your Linux VM, to do this we need to be the root user and run the following command: **fdisk -l**, as we can see the new hard drive, 10GB, is assigned to the path **/dev/vdb**.

<figure><img src="https://2882153758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9YWb69HFXLHYlXffReU%2Fuploads%2FLWA2mQyCHPR6c8ldkXXx%2Fimage.png?alt=media&#x26;token=79c1875d-e4f7-48af-af3e-2e0f5c1da085" alt=""><figcaption></figcaption></figure>

* After the new hard disk has been identified, the next step is partitioning, for this, we will use the following syntax:

```
fdisk /dev/vdb
```

{% hint style="info" %}
Common fdisk parameter are:

* n: Create a new partition.
* P: Print the partition table.
* d: Remove a partition.
* q: It leaves without saving the change.
* w: Save the changes and exit the command. With this in mind we will perform the following process once the **fdisk /dev/vdb** command has been executed: Enter the letter n to create the new partition. - Enter the letter p to define as a primary partition - Number 1 to establish a single partition of the new disk. - Establish the value of the first sector which is 2048 by default. - Establish the value of the last sector which is 20971519. - Save the changes using the letter w.
  {% endhint %}

<figure><img src="https://2882153758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9YWb69HFXLHYlXffReU%2Fuploads%2FB84tkPitDUcCi0Q2l7Ca%2Fimage.png?alt=media&#x26;token=f019727d-b618-40ed-b9c0-36cf38197e3d" alt=""><figcaption></figcaption></figure>

* We can see that the process is executed correctly. If we run **fdisk -l** we can look at the changes in the new disk (/dev/vdb).

<figure><img src="https://2882153758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9YWb69HFXLHYlXffReU%2Fuploads%2FHBcy3CgRgxUDGyslZ5Ax%2Fimage.png?alt=media&#x26;token=9a8fb1ce-f5e6-45b8-b151-522f26388cc6" alt=""><figcaption></figcaption></figure>

* Next step is to format the new hard drive with the desired file system using the command.

```
mkfs.ext4 /dev/vdb1
```

{% hint style="info" %}
**mkfs** is make file system
{% endhint %}

<figure><img src="https://2882153758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9YWb69HFXLHYlXffReU%2Fuploads%2FRzlzChApkZzp1ivBjnRO%2Fimage.png?alt=media&#x26;token=e763b582-c4c2-459b-a9a8-6473773a5492" alt=""><figcaption></figcaption></figure>

* After that we need to create a new directory, in this tutorial we create a new directory called /data:

```
mkdir /data
```

<figure><img src="https://2882153758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9YWb69HFXLHYlXffReU%2Fuploads%2FSAq5rzU2wTJeyIgTIUFC%2Fimage.png?alt=media&#x26;token=d374f2ed-99f5-4f00-926b-eb6bc1ad660e" alt=""><figcaption></figcaption></figure>

* The Next step is to mount the new disk in the desired location, in this tutorial we have created a new directory called /data. use command.

```
mount /dev/vdb1/ /data
```

<figure><img src="https://2882153758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9YWb69HFXLHYlXffReU%2Fuploads%2Fz1N1Ioli3MRRtxCS6NEZ%2Fimage.png?alt=media&#x26;token=4934f6a1-8b8e-4b47-99c9-ab60eea8a17f" alt=""><figcaption></figcaption></figure>

* If we want that partition to be mounted permanently, it will be necessary to edit the file /etc/fstab using the preferred editor and to enter the following line. We keep the change.

```
/dev/vdb1 /data ext4 default 0 0
```

<figure><img src="https://2882153758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9YWb69HFXLHYlXffReU%2Fuploads%2FwLlpuEzlCu5zEiLCOCeT%2Fimage.png?alt=media&#x26;token=97e5d7e0-30a7-4494-a607-9ad7fe8957e5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2882153758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9YWb69HFXLHYlXffReU%2Fuploads%2F13qJW6pRR7hWMK86DxnC%2Fimage.png?alt=media&#x26;token=e8cce9be-aafc-4ada-b728-0283d48c50fb" alt=""><figcaption></figcaption></figure>

* After that, use **df -h** command to see mounted hard drive.

<figure><img src="https://2882153758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi9YWb69HFXLHYlXffReU%2Fuploads%2FV5TfvWEImDN8ALFqYRbx%2Fimage.png?alt=media&#x26;token=435e2a50-eb76-4665-ba85-a3b794ef6489" alt=""><figcaption></figcaption></figure>
