Skip to content

Instantly share code, notes, and snippets.

@alambike
Last active August 29, 2015 14:22
Show Gist options
  • Save alambike/dfe912fc22a5f35e0584 to your computer and use it in GitHub Desktop.
Save alambike/dfe912fc22a5f35e0584 to your computer and use it in GitHub Desktop.
Remove a block device
Ensuring a Clean Device Removal
* Close all users of the device and backup device data as needed.
* Use umount to unmount any file systems that mounted the device.
* Remove the device from any md and LVM volume using it. If the device is a member of an LVM Volume group, then it may be necessary to move data off the device using the pvmove command, then use the vgreduce command to remove the physical volume, and (optionally) pvremove to remove the LVM metadata from the disk.
* If the device uses multipathing, run multipath -l and note all the paths to the device. Afterwards, remove the multipathed device using multipath -f device.
* Run blockdev –flushbufs device to flush any outstanding I/O to all paths to the device. This is particularly important for raw devices, where there is no umount or vgreduce operation to cause an I/O flush.
* Remove any reference to the device's path-based name, like /dev/sd, /dev/disk/by-path or the major:minor number, in applications, scripts, or utilities on the system. This is important in ensuring that different devices added in the future will not be mistaken for the current device.
* Finally, remove each path to the device from the SCSI subsystem. To do so, use the command **echo 1 > /sys/block/device-name/device/delete** where device-name may be sde, for example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment