mkfsCreate a filesystem on a disk or partition
mkfs writes a new, empty filesystem (ext4, xfs, vfat...) onto a disk or partition so it can be mounted and hold files. It is how a fresh cloud volume becomes usable, and it destroys whatever was on the device before.
mkfs.TYPE [options] DEVICE (mkfs -t TYPE DEVICE is the same)A new, empty 100G volume (nvme2n1) needs a filesystem before you can mount it on /archive.
sudoWriting to a raw block device needs root.
mkfs is a small front end: mkfs -t ext4 runs mkfs.ext4, which is mke2fs from e2fsprogs; mkfs.xfs comes from xfsprogs. mke2fs opens the device, asks the kernel for its size and sector size, and on SSDs and EBS first sends discard (TRIM) for the whole device. It then divides the space into block groups (32768 blocks of 4 KiB = 128 MiB each) and writes a superblock with a new random UUID, backup superblocks in some groups (block 32768, 98304...), group descriptors, block and inode bitmaps, inode tables and a journal. The number of inodes is fixed now: one per 16 KiB by default, which is why millions of tiny files can exhaust an ext4 filesystem. XFS instead creates allocation groups and allocates inodes on demand. Data blocks themselves are not zeroed, which is why mkfs on a large disk takes seconds, not hours.
-t TYPEWith plain mkfs: which filesystem to build (mkfs -t xfs = mkfs.xfs)-L LABELVolume label (ext4 up to 16 chars, xfs up to 12)-m PCT (ext4)Percentage reserved for root; default 5, 0-1 for pure data disks-i BYTES (ext4)One inode per BYTES of space; smaller = more inodes for small files-N NUM (ext4)Exact number of inodes to create-T TYPE (ext4)Usage profile from /etc/mke2fs.conf: small, news, largefile, huge-n (ext4)Dry run: print what would be done, including backup superblock locations-F (ext4) / -f (xfs)Force: overwrite an existing filesystem without asking-b SIZEBlock size, normally 4096-E nodiscard / -KSkip the initial TRIM (ext4 / xfs), useful on slow thin-provisioned storageRunning mkfs on a volume restored from a snapshotA snapshot volume already contains a filesystem with data. mkfs replaces it with an empty one.
sudo blkid /dev/nvme3n1 first; if it shows a TYPE, mount it insteadUsing -F / -f by habit to get past the promptThe prompt is the only thing standing between you and wiping the wrong device.
lsblk -f and blkid to identify the device, then mkfs without forcemkfs.ext4 /dev/nvme2n1 after creating partition nvme2n1p1Formatting the whole disk overwrites the partition table you just created.
sudo mkfs.ext4 /dev/nvme2n1p1Keeping the 5% root reserve on a 4 TB data volumeThat's 200 GB nobody can use; the reserve only protects system daemons on the root filesystem.
sudo mkfs.ext4 -m 1 ... or later: sudo tune2fs -m 1 /dev/nvme2n1Try these on a Linux machine of your own. Each task has a hint and a solution.
Create a 256 MB image file and put an ext4 filesystem with the label 'lab' on it.
Confirm the filesystem type, label and UUID of lab.img.
Without writing anything, find out where the backup superblocks of lab.img would be.
Reformat lab.img with four times the default number of inodes and compare with tune2fs.
mkfsCreate a filesystem on a disk or partition
mkfs writes a new, empty filesystem (ext4, xfs, vfat...) onto a disk or partition so it can be mounted and hold files. It is how a fresh cloud volume becomes usable, and it destroys whatever was on the device before.
mkfs.TYPE [options] DEVICE (mkfs -t TYPE DEVICE is the same)A new, empty 100G volume (nvme2n1) needs a filesystem before you can mount it on /archive.
sudoWriting to a raw block device needs root.
mkfs is a small front end: mkfs -t ext4 runs mkfs.ext4, which is mke2fs from e2fsprogs; mkfs.xfs comes from xfsprogs. mke2fs opens the device, asks the kernel for its size and sector size, and on SSDs and EBS first sends discard (TRIM) for the whole device. It then divides the space into block groups (32768 blocks of 4 KiB = 128 MiB each) and writes a superblock with a new random UUID, backup superblocks in some groups (block 32768, 98304...), group descriptors, block and inode bitmaps, inode tables and a journal. The number of inodes is fixed now: one per 16 KiB by default, which is why millions of tiny files can exhaust an ext4 filesystem. XFS instead creates allocation groups and allocates inodes on demand. Data blocks themselves are not zeroed, which is why mkfs on a large disk takes seconds, not hours.
-t TYPEWith plain mkfs: which filesystem to build (mkfs -t xfs = mkfs.xfs)-L LABELVolume label (ext4 up to 16 chars, xfs up to 12)-m PCT (ext4)Percentage reserved for root; default 5, 0-1 for pure data disks-i BYTES (ext4)One inode per BYTES of space; smaller = more inodes for small files-N NUM (ext4)Exact number of inodes to create-T TYPE (ext4)Usage profile from /etc/mke2fs.conf: small, news, largefile, huge-n (ext4)Dry run: print what would be done, including backup superblock locations-F (ext4) / -f (xfs)Force: overwrite an existing filesystem without asking-b SIZEBlock size, normally 4096-E nodiscard / -KSkip the initial TRIM (ext4 / xfs), useful on slow thin-provisioned storageRunning mkfs on a volume restored from a snapshotA snapshot volume already contains a filesystem with data. mkfs replaces it with an empty one.
sudo blkid /dev/nvme3n1 first; if it shows a TYPE, mount it insteadUsing -F / -f by habit to get past the promptThe prompt is the only thing standing between you and wiping the wrong device.
lsblk -f and blkid to identify the device, then mkfs without forcemkfs.ext4 /dev/nvme2n1 after creating partition nvme2n1p1Formatting the whole disk overwrites the partition table you just created.
sudo mkfs.ext4 /dev/nvme2n1p1Keeping the 5% root reserve on a 4 TB data volumeThat's 200 GB nobody can use; the reserve only protects system daemons on the root filesystem.
sudo mkfs.ext4 -m 1 ... or later: sudo tune2fs -m 1 /dev/nvme2n1Try these on a Linux machine of your own. Each task has a hint and a solution.
Create a 256 MB image file and put an ext4 filesystem with the label 'lab' on it.
Confirm the filesystem type, label and UUID of lab.img.
Without writing anything, find out where the backup superblocks of lab.img would be.
Reformat lab.img with four times the default number of inodes and compare with tune2fs.