Format and mount disk in Linux

Inspect connected disks

sudo fdisk -l

Output might looks like this:

Disk /dev/sda: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: TOSHIBA MQ01
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 1527D2C6-3B89-4709-90B0-B9D5224BA0DD

Execute fdisk to create new partition table

sudo fdisk /dev/sda

Create new partition (considering disk has no partitions, otherwise, we should delete all of them first)

Command (m for help): n # "n" to create new partition
Partition number (1-128, default 1): 1
First sector (34-976773134, default 2048): # default
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-976773134, default 976773134): # default
Do you want to remove the signature? [Y]es/[N]o: Y
Command (m for help): w # Write changes

Check partitions

lsblk

Format partition

sudo mkfs.ext4 /dev/sda1
# or
sudo mkfs -t ext4 /dev/sda1

Check partition

lsblk -f

Create mount folder in host device

sudo mkdir /videos

Mount partition

sudo mount /dev/sda1 /videos

Check mount

sudo mount -a

Get disk UUID

ls -lha /dev/disk/by-uuid

Mount hard disk at boot time

sudo vim /etc/fstab

Add:

/dev/disk/by-uuid/5a3153c9-652d-40b8-8fce-9e829c5a9b5a /videos ext4 defaults 0 0

Leave a Comment

Scroll to Top