A system administrator needs to create a new ext4 filesystem on /dev/sdb1 and mount it persistently at /data. Which set of commands should be used?
Trap 1: mkfs.ext4 /dev/sdb1 && mount /dev/sdb1 /data
The command creates the ext4 filesystem but then attempts to mount it to /data without first creating that directory — mount(8) will fail with 'mount point /data does not exist'. Even if the directory existed, this sequence omits the /etc/fstab entry entirely, so the filesystem would not be mounted after a reboot. Persistence requires an fstab record, not just an immediate mount.
Trap 2: mkfs -t ext4 /dev/sdb1 && echo '/dev/sdb1 /data ext4 defaults 0 0'…
This sequence writes the fstab entry before verifying that the mount point exists and then issues mount /data with no device argument, which relies on fstab lookup but fails because /data is absent. Creating a filesystem and adding an fstab line for a nonexistent directory is invalid; the mount attempt would report that /data does not exist. The missing mkdir prevents both the immediate mount and any future boot-time mount from succeeding.
Trap 3: mkfs.ext4 /dev/sdb1 && mkdir /data && mount /dev/sdb1 /data &&…
Running blkid /dev/sdb1 outputs key=value data such as /dev/sdb1: UUID="..." TYPE="ext4", which is not a valid /etc/fstab line — fstab requires whitespace-separated fields: device (or UUID=), mount point, filesystem type, options, dump, and pass. Appending this raw output corrupts fstab and would cause mount -a to fail with a parsing error. The correct way to reference a filesystem by UUID in fstab is a line like UUID=... /data ext4 defaults 0 0.
- A
mkfs -t ext4 /dev/sdb1 && mkdir /data && mount /dev/sdb1 /data && echo '/dev/sdb1 /data ext4 defaults 0 0' >> /etc/fstab
This is the only complete sequence: mkfs -t ext4 /dev/sdb1 (equivalent to mkfs.ext4) creates a fresh ext4 filesystem, mkdir /data provides the required directory mount point, mount /dev/sdb1 /data attaches the filesystem for immediate use, and appending a correctly formatted fstab line ('/dev/sdb1 /data ext4 defaults 0 0') ensures the filesystem is mounted automatically at boot. The fstab line contains the six required fields in the correct order, making this the correct answer.
- B
mkfs.ext4 /dev/sdb1 && mount /dev/sdb1 /data
Why wrong: The command creates the ext4 filesystem but then attempts to mount it to /data without first creating that directory — mount(8) will fail with 'mount point /data does not exist'. Even if the directory existed, this sequence omits the /etc/fstab entry entirely, so the filesystem would not be mounted after a reboot. Persistence requires an fstab record, not just an immediate mount.
- C
mkfs -t ext4 /dev/sdb1 && echo '/dev/sdb1 /data ext4 defaults 0 0' >> /etc/fstab && mount /data
Why wrong: This sequence writes the fstab entry before verifying that the mount point exists and then issues mount /data with no device argument, which relies on fstab lookup but fails because /data is absent. Creating a filesystem and adding an fstab line for a nonexistent directory is invalid; the mount attempt would report that /data does not exist. The missing mkdir prevents both the immediate mount and any future boot-time mount from succeeding.
- D
mkfs.ext4 /dev/sdb1 && mkdir /data && mount /dev/sdb1 /data && blkid /dev/sdb1 >> /etc/fstab
Why wrong: Running blkid /dev/sdb1 outputs key=value data such as /dev/sdb1: UUID="..." TYPE="ext4", which is not a valid /etc/fstab line — fstab requires whitespace-separated fields: device (or UUID=), mount point, filesystem type, options, dump, and pass. Appending this raw output corrupts fstab and would cause mount -a to fail with a parsing error. The correct way to reference a filesystem by UUID in fstab is a line like UUID=... /data ext4 defaults 0 0.