> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Basic Storage

> A hands-on Linux tutorial on partitioning, formatting, mounting disks and making filesystems persistent via /etc/fstab

This hands-on demo shows how to work with disks, partitions, and filesystems on Linux. You'll learn how to:

* Identify available block devices
* Create a GPT partition table and partitions using `parted`
* Format partitions with XFS, ext4, and VFAT (FAT32)
* Mount partitions and verify mounts
* Make mounts persistent by editing `/etc/fstab`

Prerequisites: root (or sudo) access and an unused block device (in this demo `/dev/sdb`).

## 1 — List block devices

Start by listing block devices to identify the device you'll work on:

```bash theme={null}
root@control:~# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   20G  0 disk
├─sda1        8:1    0    1M  0 part
├─sda2        8:2    0    1G  0 part /boot
└─sda3        8:3    0   19G  0 part
  ├─rhel-root 253:0  0   17G  0 lvm /
  └─rhel-swap 253:1  0    2G  0 lvm [SWAP]
sdb           8:16   0  5.1G  0 disk
sr0          11:0    1 1024M  0 rom
```

<Callout icon="lightbulb" color="#1CB2FE">
  Before proceeding, double-check the target device (this demo uses `/dev/sdb`). Partitioning the wrong disk can cause irreversible data loss.
</Callout>

## 2 — Create partitions with parted

Create a GPT label and three partitions on the target device. The example below creates:

* Partition 1: XFS (start 2048s to 500MiB)
* Partition 2: ext4 (501MiB to 1000MiB)
* Partition 3: FAT32/VFAT (1001MiB to 1500MiB)

Run `parted` interactively:

```bash theme={null}
root@control:~# parted /dev/sdb
GNU Parted 3.6
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
(parted) mkpart primary xfs 2048s 500MiB
(parted) name 1 xfspartition
(parted) mkpart primary ext4 501MiB 1000MiB
(parted) name 2 ext4partition
(parted) mkpart primary fat32 1001MiB 1500MiB
(parted) name 3 vfatpartition
(parted) print
Model: (unknown) (scsi)
Disk /dev/sdb: 5369MB
Number  Start    End      Size     File system  Name
 1      2048s    500MiB   499MiB   xfs          xfspartition
 2      501MiB   1000MiB  499MiB   ext4         ext4partition
 3      1001MiB  1500MiB  499MiB   fat32        vfatpartition
(parted) quit
```

After quitting `parted`, verify the new partition nodes:

```bash theme={null}
root@control:~# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   20G  0 disk
├─sda1        8:1    0    1M  0 part
├─sda2        8:2    0    1G  0 part /boot
└─sda3        8:3    0   19G  0 part
  ├─rhel-root 253:0  0   17G  0 lvm /
  └─rhel-swap 253:1  0    2G  0 lvm [SWAP]
sdb           8:16   0  5.1G  0 disk
├─sdb1        8:17   0  499M  0 part
├─sdb2        8:18   0  499M  0 part
└─sdb3        8:19   0  499M  0 part
sr0          11:0    1 1024M  0 rom
```

Partition summary:

| Partition | Size | Intended FS | Name (PARTLABEL) |
| -: | - | - | - |
| `/dev/sdb1` | 499M | XFS | `xfspartition` |
| `/dev/sdb2` | 499M | ext4 | `ext4partition` |
| `/dev/sdb3` | 499M | vfat (FAT32) | `vfatpartition` |

