Hot-add and hot-remove a disk on a running server VM
Task
Add a disk to a running server without shutting it down, confirm the operating system detected it, then remove it safely the right way round: take it out of use in the operating system first, then detach it. Watching the kernel log while you do it shows exactly what hot-swap means from the server's side.
Steps
- Start
journalctl -kf(ordmesg -w) in one session on lin-srv and leave it running. - In the hypervisor, attach a new 1 GB virtual disk to the running VM. Save
lsblktolab/hotswap/after-add.txtand copy the kernel messages about the new disk tolab/hotswap/kernel-add.txt. - Partition and mount the new disk, write a file to it, and record the mount point in
lab/hotswap/mount.txt. - Remove it safely: unmount it, then tell the kernel to release it with
echo 1 > /sys/block/<disk>/device/delete, and only then detach it in the hypervisor. Savelsblktolab/hotswap/after-remove.txt. - Write
lab/hotswap/order.txtwith the correct order for replacing a hot-swap drive in a real server, from identifying the drive to confirming the rebuild.
Verify
These checks run in a POSIX shell: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. A stock Windows PowerShell or Command Prompt has no awk or grep, so there the first line fails.
wc -l < lab/hotswap/after-add.txt
wc -l < lab/hotswap/after-remove.txt
grep -Eic 'sd[a-z]|attached|scsi' lab/hotswap/kernel-add.txt
grep -Eic 'locate|identify|slot' lab/hotswap/order.txt
The listing after the add must be longer than the listing after the removal, and the kernel messages must show the new disk attaching. Your order must include identifying the correct drive, by its locate LED or slot number, before pulling anything -- the most common hot-swap mistake is removing a healthy disk from a degraded array.
Notes
Hot-swap is a property of the whole chain: the backplane, the controller, the driver and the operating system. A drive that is physically hot-swappable in a controller that does not support it is only swappable with the power off.
This is an independent study companion for CompTIA Server+ SK0-005 and is not produced by or endorsed by CompTIA.