mounting partitions in a logical volume used as a physical disk for a virtual machine

Kees Cook kees at ubuntu.com
Thu Mar 5 00:18:29 UTC 2009


Hi James,

On Wed, Mar 04, 2009 at 05:06:01PM -0600, James Dinkel wrote:
> I have an lvm volume group that I use as my storage pool and on the host I
> would like to mount a partition from one of the logical volumes used as a
> virtual drive.
> 
> I would guess that this would be similar to mounting a disk image file, but
> I can't even find good instructions for doing that.  All I've found is to do
> this:
> 
> sudo mount -o loop,offset=32256 <image-file> /mnt/folder -t vfat
> 
> but what if the partition is not fat, or if it's not the first partition?

If I'm understanding correctly, you have a host LV serving as a full drive
for a guest, and you want to mount the partitions that are stored within
that LV?

You probably want "kpartx", which will build a dm device for each
partition, based on the partition table it finds:

set up the dm slices:
sudo kpartx -a /dev/storagevg/drivelv
ls -l /dev/mapper/loop0p*

and to mount partition 2:
sudo mount /dev/mapper/loop0p2 /mnt/folder .....

after you're done:
sudo kpartx -d /dev/storagevg/drivelv


e.g. I've used this tool when converting KVM images:
http://www.outflux.net/blog/archives/2008/09/03/kvm-disk-image-filesystem-growth-notes/

-- 
Kees Cook
Ubuntu Security Team




More information about the ubuntu-server mailing list