Format, and Mount a Disk on Ubuntu 20.04

SiddharthaSiddhartha
2 min read

To format and mount a disk on Ubuntu 20.04, follow these steps:

  1. Identify the Disk: List all disks to find the one you want to format:

     sudo fdisk -l
    
  2. Remove Old Partitions (Optional): If the disk has old partitions, remove them using gdisk:

     sudo gdisk /dev/sdX
    

    Replace /dev/sdX with your actual disk identifier. Use the d command to delete partitions and w to write changes.

  3. Create a New Partition Table: Create a new GPT partition table:

     sudo gdisk /dev/sdX
    

    Use the n command to create a new partition and w to write changes.

  4. Format the Partition: Format the new partition with the ext4 file system:

     sudo mkfs.ext4 /dev/sdX1
    

    Replace /dev/sdX1 with your actual partition identifier.

  5. Create a Mount Point: Create a directory where the partition will be mounted:

     sudo mkdir /mnt/mydrive
    
  6. Mount the Partition: Mount the partition to the created directory:

     sudo mount /dev/sdX1 /mnt/mydrive
    
  7. Permanent Mount (Optional): To mount the partition automatically at boot, edit the /etc/fstab file:

     sudo nano /etc/fstab
    

    Add a line for your partition:

     UUID=your-partition-uuid /mnt/mydrive ext4 defaults 0 2
    

    Get the UUID with:

     sudo blkid /dev/sdX1
    
  8. Apply Changes: Mount all filesystems mentioned in /etc/fstab:

     sudo mount -a
    

For more detailed instructions, you can refer to this guide and this AskUbuntu post.

0
Subscribe to my newsletter

Read articles from Siddhartha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Siddhartha
Siddhartha