Unplugging an LVM partitioned USB drive

Recently I had the heartbreaking experience of having to reboot a Linux server. Normal usage should almost never require you to reboot the OS like you have to so frequently in Windows. In this case I had an external USB drive partitioned with LVM humming along on a Linux server. I needed to pull the drive, so like I’ve done with other drives I unmounted all partitions on the drive. Then proceeded to unplug it from the USB port. All well and good. But when I plugged it back in, the lvs command was showing error messages on the partitions and I was unable to mount them.

Some Google searches later I found that when it comes to LVM partitions the OS keeps references to it unless you explicitly tell it to unhook them. Only then can you tell the OS to hook the LVM partitions back up when you’ve plugged the drive back in. In my case I had to resort to rebooting the server in order for the OS to hook all the pieces together for the LVM partitions. Short of this I would have to manually delete certain files and move things around to get the LVM partitions to work again. So here are the magic incantations that will save you the headache.

Before you unplug an LVM partitioned USB drive, you must run the following commands:

lvchange -an /dev/your_volume_group_name
vgexport -a

Use the man command to explore what these commands do.

Now you should be able to unplug the drive. When you are ready to plug it back in, stick it back in the USB port and run the following commands:

vgimport -a
lvchange -ay /dev/your_volume_group_name

You should now be able to run lvs and see you LVM partitions on the USB drive without any errors and proceed to mount the partitions.

Hope you found this useful. Are there other or different ways of doing this? Please add your comments below and Happy Holidays!


  1. Thanks for this! I spent a whole day trying to figure out why I couldn’t mount an lvm partitioned drive that I had hot-plugged. This is just what I needed!

  2. Just what I needed, thanks.

    In some cases you may find `partprobe` useful when `vgimport -a` doesn’t do the trick: this makes the kernel reexamine all partition tables.

  3. It is not a good idea to use vgexport for unplugging. I have a device allowing to connect almost any IDE and SATA disk via USB. I used this to make a backup on another computer because my computer had HW problems. If vgexport is used and the root directory is on LVM, Linux will not boot. I had to boot a Live Linux and use vgimport.

Comments are closed.