Initialize the empty LV /dev/vgdata/lvswap as swap.
Enable it in a later step.
Which command is appropriate?
mkswap creates swap metadata. swapon is the separate operation that enables the initialized area.
Detailed explanation
swapon /dev/vgdata/lvswapIncorrect. swapon enables an already initialized swap area.
mkfs.ext4 /dev/vgdata/lvswapIncorrect. This creates an ext4 filesystem instead of swap.
mount /dev/vgdata/lvswap /swapIncorrect. Swap is not normally mounted as a regular filesystem.
mkswap /dev/vgdata/lvswapCorrect. mkswap initializes the target as swap.
Try it yourself
An example you can run in a temporary verification environment.
mkswap --help | sed -n '1,12p'Expected result
swap areaを設定するmkswapの使用法Key points
- mkswap initializes
- swapon enables
- Swap is not normally mounted
Notes
- Environment: util-linux mkswap / ヘルプ表示のみ
- Prefer help or version output and a disposable device when testing storage commands.
- Formatting, repair, and mount changes can affect data or availability.
Foundation review
Place the operation
Swap initialization and activation are separate stages from normal filesystem mounting.
Check the side effect
Confirm the intended device before writing a swap header.