On Linux systems, which command is used to create a new file system on a partition or block device before it can be mounted?
Computer Science
Linux
Difficulty: Easy
Choose an option
-
Afdisk
-
Bmkfs
-
Cfsck
-
Dmount
-
ENone of the above
Answer
Correct Answer: mkfs
Explanation
Introduction / Context:Before a partition or block device can be used for storing files, it must be formatted with a file system. Linux provides a specific command for this purpose, which abstracts details of different file system types.
Given Data / Assumptions:
- We have a new or unformatted partition or block device.
- We want to create a usable file system on it.
- Linux standard utilities are installed.
Concept / Approach:
The mkfs command ('make file system') initializes a partition with a chosen file system (ext4, xfs, vfat, etc.). Variants like mkfs.ext4 or mkfs.xfs provide specific implementations.
Step-by-Step Solution:
Identify device: lsblk or fdisk -l.Run: mkfs.ext4 /dev/sdb1 (example).Wait for formatting to complete.Mount the filesystem: sudo mount /dev/sdb1 /mnt.Verification / Alternative check:
Check with file -s /dev/sdb1 or blkid. Mount and verify with df -h.
Why Other Options Are Wrong:
- fdisk: partitions disks, does not format.
- fsck: checks and repairs file systems.
- mount: attaches a filesystem to a directory tree, does not create one.
- None: incorrect since mkfs is correct.
Common Pitfalls:
- Confusing partitioning with formatting.
- Accidentally formatting the wrong device (always double-check identifiers).
Final Answer:
mkfs.