Remove a disk from Redhat/Centos Linux without rebooting the system

Once a disk/lun is no longer required, it is a good practice to remove the disks cleanly from the system and tidy up. What more? this can be done without a server reboot.

IMPORTANT! As always, ensure that the disks are no longer in use by any file systems, logical volumes, volume groups or most importantly raw devices.

The task of removing the disk device is a 2 step process and this is how we do it. Here /dev/sdc is the disk we want to remove from the host

1. Mark the device as OFFLINE

[root@pulpserver1 host1]# echo "offline" > /sys/block/sdc/device/state

2. Delete disk from system

[root@pulpserver1 host1]# echo "1" > /sys/block/sdc/device/delete

This should remove the disk and clean up entries under /dev/ and fdisk cannot see the disk any longer.

[root@pulpserver1 host1]# fdisk -l

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003d9c2

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39        2358    18631680   83  Linux
/dev/sda3            2358        2611     2031616   82  Linux swap / Solaris

Disk /dev/sdd: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vgtest-lvtest: 1069 MB, 1069547520 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Leave a Reply

Your email address will not be published. Required fields are marked *