How to Safely Remove vmdk from Linux/Unix Virtual Host

In our previous article we told you how to add new storage/VMDK disk to your virtual machine and scan them at your machine without reboot and now in this article we are going to do the reverse. This article will tell you how to remove your unused or unwanted VMDK (Virtual Machine Disk) from your virtual machine without any reboot. The virtual machine is using UNIX/Linux operating system.


How to remove vmdk from Linux


Reasons to remove vmdk disk from Virtual Server


There are many situation where user wants to remove the vmdk disk from virtual machine.

I. Disk is unused and was added by mistake during build.

II. Want to replace with bigger vmdk disk [Though you can add other disk and make VG bigger].

III. Server going to retire soon and disk need to be reclaimed and should be returned to storage pool.

Or there may be some other reasons too.

Whatever may be the reason, removing disk properly and safely without touching any data is very important. Suppose you have to remove /dev/sdc but you removed /dev/sdb from virtual machine settings, then there can be a major outage in your environment and you will see lots of input/output errors.


Note: Do take backup before removing any disk


Steps to Remove VMDK disk from Virtual Linux/Unix Server


1. First of all take output of fdisk command and save it. Use below command to perform this task.

# fdisk -l | tee /tmp/fdisk-pre.out

fdisk pre output


2. The next important step is to unmount the filesystem. If the disk you want to remove is used by the filesystem then you will have to un-mount it first.

# umount /mount-point/

If you are getting device is busy error while unmounting filesystem, then use below command.

# umount -l /mount-point


3. If the disk in Volume group and you have created a logical volume, then remove that logical volume (LV) and then reduce your volume group (VG).

# lvremove /dev/mapper/vg1-lv1

If you have a separate VG from the physical volume (PV) that you want to remove, then you can directly remove the VG.

# vgreduce vg1 /dev/sdb

where vg1 is the name volume group and /dev/dsb is PV.

filesystem remove


4. Once you have remove the PV from volume group, you can now reduce physical volume. Use the below command.

# pvreduce /dev/sdb 

You can see above mentioned steps in above image. Now you have done initial steps.


Recommended Article: Understanding Concept of Striping, Mirroring & Parity


5. Now use below command to remove block device which will remove the device from your UNIX/LINUX machine.

echo "1" > /sys/block/sdx/device/delete

Where sdx is any disk which you want to remove.

Confirm by fdisk -l command and you can also compare with output of earlier taken fdisk command as shown below.

# diff /tmp/pre-fdisk /tmp/post-fdisk


fdisk comparison


Now as your disk has been removed from UNIX/Linux server without reboot, its time to remove the VMDK hard disk from virtual machine settings also.


6. Go to your virtual machine setting as shown below. And click on the advance hard disk setting and check its virtual disk node.


virtual machine hard disk setting


Generally its virtual hard disk naming convention is like below.

SCSI(0:0) -> /dev/sda
SCSI(0:1) -> /dev/sdb

So as we have to remove /dev/sdb we will check its node and for corresponding hard disk and will remove it.


Hard disk remove


Note: Remember don’t just remove hard disk with naming convention Hard Disk X as it may not correspond to correct /dev/sd.


This is how you remove VMDK disk from Linux/UNIX host safely and if you have any doubt or confusion in any steps do let us know. Don’t forget to share this article if you like it and do subscribe to our email newsletter for more tutorials.

Buy me a coffeeBuy me a coffee

Add Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.