References: [GNU Parted Documentation](https://www.gnu.org/software/parted/manual/parted.html)

## 3 — Create filesystems

Format each partition with the desired filesystem and apply labels where helpful for `/etc/fstab`.

Commands used:

```bash theme={null}
# XFS on /dev/sdb1
root@control:~# mkfs.xfs /dev/sdb1

# ext4 on /dev/sdb2 and apply label "ext4fs"
root@control:~# mkfs.ext4 -L ext4fs /dev/sdb2

# FAT32 on /dev/sdb3 and set label "vfatpartition"
root@control:~# mkfs.vfat -F 32 -n vfatpartition /dev/sdb3
```

Tip: Use `-L` (or `-n` for vfat) to set a label you can reference in `/etc/fstab` via `LABEL=<name>`. For stable references across reboots and device enumerations, prefer `UUID=`.

See `man mkfs.xfs`, `man mkfs.ext4`, and `man mkfs.vfat` for options.

## 4 — Create mount points and mount

Create directories to use as mount points and mount the newly formatted partitions:

```bash theme={null}
root@control:~# mkdir /xfsmount /ext4mount /vfatmount

root@control:~# mount /dev/sdb1 /xfsmount
root@control:~# mount /dev/sdb2 /ext4mount
root@control:~# mount /dev/sdb3 /vfatmount
```

Verify mounts with `lsblk`:

```bash theme={null}
root@control:~# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda           8:0    0   20G  0 disk
├─sda1        8:1    0    1M  0 part
├─sda2        8:2    0    1G  0 part /boot
└─sda3        8:3    0   19G  0 part
  ├─rhel-root 253:0  0   17G  0 lvm /
  └─rhel-swap 253:1  0    2G  0 lvm [SWAP]
sdb           8:16   0  5.1G  0 disk
├─sdb1        8:17   0  499M  0 part /xfsmount
├─sdb2        8:18   0  499M  0 part /ext4mount
└─sdb3        8:19   0  499M  0 part /vfatmount
sr0          11:0    1 1024M  0 rom
```

Inspect mounted filesystems with a filtered `mount` output:

```bash theme={null}
root@control:~# mount | egrep '/xfsmount|/ext4mount|/vfatmount'
/dev/sdb1 on /xfsmount type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /ext4mount type ext4 (rw,relatime,seclabel)
/dev/sdb3 on /vfatmount type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed)
```

Check available space with `df -h`:

```bash theme={null}
root@control:/# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root        17G   7.6G  9.5G  45% /
/dev/sda2                    960M  353M  608M  37% /boot
/dev/sdb1                    435M   34M  402M   8% /xfsmount
/dev/sdb2                    458M   14K  429M   1% /ext4mount
/dev/sdb3                    499M     0  499M   0% /vfatmount
```

## 5 — Make mounts persistent in /etc/fstab

To ensure the filesystems mount automatically at boot, add entries to `/etc/fstab`. Prefer `UUID=` or `LABEL=` references rather than device node paths like `/dev/sdb1`, since device names can change.

Obtain UUIDs and label information:

```bash theme={null}
root@control:~# blkid /dev/sdb3
/dev/sdb3: SEC_TYPE="msdos" UUID="B195-D19A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="vfatpartition" PARTUUID="8c4bffb6-0bfc-4cff-9529-c4dfe33d6193"
```

Or list filesystem information for all devices:

```bash theme={null}
root@control:~# lsblk --fs
NAME   FSTYPE      LABEL        UUID                                   MOUNTPOINTS
sdb
├─sdb1 xfs                       4f965fc2-f957-47cf-a7a8-ef503b6bfb95   /xfsmount
├─sdb2 ext4        ext4fs      356cf60a-b4c4-4294-83cb-42273fbd8cbe   /ext4mount
└─sdb3 vfat        vfatpartition B195-D19A                             /vfatmount
```

Edit `/etc/fstab` (example snippet). This file controls mounts at boot:

```text theme={null}
#
# /etc/fstab
# Created by anaconda on Tue Mar 31 10:50:07 2026
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5) https://man7.org/linux/man-pages/man5/fstab.5.html, findfs(8) https://man7.org/linux/man-pages/man8/findfs.8.html, mount(8) https://man7.org/linux/man-pages/man8/mount.8.html and/or blkid(8) https://man7.org/linux/man-pages/man8/blkid.8.html for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=d3b9cb8c-5cf7-45cb-8bef-9dec51747be4  /               xfs     defaults        0 0
UUID=691cc3c4-617b-46de-88a8-72845adc7636  /boot           xfs     defaults        0 0
UUID=f7ba6641-f5c1-4503-a64f-c804eda85768  none            swap    defaults        0 0
/dev/sdb1       /xfsmount       xfs     defaults        0 0
LABEL=ext4fs    /ext4mount      ext4    defaults        0 0
UUID=B195-D19A  /vfatmount      vfat    defaults        0 0
```

Notes on the example:

* The `/dev/sdb1` entry uses a device path — acceptable for demos but not recommended for production.
* The ext4 filesystem is mounted by label (`LABEL=ext4fs`).
* The vfat filesystem is mounted by UUID (`UUID=B195-D19A`) — recommended for stability.

After saving `/etc/fstab`, reload and test:

1. Reload systemd units generated from fstab:

```bash theme={null}
root@control:~# systemctl daemon-reload
```

2. Test fstab entries by attempting to mount all filesystems:

```bash theme={null}
root@control:~# mount -a
```

If `mount -a` completes without errors, the fstab entries are valid and the system should mount those filesystems automatically on boot.

Verify with `lsblk`:

```bash theme={null}
root@control:~# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0    20G  0 disk
├─sda1        8:1    0     1M  0 part
├─sda2        8:2    0     1G  0 part /boot
└─sda3        8:3    0    19G  0 part
  ├─rhel-root 253:0  0   17G  0 lvm  /
  └─rhel-swap 253:1  0    2G  0 lvm  [SWAP]
sdb           8:16   0   5.1G  0 disk
├─sdb1        8:17   0   499M  0 part /xfsmount
├─sdb2        8:18   0   499M  0 part /ext4mount
└─sdb3        8:19   0   499M  0 part /vfatmount
sr0           11:0   1  1024M  0 rom
```

You can also test full unmount/remount to ensure behavior:

```bash theme={null}
root@control:~# umount /xfsmount /ext4mount /vfatmount
root@control:~# mount -a
```

<Callout icon="warning" color="#FF6B6B">
  Always validate `/etc/fstab` changes with `mount -a` before rebooting. A malformed fstab can leave the system unbootable or in rescue mode.
</Callout>

## Summary

In this tutorial you have:

* Created a GPT partition table on `/dev/sdb`
* Added three partitions (XFS, ext4, VFAT)
* Formatted each partition with appropriate filesystem tools and applied labels/UUIDs
* Mounted the filesystems and verified them using `lsblk`, `mount`, and `df`
* Made mounts persistent by adding entries to `/etc/fstab` and testing with `mount -a`

Further reading and references:

* Parted manual: [https://www.gnu.org/software/parted/manual/parted.html](https://www.gnu.org/software/parted/manual/parted.html)
* fstab(5): [https://man7.org/linux/man-pages/man5/fstab.5.html](https://man7.org/linux/man-pages/man5/fstab.5.html)
* mount(8): [https://man7.org/linux/man-pages/man8/mount.8.html](https://man7.org/linux/man-pages/man8/mount.8.html)
* blkid(8): [https://man7.org/linux/man-pages/man8/blkid.8.html](https://man7.org/linux/man-pages/man8/blkid.8.html)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/red-hat-certified-system-administrator-rhcsa/module/2f9323b6-f8cf-4f7e-94e3-a136743e7970/lesson/ed03bc34-ebba-47d0-a772-c2a362f0e0a2" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.