CompTIA Linux+ (XK0-006)System ManagementMedium
A technician created a 2GB swap file with the commands 'fallocate -l 2G /swapfile' and 'chmod 600 /swapfile', then ran 'mkswap /swapfile'. Which command is required next to activate the swap file for immediate use?
- Amkfs.swap /swapfile
- Bswapon /swapfile
- Cfdisk /swapfile
- Dmount /swapfile
Show answer & explanationAnswer & explanation
Correct answer: B. swapon /swapfile
swapon activates the swap area so the kernel can use it. mount is used for filesystems, not swap areas; mkfs.swap is not a valid command since mkswap already formatted the file; fdisk is for disk partitioning, not files.
Why the other options are wrong
- A. Not a valid command; mkswap already formatted the swap file.
- C. fdisk manages disk partitions, not swap files.
- D. mount is used for regular filesystems, not swap areas.
Swap File Activation
Sequence to create and enable a swap file: allocate space, secure permissions, format as swap, then activate with swapon.
- fallocate/dd allocates file size
- chmod 600 restricts access for security
- mkswap formats the file as swap space
- swapon activates it; add to /etc/fstab for persistence
Memory trick: Allocate, lock, format, then switch ON the swap