Unable to mount Xen image that uses LVM

Issues related to applications and software problems
Post Reply
jamiehankins
Posts: 3
Joined: 2011/08/08 02:02:46

Unable to mount Xen image that uses LVM

Post by jamiehankins » 2011/08/08 02:40:25

Greetings,

The executive summary is that I have two questions.

1. What do I need to do to mount an img file that uses LVM internally?
2. If you gzip a file, and copy it over a network connection, if the file gunzips on the other end without an error, can you be reasonably sure that the file made it intact?

I need to be able to mount and access a partition on an img file for a Xen DomU domain that's using LVM internally. I found a lot of different instructions online involving using losetup and kpartx. Unfortunately, kpartx doesn't like the image file.

Here's what happens when I try to follow the directions for using losetup and kpartx:
[code]
[root@mcp phoneserver]# ls -l /home/vm/phoneserver/phoneserver.bin
-rwxr-xr-x 1 qemu qemu 40741579776 Aug 7 01:13 /home/vm/phoneserver/phoneserver.bin
[root@mcp phoneserver]# fdisk -lu /home/vm/phoneserver/phoneserver.bin
You must set cylinders.
You can do this from the extra functions menu.

Disk /home/vm/phoneserver/phoneserver.bin: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001fb1b

Device Boot Start End Blocks Id System
/home/vm/phoneserver/phoneserver.bin1 * 63 208844 104391 83 Linux
/home/vm/phoneserver/phoneserver.bin2 208845 83875364 41833260 8e Linux LVM
Partition 2 has different physical/logical endings:
phys=(1023, 254, 63) logical=(5220, 254, 63)
[root@mcp phoneserver]# losetup /dev/loop0 /home/vm/phoneserver/phoneserver.bin
[root@mcp phoneserver]# kpartx -av /dev/loop0
add map loop0p1 (253:3): 0 208782 linear /dev/loop0 63
device-mapper: resume ioctl failed: Invalid argument
create/reload failed on loop0p2
add map loop0p2 (0:0): 0 83666520 linear /dev/loop0 208845
[/code]

Now, for those with the patience, here's the long version.

On my home CentOS server using Xen, I was running a virtual Win2K3 domain controller and a virtual CentOS 5.6 instance running an Asterisk PBX. I was having a little bit of strange behavior from my host OS. I read that Centos 6 was out, so I decided it was time to take the plunge.

I gzipped and copied the img files from my server to my Windows Home Server using cifs (Samba).

After cleaning and reinstalling, I managed to get my Win2K3 server running under KVM. However, the Asterisk (CentOS 5.6) guest would not boot. It brings up the grub screen, and when you choose to boot, it gets to the first line and hangs. I tried changing the VirtIO interface to a virtualized IDE drive to no avail. Nothing I've tried has made this VM boot.

Moving along to a different strategy, I decided to try to access the virtual hard drive image. I found that following the defaults when I installed CentOS 5.5 made me wind up with a virtual LVM drive which is not easily mountable.

My gut feeling is that my hard drive image has somehow gotten corrupted. I don't know a lot about gzip, but shouldn't it complain when I try to unzip the image, if it's corrupted? I still have my gzipped copy.

If you guys don't have any magic bullets for me, I guess my last best hope is to set up a CentOS 5.6 machine with a Xen server on it and hope that the VM boots there.

Sorry for the length of this, and I'll appreciate any advice you have. Oh, and if you're wondering why I don't just restore from my back-up, this is a home system. There's nothing that I can't live without. Still, I should have been making backups, and I didn't.

Thanks,
Jamie

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Unable to mount Xen image that uses LVM

Post by TrevorH » 2011/08/08 10:18:13

This may not be the correct way to do it but after the losetup, have you tried to see if `fdisk -l /dev/loop0` works? If it does then the chances are that running `pvscan` as root will detect the LVM partition on /dev/loopp2 and make the LVs inside it accessible to the system.

User avatar
WhatsHisName
Posts: 1549
Joined: 2005/12/19 20:21:43
Location: /earth/usa/nj

Unable to mount Xen image that uses LVM

Post by WhatsHisName » 2011/08/08 13:02:02

The only reason you would need to set up a loop (losetup) would be to partition the image file.

After deleting the loop, run kpartx on the image file directly.

[code]# losetup -d /dev/loop0

# kpartx -av /home/vm/phoneserver/phoneserver.bin

# vgscan

# vgchange -ay

# lvscan[/code]
Hopefully, your Dom0 and DomU use different VG names. Otherwise, you do NOT want to execute the above commands.

jamiehankins
Posts: 3
Joined: 2011/08/08 02:02:46

Re: Unable to mount Xen image that uses LVM

Post by jamiehankins » 2011/08/09 01:25:16

Hi TrevorH,

fdisk does see it via loop0, but pvscan doesn't see it.
[code]
[root@mcp phoneserver]# losetup /dev/loop0 /home/vm/phoneserver/phoneserver.bin
[root@mcp phoneserver]# fdisk -l /dev/loop0

Disk /dev/loop0: 40.7 GB, 40741579776 bytes
255 heads, 63 sectors/track, 4953 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: 0x0001fb1b

Device Boot Start End Blocks Id System
/dev/loop0p1 * 1 13 104391 83 Linux
/dev/loop0p2 14 5221 41833260 8e Linux LVM
[root@mcp phoneserver]# pvscan
PV /dev/sda2 VG vg_mcp lvm2 [1.82 TiB / 0 free]
Total: 1 [1.82 TiB] / in use: 1 [1.82 TiB] / in no VG: 0 [0 ]
[root@mcp phoneserver]#
[/code]

Thanks,
Jamie

jamiehankins
Posts: 3
Joined: 2011/08/08 02:02:46

Re: Unable to mount Xen image that uses LVM

Post by jamiehankins » 2011/08/09 01:36:22

Hi WhatsHisName,

Unfortunately, kpartx doesn't like accessing the file directly, either.

[code]
[root@mcp phoneserver]# kpartx -av /home/vm/phoneserver/phoneserver.bin
add map loop0p1 (253:3): 0 208782 linear /dev/loop0 63
device-mapper: resume ioctl failed: Invalid argument
create/reload failed on loop0p2
add map loop0p2 (0:0): 0 83666520 linear /dev/loop0 208845
[root@mcp phoneserver]#
[/code]

Some googling turned up a few hits with bug reports against kpartx, but it was all from years ago.

Anyone know the answer to question number 2? If I can gunzip a file, can I assume that it's intact? I know pkzip will give you a CRC error if you try to unzip a corrupt archive. If I can have confidence that the file really does contain my hard drive as it was, then it will be worth it for me to set up a CentOS 5.6 machine with Xen to try and boot it.

Thanks much for trying, guys.

Jamie

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Unable to mount Xen image that uses LVM

Post by TrevorH » 2011/08/09 09:24:54

[quote]
Anyone know the answer to question number 2?
[/quote]

Run `man gzip` and search for DIAGNOSTICS. It tells you about the exit codes and one of those is the file is corrupt.

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: Unable to mount Xen image that uses LVM

Post by pschaff » 2011/08/09 21:16:55

[quote]
jamiehankins wrote:
...
Anyone know the answer to question number 2?[/quote]
If it unzips without error you are probably OK, but as an additional check one could run md5sum or sha1sum on the source and destination files.

Post Reply