Xen: mount Windows domU residing on LV under Linux Mint dom0

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

Xen: mount Windows domU residing on LV under Linux Mint dom0

Postby powerhouse on Tue Sep 04, 2012 4:56 pm

This is for Xen users who run a Xen hypervisor and Linux Mint as dom0 and have a Windows virtual machine installed as domU on a LVM formatted partition.

LVM or logical volume manager is the recommended way of installing domUs onto a partition. I've written another how-to on installing Linux Mint 13 root and /home partitions onto LVs.

Once you have successfully created the Windows domU and installed Windows, you can also access the Windows file system from your Linux Mint dom0.

Warning: Don't mount your Windows domU under Linux in read-write mode while Windows is running - it may cause data loss

It's strongly advised to shut down the guest system BEFORE mounting it under dom0 as shown below !

Install kpartx:
Code: Select all
sudo apt-get install kpartx


List the partitions:
Code: Select all
sudo fdisk -l


The interesting part of fdisk -l is:
Device Boot Start End Blocks Id System
/dev/mapper/lm13-win7p1 * 2048 206847 102400 7 HPFS/NTFS/exFAT
/dev/mapper/lm13-win7p2 206848 125827071 62810112 7 HPFS/NTFS/exFAT


win7p1 is the boot partition, win7p2 is the actual Windows partition which I'm going to mount. lm13 is the volume group I created when installing my Linux Mint system.

Use kpartx to map the new LVs:
Code: Select all
sudo kpartx -av /dev/mapper/lm13-win7


Note: I didn't try /lm13-win7p2 which may also work.

Create a mount point:
Code: Select all
sudo mkdir /mnt/win7 # or wherever you want to mount your Windows partition


Code: Select all
ls /dev/mapper
gives me something like this:
control lm13-root lm13-win7p1 vol1-lm13_backup vol2-swap
lm13-home lm13-win7 lm13-win7p2 vol2-data


lm13-win7p2 is what I want.

Let's mount the Windows file system as NTFS, read-only:
Code: Select all
sudo mount -t ntfs -o ro /dev/mapper/lm13-win7p2 /mnt/win7


And check:
Code: Select all
ls /mnt/win7


Documents and Settings PerfLogs Recovery Users
hiberfil.sys ProgramData $Recycle.Bin Windows
NVIDIA Program Files System Volume Information
pagefile.sys Program Files (x86) temp


Note: Never mount the Windows domU file system under dom0 when it is up and running, unless in read-only mode..

Important: When you're done with the Windows partition,you must remove the partitions with kpartx -d:
Code: Select all
sudo kpartx -dv /dev/mapper/lm13-win7




That was easy.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Sapphire 7770 GPU, PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB SSD + various HD, Corsair 500R case, SeaSonic 660W Gold X PS
powerhouse
Level 5
Level 5
 
Posts: 649
Joined: Thu May 03, 2012 3:54 am

Linux Mint is funded by ads and donations.
 

Re: Xen: mount Windows domU residing on LV under Linux Mint

Postby powerhouse on Fri Nov 09, 2012 9:30 am

It might be worth noting that kpartx also works perfectly with .img files. I did a snapshot backup of my Windows 7 domU using the script below:
Code: Select all
#!/bin/sh
mv /media/tmp_stripe/lm13-win7.img /media/tmp_stripe/lm13-win7.img.old
lvcreate --size 10G --snapshot -n win7-snap /dev/lm13/win7
echo Creating backup copy of win7...
pv /dev/lm13/win7-snap | dd of=/media/tmp_stripe/lm13-win7.img
lvremove -f /dev/lm13/win7-snap
echo Finished

Notes:
1. /media/tmp_stripe/lm13-win7.img is the Windows 7 .img file (a backup of my virtual Xen Windows 7 "c:" drive).
2. /dev/lm13/win7 is the logical volume containing my Windows 7 installation under Xen: lm13 is the volume group; win7 the logical volume.
3. win7-snap is the snapshot partition of the win7 LV, which is used for backup. I gave it 10GB which is far more than you ever need, unless you create or change files in excess of 10GB during the backup. It actually only holds the changes to the files/file system while backing up, until the snapshot is deleted (removed).
4. "pv /dev/lm13/win7-snap | dd of=/media/tmp_stripe/lm13-win7.img" is the same as "dd if=/dev/lm13/win7-snap of=/media/tmp_stripe/lm13-win7.img", but gives a progress bar and ETA so you know how long to wait.

Now I can mount the .img file as a loop file with kpartx as follows:
Code: Select all
kpartx -av /media/tmp_stripe/lm13-win7.img

Watch the output of the above command.

To access the files, however, there are two more steps required. First we create a folder to mount the loop file in /mnt/win7:
Code: Select all
mkdir /mnt/win7


and then mount the Windows 7 partition:
Code: Select all
mount -t ntfs -o ro /dev/mapper/loop0p2 /mnt/win7


Now you got read access to the files in the .img backup file of a Xen Windows 7 domU. Of course this works as well with any other Xen domU virtual machine. Just adopt the mount -t ntfs to mount -t ext2 or whatever.

To close everything, do the following:
Code: Select all
umount /mnt/win7
kpartx -dv /media/tmp_stripe/lm13-win7.img


Again, adapt to your needs.
Asus Sabertooth X79, i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Sapphire 7770 GPU, PNY Quadro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB SSD + various HD, Corsair 500R case, SeaSonic 660W Gold X PS
powerhouse
Level 5
Level 5
 
Posts: 649
Joined: Thu May 03, 2012 3:54 am


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests