Linux Disk Management: Partitioning, Formatting, and Mounting

Prepare a new disk by separating device identification, partition planning, filesystem creation, and mounting. Perform the write operations below only on a dedicated lab disk with no data to preserve; the name /dev/sdb alone does not identify a safe target. For the related conditions and procedure, see Understand Disks, Partitions, and File Systems. For the related conditions and procedure, see Mount File Systems and Diagnose Storage Usage.

Verify the target and recovery plan before writing

lsblk -o NAME,SIZE,MODEL,SERIAL,TYPE,FSTYPE,MOUNTPOINTS
findmnt
sudo fdisk -l

Match the device model, size, and attachment against the expected disk; inspect existing filesystems, LVM, encryption, and mounts. Stop if the disk is in use or its ownership is unclear. Back up required data and the partition table to another location and verify recovery before editing. Replace all example devices and paths with your confirmed values.

Checking Installed Disks

  • ls -l /dev/sd* is only an example listing of sd-style device names. Use the preceding lsblk and fdisk queries to identify NVMe, virtual devices, and LVM as well.
  • /dev/sda, /dev/sdb, etc. are hard disks, and /dev/sda1, etc. are partitions.
ls -l /dev/sd*

Example output from an earlier environment; actual devices and UUIDs differ.

brw-rw----. 1 root disk 8,  0 Oct 16 13:12 /dev/sda
brw-rw----. 1 root disk 8,  1 Oct 16 13:12 /dev/sda1
brw-rw----. 1 root disk 8,  2 Oct 16 13:12 /dev/sda2
brw-rw----. 1 root disk 8, 16 Oct 16 13:12 /dev/sdb
brw-rw----. 1 root disk 8, 32 Oct 16 13:12 /dev/sdc

You can check the file system in the following two ways.

  • df -T: Check the file system of mounted partitions
  • sudo blkid: inspect recognizable filesystem and signature metadata on block devices; this is not a guaranteed inventory of every storage type.

Creating Partitions

The existing screenshots show an MBR/DOS example in fdisk 2.23.2. Current fdisk also supports GPT, but creating a new GPT replaces the partition table. Do not run g on a disk containing data merely because it exceeds 2 TB. Before writing, q cancels and w commits; q cannot undo changes already written.

  • The command to manage partitions is fdisk.
  • If you want to manage the partitions of /dev/sdb, use the following commands.
sudo fdisk /dev/sdb

Starting an example disk edit in an older fdisk

  • If you need help, type m.

Interactive fdisk command help

  • To create a new partition, type n and follow the prompts.

Selecting the first partition boundaries in an MBR example

  • Type w to apply the changes.

Adding a second partition in the MBR example

Inspecting the resulting example partition table

If you try to create a partition on a hard disk over 2TB, for example a 4TB hard disk, you will see a message like the following and will not be able to use the entire disk.

The size of this disk is 4 TiB (4398046511104 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

In such a case, type g to create a GPT partition table and then make the partition.

Command (m for help): g
Created a new GPT disklabel (GUID: F13C6D0D-1E30-4448-B015-A61F3AE9EA48).

Formatting

Choose either ext4 or XFS; do not run both formatting examples on the same device in sequence. Proceed only after confirming the device is unused and contains no data that must be preserved.

  • The command to format is mkfs. For example, to format the /dev/sdb1 partition with the ext4 file system, use the following command.
sudo mkfs.ext4 /dev/sdb1
  • To format to the xfs file system, use the following command.
sudo mkfs.xfs /dev/sdb1

Mounting

Prepare a new empty mount point. Mounting over existing files hides them without deleting them, so do not use a production path such as /home for this exercise.

sudo mkdir -p /mnt/disk-lab
findmnt --mountpoint /mnt/disk-lab
  • You need to attach the partition to a specific directory to be able to use that partition.
  • For example, to mount /dev/sdb1 to the /mnt/disk-lab directory, use the following command.
sudo mount /dev/sdb1 /mnt/disk-lab
  • To unmount, use the umount command. There are two methods.

Unmount by either mount point or device, not both in sequence. If the following succeeds, do not try to unmount the same filesystem again.

sudo umount /mnt/disk-lab
  • To have it automatically mount at boot, add the following code to the /etc/fstab file.
  • This means to mount the /dev/sdb1 partition to the /mnt/disk-lab directory. Adjust options such as the file system as appropriate.
/dev/sdb1 /mnt/disk-lab xfs defaults 0 0
  • If you want to immediately apply the changes made to the fstab file, use the following command.
sudo mount -a

Using UUID

A hard disk gets a name like /dev/sdb, and a partition gets a name like /dev/sdb1, but these names are not fixed. If you change the hard disk's mounting location or the recognition order changes, those names can also change. In such cases, mounting may not work properly. Therefore, when using fstab to mount, it is better to use the filesystem UUID. For the related conditions and procedure, see Prepare an Additional Disk and Configure fstab Mounts.

  • You can check the UUID with the blkid command.
sudo blkid

Example output from an earlier environment; actual devices and UUIDs differ.

/dev/sda1: UUID="69d9add5-2153-4bc2-ad99-1560fb205c4b" TYPE="ext4" PARTUUID="aa61ba4b-01"
/dev/sda2: UUID="PuMuNg-5YHg-qikJ-tc10-iPIM-7W1q-4fUqyc" TYPE="LVM2_member" PARTUUID="aa61ba4b-02"
/dev/mapper/cl-root: UUID="79c8cfcb-c9e2-4243-8cf2-cf10eab57c40" TYPE="xfs"
/dev/mapper/cl-swap: UUID="b69a5fc3-98db-4a27-b3d4-a7ef76244ad1" TYPE="swap"
/dev/mapper/cl-home: UUID="fd372a6b-ee76-41d6-b7e6-6e6a7cf8193b" TYPE="xfs"
/dev/sdb1: UUID="fd95c93f-03fc-418a-a6db-c26b921ec93b" TYPE="xfs" PARTUUID="e5f55ef6-01"
  • When adding mount information to /etc/fstab, include the UUID information as follows.
UUID=fd95c93f-03fc-418a-a6db-c26b921ec93b /mnt/disk-lab xfs defaults 0 0

This UUID entry replaces the earlier /dev/sdb1 entry; do not add both for the same mount point. systemctl daemon-reload applies only to systemd-managed systems. If an older lsblk lacks MOUNTPOINTS, inspect the MOUNTPOINT column and the actual mounts.

 

Verify UUID and fstab before reboot

Here, UUID identifies filesystem metadata, not the disk’s hardware serial number. Reformatting can change it and cloning can duplicate it. Distinguish it from PARTUUID and LVM identifiers. Read TYPE and UUID from the partition actually formatted; do not copy the example UUID.

Back up the current fstab under a distinct name and check for duplicate entries at the same mount point. Validate syntax and the actual mount, then verify during a planned reboot. A successful mount -a does not prove every entry or the next boot will work.

sudo findmnt --verify --verbose
sudo systemctl daemon-reload
sudo mount -a
findmnt --mountpoint /mnt/disk-lab
df -T /mnt/disk-lab

If validation or mounting fails, do not reboot; restore only the changed fstab entry. If boot fails, use the console or recovery environment to restore that entry and verify normal boot. Reformatting a disk containing data is not a remedy for a mount error.

blkid filesystem identifier documentation