Format, and Mount a Disk on Ubuntu 20.04
To format and mount a disk on Ubuntu 20.04, follow these steps:
Identify the Disk: List all disks to find the one you want to format:
sudo fdisk -l
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 thed
command to delete partitions andw
to write changes.Create a New Partition Table: Create a new GPT partition table:
sudo gdisk /dev/sdX
Use the
n
command to create a new partition andw
to write changes.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.Create a Mount Point: Create a directory where the partition will be mounted:
sudo mkdir /mnt/mydrive
Mount the Partition: Mount the partition to the created directory:
sudo mount /dev/sdX1 /mnt/mydrive
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
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.
Subscribe to my newsletter
Read articles from Siddhartha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by