Linux Labs

Storage / Stage 4 of 11

Partition, filesystem, mount

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 7 · on a machine · 9 min

The partition table

Before a filesystem goes on, a disk is partitioned: its start records which pieces are given to what. Here is how to partition an empty disk.

In the lsblk output the system disk vda has four partitions: vda4 holds the root /, and vda3 holds /boot. A partition is a piece of a disk that the system shows as a device of its own: you create a filesystem on it and mount that. loop0 has no partitions. df shows only mounted filesystems, which is why the new disk was missing from its output.

Where each partition starts and ends is recorded in the partition table at the start of the disk. There are two formats:

Format Where you meet it
GPT new disks; up to 128 partitions, disks over 2 TiB
MBR (msdos) older systems; 4 primary partitions, disks up to 2 TiB

The training disk is a loop device: an image file that the system presents as a disk. You partition it just like a real /dev/vdb, except that its partitions are called loop0p1, loop0p2 instead of vdb1, vdb2.

parted does the partitioning. The --script option runs a command without asking questions:

bash
sudo parted /dev/loop0 --script mklabel gpt  # an empty GPT table
sudo parted /dev/loop0 --script mkpart data ext4 1MiB 100%
sudo parted /dev/loop0 unit MiB print free   # the table and free space

mkpart data ext4 1MiB 100% creates a partition named data from 1 MiB to the end of the disk. It starts at 1 MiB because the table itself sits at the start of the disk, and this offset keeps the partition aligned with the disk's blocks.

Warning

mklabel on a partitioned disk writes a new empty table: the old partitions disappear from it, and access to their data goes with them. Check the disk name against lsblk before partitioning.

Exercise · do it

Partition the disk

Write a GPT partition table to the disk /dev/loop0, create a data partition spanning the whole disk and look at the table.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Write a partition table to the disk not done yet
  • Create a partition spanning the whole disk not done yet
Check yourself 1 question

The mkpart command included the word ext4. What will sudo mount /dev/loop0p1 /srv/data answer now?

  • The table sits at the start of the disk, before the partition, and does not occupy it. The error is about something else, wrong fs type.

  • ext4 in mkpart is a note in the partition table. The partition holds no filesystem: sudo blkid /dev/loop0p1 prints no TYPE.

  • The partition device appeared right after mkpart: lsblk /dev/loop0 shows loop0p1.

mkpart only marks out the partition in the table; mkfs creates the filesystem on it.

Step goals

0 of 2
  • Write a partition table to the disk — not done yet
  • Create a partition spanning the whole disk — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Write a partition table to the disk — not done yet
  • Create a partition spanning the whole disk — not done yet
Loading…