Archive · Linux

Disks and Mounts: lsblk, fdisk, mkfs and fstab

Add a new disk, put a filesystem on it and mount it permanently.

1 min read

  • Ubuntu 18.04.3 LTS
  • util-linux 2.31
  • ext4

Ubuntu 18.04.3 (August 2019) is the third update of the 18.04 LTS. Adding a disk follows the same steps on any release.

lsblk                                  # find the new disk, e.g. /dev/sdb
sudo fdisk /dev/sdb                    # n, p, 1, defaults, w to create a partition
sudo mkfs.ext4 /dev/sdb1               # create the filesystem
sudo mkdir /data && sudo mount /dev/sdb1 /data
sudo blkid /dev/sdb1                   # note the UUID

Make it permanent in /etc/fstab, using the UUID because device names such as /dev/sdb can change between boots:

UUID=3f1c0a5e-2b5d-4d6e-9a4b-0c6f3f7a1d22  /data  ext4  defaults,nofail  0  2

Run sudo mount -a to test the line before rebooting; an error in fstab can drop a server into emergency mode. Check usage with df -hT.