Access to logical volumes in domU from the dom0
I currently run a Fedora 8 dom0 with Fedora 9 domU's primarily. I'm working on exactly how I wish to configure the disk layout, but here is how to configure each domU on it's own logical volume, configure further logical volumes within that domU, and how to access those logical volumes from the host dom0.
The domU's live inside a VG across the SAN named VGSanLun10. Each domU gets a dedicated LV with a unique name. Because, I believe even arbitrary things should have a predictable rational behind them, I generate a private MAC addresses for the domU by appending the unix time in hex to 'AA00'. I could use the name of the domU as the name of the LV, but that could change and hex numbers are more sexy, this unique identifier makes for a good string to put in the LV name.
#!/bin/bash
# spit out a MAC based on current time and UUID based on that MAC
# use this for virtual machine definitions
MAC_PREFIX='AA:00'
generate_mac () {
# create a MAC based on the time
date=$(printf "%02X\n", `date +%s`)
MAC=$MAC_PREFIX
i=1;
while [ $i -lt 8 ]; do
pair=`echo $date | cut -c${i}-$(($i + 1))`
MAC=${MAC}:$pair
((i=$i + 2));
done
}
generate_uuid () {
if [ -n "$MAC" ]; then
UUID=00000000-0000-0000-0000-`echo $MAC | sed s/://g`
fi
}
generate_mac
generate_uuid
echo "export MAC=$MAC"
echo "export UUID=$UUID"
So, domU with MAC AA00485BE004 gets a dom0 LV named LVDomUAA00485BE004 on VG VGSanLun10. Inside this LV block device the domU names its VG VGDomU. It is important that this VG have a name that is distinct from any VG found in dom0. Otherwise things will get ugly when you try to access domU volume group on dom0.
Here's the config I'm currently using.
- Assuming in the dom0 you create a LV for use by the domU thusly:
lvcreate --name 'LVDomUAA00485BE004' --size '10G' 'VGSanLun10'
- And assuming in the domU you split that 10G up in kickstart thusly:
zerombr clearpart --all --initlabel # raw partition for boot part /boot --fstype ext3 --size=100 # physical volume on remainder part pv.01 --size=1 --grow # LVM on physical volume - make sure VG name is not used in dom0 volgroup VGDomU pv.01 logvol / --fstype=ext3 --name=LVRoot --vgname=VGDomU --size=512 logvol /var --fstype=ext3 --name=LVVar --vgname=VGDomU --size=1024 logvol /usr --fstype=ext3 --name=LVUsr --vgname=VGDomU --size=2048 logvol /home --fstype=ext3 --name=LVHome --vgname=VGDomU --size=100 logvol swap --fstype swap --name=LVSwap --vgname=VGDomU --size=512 # install grub bootloader --location=mbr --driveorder=xvda --append="console=hvc0"
- When domU is down, you may read from the dom0 command line thusly:
kpartx -av /dev/VGSanLun10/LVDomUAA00485BE004 # informative trivia for before/after comparison lvs vgscan # it's assumed VGDomU is not used in the dom0 LVM config vgchange -ay VGDomU mkdir -p /mnt/LVDomUAA00485BE004 mount /dev/mapper/VGDomU-LVRoot /mnt/LVDomUAA00485BE004 mount /dev/mapper/VGDomU-LVUsr /mnt/LVDomUAA00485BE004/usr mount /dev/mapper/VGDomU-LVVar /mnt/LVDomUAA00485BE004/var mount /dev/mapper/VGDomU-LVHome /mnt/LVDomUAA00485BE004/home mount /dev/mapper/LVDomUAA00485BE0041 /mnt/LVDomUAA00485BE004/boot
- Do what you need to do then besure to unmount and deactivate before booting domU again:
umount /mnt/LVDomUAA00485BE004/usr umount /mnt/LVDomUAA00485BE004/var umount /mnt/LVDomUAA00485BE004/home umount /mnt/LVDomUAA00485BE004/boot umount /mnt/LVDomUAA00485BE004 vgchange -an VGDomU kpartx -dv /dev/VGSanLun10/LVDomUAA00485BE004
- dale's blog
- Login or register to post comments

Recent comments
50 weeks 2 days ago
50 weeks 2 days ago
1 year 9 weeks ago
1 year 38 weeks ago
1 year 38 weeks ago
1 year 50 weeks ago
2 years 5 weeks ago
2 years 5 weeks ago
2 years 6 weeks ago
2 years 6 weeks ago