Hot-add and hot-remove a disk on a running server VM

short · 30 min · Objective 1.3

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

  1. Start journalctl -kf (or dmesg -w) in one session on lin-srv and leave it running.
  2. In the hypervisor, attach a new 1 GB virtual disk to the running VM. Save lsblk to lab/hotswap/after-add.txt and copy the kernel messages about the new disk to lab/hotswap/kernel-add.txt.
  3. Partition and mount the new disk, write a file to it, and record the mount point in lab/hotswap/mount.txt.
  4. 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. Save lsblk to lab/hotswap/after-remove.txt.
  5. Write lab/hotswap/order.txt with 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.