Sitemap

How to Format, Mount, and Persist a Drive on Linux

3 min readJul 18, 2026

--

Press enter or click to view image in full size
Photo by Glen Carrie on Unsplash

Here’s how to add a new drive to your Linux server.

  1. List block devices before plugging in the drive
  2. Plug in the drive, list it again to identify it
  3. Check if there’s an existing filesystem
  4. Format the drive if needed
  5. Create a mount point
  6. Verify the mount
  7. Get the drive’s UUID
  8. Add the entry to fstab
  9. Test fstab without rebooting

IDENTIFYING THE STORAGE DRIVE AND FILESYSTEM

Before plugging in the drive, use this command to list the hard drives and partitions:

lsblk

Now plug in the drive and run the command again. Take note of what the new drive is (this is just a USB):

lsblk
Press enter or click to view image in full size

Verify if there is a filesystem in the new volume:

sudo file -s /dev/[disk-name]
sudo file -s /dev/sdc1

If the output has ‘data’ (/dev/sdc: data) then it means there’s no filesystem.

Press enter or click to view image in full size

In my case, it was xfs. It’s up to you if you want to reformat the filesystem.

REFORMATTING THE DRIVE

IMPORTANT: Verify that you are formatting the correct drive first. You do not want to risk erasing the data from the wrong drive.

sudo mkfs.[filesystem] -f /dev/[disk-name]
sudo mkfs.xfs -f /dev/sdc1
Press enter or click to view image in full size
Press enter or click to view image in full size

CREATING A MOUNT POINT

Create the mount point directory:

mkdir [ FOLDER YOU WANT TO MOUNT IT TO ]
mkdir /test-folder

Optional — Change the ownership:

sudo chown [ USER-OWNER ]:[ GROUP-OWNER ] [ MOUNT POINT ]
sudo chown $USER:$USER /test-folder

This makes the account that you’re logged in the owner of the directory.

Mount the disk to the new directory:

sudo mount /dev/[disk-name] /[mountpoint]
sudo mount /dev/sdc1 /test-folder

Confirm that it’s been added to the mount point:

df -h
Press enter or click to view image in full size

ENSURE THESE SETTINGS PERSIST AFTER A REBOOT

We’ll have to edit the /etc/fstab file, which is responsible for telling the OS how to automatically mount disk partitions and filesystems during the boot process.

Get Lumenyx’s stories in your inbox

Join Medium for free to get updates from this writer.

First we have to find the UUID for the new filesystem:

sudo blkid
Press enter or click to view image in full size

Now we have to edit the /etc/fstab file:

sudo vim /etc/fstab

Append /etc/fstab with:

UUID=[UUID-you-copied] [mountpoint] [type-of-filesystem] [configuration-options] [dump] [pass]

In my case, the command is:

UUID=eea4436d-154c-4bde-b885-940d7ed42971 /test-folder xfs defaults,nofail 0 0
Press enter or click to view image in full size

What is nofail?

Specifying nofail means that if the drive fails to mount at boot, then the OS will continue to boot without it.

By default, not specifying nofail can cause the boot process to hang waiting for the device.

Specifying nofail is important for removable drives like USB sticks as they may not always be plugged in.

Run daemon-reload:

sudo systemctl daemon-reload

Test out your changes without rebooting by telling the OS to manually mount everything listed in /etc/fstab with this command:

sudo mount -a

You’re all done.

--

--