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:
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.
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.
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.
Goals · 0 of 2
- Write a partition table to the disk not done yet
- Create a partition spanning the whole disk not done yet
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. -
ext4inmkpartis a note in the partition table. The partition holds no filesystem:sudo blkid /dev/loop0p1prints noTYPE. -
The partition device appeared right after
mkpart:lsblk /dev/loop0showsloop0p1.
mkpart only marks out the partition in the table; mkfs creates the filesystem on it.