How to Find, Format, and Auto-Mount Hard Disks in Ubuntu 22.04

Whether you’ve just added a new hard drive to your Ubuntu system or you’re trying to set up existing unmounted disks, this guide will walk you through the process of finding, formatting, and setting up automatic mounting for your hard disks in Ubuntu 22.04.

Step 1: Identify Unmounted Disks

First, we need to find which disks are currently unmounted:

  1. Open a terminal.
  2. Run the following command:

sudo lsblk

  1. Look for disks without mount points. They’ll typically be listed as /dev/sdX or /dev/vdX (where X is a letter).

Step 2: Create a New Partition (If Needed)

If your disk doesn’t have a partition:

  1. Use fdisk to create a new partition:

sudo fdisk /dev/vdb

Replace /dev/vdb with your disk identifier.

  1. Follow the prompts to create a new partition.

Step 3: Format the Partition

Now, let’s format the partition:

  1. Format the partition with ext4 filesystem:

sudo mkfs.ext4 /dev/vdb1

Replace /dev/vdb1 with your partition identifier.

Step 4: Create a Mount Point

  1. Create a directory to serve as the mount point:

sudo mkdir /mnt/data

You can replace /mnt/data with your preferred mount point.

Step 5: Test Mount the Disk

  1. Mount the disk to test:

sudo mount /dev/vdb1 /mnt/data

  1. Verify the mount:

df -h

  1. Unmount the disk:

sudo umount /mnt/data

Step 6: Set Up Automatic Mounting

  1. Get the UUID of the partition:

sudo blkid /dev/vdb1

Note down the UUID.

  1. Edit the fstab file:

sudo nano /etc/fstab

  1. Add this line to the end of the file:

UUID="2a***-****-****-****-8d*******" /mnt/data ext4 defaults 0 2

Replace the UUID with your actual UUID, and ensure you keep the quotation marks.

  1. Save and exit the editor (Ctrl+X, then Y, then Enter in nano).

Step 7: Test and Verify

  1. Test the fstab entry:

sudo mount -a

  1. Verify the mount:

df -h

  1. Reboot your system to ensure it mounts automatically:

sudo reboot

  1. After reboot, check if the disk is mounted:

df -h

Congratulations! You’ve successfully found, formatted, and set up automatic mounting for your hard disk in Ubuntu 22.04. This disk will now mount automatically every time you boot your system.

Remember to always be cautious when formatting disks, as it will erase all data on them. Always double-check that you’re working with the correct disk before proceeding with any formatting operations.