LVM + USB drive

Itay's picture

Forums: 

I'd like to set up a USB drive using LVM. Could someone knowledgable
confirm that the following recipe should allow me to hot-plug the
USB drive without rendering the LVM file-systems inaccessible?

Many thanks.
Itay

Recipe follows:

Set up:
# (Actual number of partitions, etc., is not important here.)

# Assume attached disk is /dev/sdc and it has an extended partition
#+ that covers that whole disk.

# Prepare partitions for LVM (say, 2 partitions)
$ parted /dev/sdc mkpart logical START1 END1
$ parted /dev/sdc mkpart logical START2 END2
# Create Physical Volumes
$ pvcreate /dev/sdc1
$ pvcreate /dev/sdc2
# Identify the Physical Volumes' UUIDs
$ blkid
# Create Volume Groups using PVs **UUIDs**
$ vgcreate [options] myVG /dev/disk/by-uuid/UUID-OF-PART-1
$ vgexted [options] myVG /dev/disk/by-uuid/UUID-OF-PART-2
# From this point I can "forget" that I deal with a USB drive, and
#+ continue the set up as with built in drives; right?

Usage:

# (Based on advice here:
# http://blogs.sourceallies.com/2009/12/unplugging-an-lvm-partitioned-usb-drive/
# )

# Before unplugging
$ umount /mnt/point/of/lvm
$ lvchange -an /dev/myVG
$ vgexport -a
# After plugging-in
$ vgimport -a
$ lvchange -ay /dev/myVG
$ mount [options] /mnt/point/of/lvm

# (Question: vgexport/import is needed if volume groups are identified
# by UUID?)

Thanks.

LVM + USB drive

Ron Johnson's picture

On 05/30/2011 02:56 AM, Itay wrote:
>
[snip]
> # )
>
> # Before unplugging
> $ umount /mnt/point/of/lvm
> $ lvchange -an /dev/myVG
> $ vgexport -a
> # After plugging-in
> $ vgimport -a
> $ lvchange -ay /dev/myVG
> $ mount [options] /mnt/point/of/lvm
>
> # (Question: vgexport/import is needed if volume groups are identified #
> by UUID?)
>

That's correct. You don't need vgexport/vgimport. I had (since moved
to a larger eSATA enclosure) a 2-bay USB enclosure and bonded the disks
in a "RAID 0" set.

# umount -v /mnt/point/of/lvm
# lvchange -an /dev/myVG

# lvchange an /dev/myVG
# mount -v /mnt/point/of/lvm

LVM + USB drive

Itay's picture

On Mon, 30 May 2011, Ron Johnson wrote:

>> [snip]
>>
>> # (Question: vgexport/import is needed if volume groups are identified #
>> by UUID?)
>
> That's correct. You don't need vgexport/vgimport. I had (since moved to a
> larger eSATA enclosure) a 2-bay USB enclosure and bonded the disks in a "RAID
> 0" set.

Thanks.
Itay