# Linux - File Systems and Partitions

Managing file systems and partitions is essential for effective data organization and optimal system performance in Linux. In this blog, we'll cover the basics of file systems, how to create and manage partitions, and best practices for maintaining them.

**What is a File System?**

A file system in Linux defines how data is stored and accessed on storage devices. Common Linux file systems include **ext4**, **XFS**, and **Btrfs**, each offering unique features suited to different use cases. For example, **ext4** is widely used due to its reliability and performance, while **XFS** is preferred for handling large files, and **Btrfs** is popular for its advanced features like snapshots.

**Understanding Partitions**

Partitions divide your hard drive into distinct sections, allowing for better data management. In Linux, you can create **primary**, **extended**, and **logical** partitions. Proper partitioning not only helps with data organization but also improves system performance.

**Step-by-Step Guide to Partitioning**

**<mark>Step 1: Add the new disk</mark>**

In this guide, a 5GB virtual disk has been added in vSphere for testing purposes.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726844965496/d4591ae0-b952-4dfa-9868-09bf43409d10.png align="center")

#### **<mark>Step 2: Check the Disk</mark>**

Once you've added the new virtual disk, verify that Linux recognizes it by running the following command:

```plaintext
lsblk
```

You'll see a list of disks, including your newly added one (e.g., `/dev/sdb` or `/dev/sdc`).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726845383801/a330086b-a649-4526-aeae-c9c39aa54128.png align="center")

#### **<mark>Step 3: Create Partitions with fdisk</mark>**

Linux provides tools like `fdisk` and `parted` for partitioning. Here's how to use `fdisk`:

**Open a terminal and run:**

Replace sdX with your new disk identifier (e.g., /dev/sdc).

```plaintext
sudo fdisk /dev/sdX  
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726845605870/63ad7560-3637-48c5-bdca-2e9e95e5bba3.png align="center")

**Create a new partition:**

* Type `n` to create a new partition, and follow the prompts:
    
* **Primary or Extended Partition:** Select `p` for a primary partition.
    
* **Partition Number:** Press `Enter` to accept the default.
    
* **First Sector:** Press `Enter` to accept the default.
    
* **Last Sector:** If you want to use the entire disk, press Enter. For a specific size (e.g., 3GB), type `+3G`.
    
* Press `p` to print the partition table and verify the changes.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726845864556/8024de9c-b9ef-4ab1-9a5c-a3837c2f529a.png align="center")

**Write the changes:**

Press `w` to write the changes and exit `fdisk`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726846044500/c3026159-abc3-4282-a87d-bb935e813d9f.png align="center")

#### **<mark>Step 4: Format the Partition</mark>**

Before formatting, check the disk name by running:

```plaintext
lsblk
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726846182507/c2fe69a6-858b-403b-8388-7a009d1d5761.png align="center")

Now, format the newly created partition with the **ext4** file system:

```plaintext
sudo mkfs.ext4 /dev/sdX1
```

Replace `sdX1` with the partition identifier (e.g., `/dev/sdc1`).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726846305096/ba119bc1-ebed-4d79-8990-a389db2f68a3.png align="center")

#### **<mark>Step 5: Mount the Partition</mark>**

Create a mount point and mount the partition:

```plaintext
sudo mkdir /mnt/newdisk
sudo mount /dev/sdX1 /mnt/newdisk
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726846453604/ebb6348e-1e42-4724-8008-9521ad5762a8.png align="center")

Your partition is now ready to use. Verify the mounted disk by running:

```plaintext
df -h
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726846985518/df2d55f4-46d5-40fb-8498-bb6caf6f4bbb.png align="center")

**Conclusion**

Effectively managing file systems and partitions in Linux is crucial for enhancing system performance and ensuring well-organized data. Familiarizing yourself with these concepts will make you a more proficient system administrator, capable of optimizing storage devices for various use cases.
