Problem:
In RedHat, how do you mount a KVM image with an LVM partition? Some of the files in the image, like "/etc/sysconfig/ifcfg-eth0" & "/etc/sysconfig/network" need to be edited before use.
Solution:
From the KVM host, use a combination of "kpartx" & "lvchange" command line tools.
Procedure:
1. Install kpartx rpm through yum.
yum install kpartx
2. Install lvm2 rpm through yum.
yum install lvm2
3. Use "kpartx" to read partition tables & create device maps of your image.
kpartx -av <image path>.img
Example:
[root@test1-server ~]# kpartx -av /home/images/test1.img
add map loop0p1 (253:6): 0 1024000 linear /dev/loop0 2048
add map loop0p2 (253:7): 0 30428928 linear /dev/loop0 1026048
4. Use "pvscan" to see your LVM block devices for physical volume.
Example:
[root@test1-server ~]# pvscan
PV /dev/mapper/loop0p2 VG vg_or2svmqawmgr1 lvm2 [14.51 GiB / 0 free]
5. Use "vgscan" to see your LVM physical volumes & volume groups.
Example:
[root@test1-server ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg_test1" using metadata type lvm2
6. Use "lvscan" to see your LVM block devices for logical volumes.
Example:
[root@test1-server ~]# lvscan
inactive '/dev/vg_test1/lv_root' [10.75 GiB] inherit
inactive '/dev/vg_test1/lv_swap' [3.75 GiB] inherit
7. Use "lvchange" to activate the logical volume, to make it useable.
lvchange -ay <volume group name>
Example:
[root@or14svm-rsvr3 vm_xml_files]# lvchange -ay vg_test1
[root@test1-server ~]# lvscan
ACTIVE '/dev/vg_test1/lv_root' [10.75 GiB] inherit
ACTIVE '/dev/vg_test1/lv_swap' [3.75 GiB] inherit
8. Create the directory for mounting the logical volume, then mount it, and start editing your files.
Example:
mkdir /mnt/partition
mount /dev/vg_test1/lv_root /mnt/partition
cd /mnt/partition
ls
Reverse Procedure:
1. Unmount the logical volume.
Example:
cd $HOME
umount /mnt/partition
2. Use "lvchange" to deactivate the logical volume.
lvchange -an <volume group name>
Example:
[root@or14svm-rsvr3 vm_xml_files]# lvchange -an vg_test1
[root@test1-server ~]# lvscan
inactive '/dev/vg_test1/lv_root' [10.75 GiB] inherit
inactive '/dev/vg_test1/lv_swap' [3.75 GiB] inherit
3. Use "vgchange" to deactivate the volume group.
lvchange -an <volume group name>
Example:
[root@test1-server ~]# vgchange -an vg_test1
0 logical volume(s) in volume group "vg_test1" now active
4. Use "kpartx" to delete device maps of your image.
kpartx -dv <image path>.img
Example:
[root@test1-server ~]# kpartx -dv /home/images/test1.img
del devmap : loop0p2
del devmap : loop0p1
loop deleted : /dev/loop0
Reference:
http://support.citrix.com/article/CTX117791/
Monday, August 6, 2012
Friday, February 10, 2012
Finding out the KVM client IP address, without running virt-manager
Problem:
In RedHat, how do you find out the IP address of KVM client from the hypervisor it's running on, without starting virt-manager?
Solution:
From the kvm host or hypervisor, use "virsh dumpxml [servername]" to get the kvm client MAC address & the network interface its using. Then use "arp" or "tcpdump" to get its IP address.
Procedure:
1. Login to the kvm host/hypervisor and issue the command: virsh dumpxml [server name].
Example: virsh dumpxml test1-server
2. From the xml output, look for the MAC address & interface entry, which looks something like this:
3. Use "arp -a" to query for the IP address.
[testuser@test1-server ~]$ arp -a
test-client1.apollo.com (192.168.1.120) at 63:54:00:3f:46:5a [ether] on br0
test-client2.apollo.com (192.168.1.125) at 63:54:00:bb:e7:90 [ether] on br0
test-client3.apollo.com (192.168.1.9) at 01:25:45:b3:6d:84 [ether] on br0
4. If "arp -a" does not match the xml MAC address you're looking for, use the old reliable "tcpdump".
[testuser@test1-server ~]$ sudo tcpdump -vv -i br0 | grep 63:54:00:49:f4:87
tcpdump: listening on br0, link-type EN10MB (Ethernet), capture size 65535 bytes
12:31:08.887230 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.1.118 is-at 63:54:00:49:f4:87 (oui Unknown), length 28
12:32:08.000218 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.1.118 is-at 63:54:00:49:f4:87 (oui Unknown), length 28
12:32:32.121785 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.1.118 is-at 63:54:00:49:f4:87 (oui Unknown), length 28
Reference:
http://rwmj.wordpress.com/2010/10/26/tip-find-the-ip-address-of-a-virtual-machine/
In RedHat, how do you find out the IP address of KVM client from the hypervisor it's running on, without starting virt-manager?
Solution:
From the kvm host or hypervisor, use "virsh dumpxml [servername]" to get the kvm client MAC address & the network interface its using. Then use "arp" or "tcpdump" to get its IP address.
Procedure:
1. Login to the kvm host/hypervisor and issue the command: virsh dumpxml [server name].
Example: virsh dumpxml test1-server
2. From the xml output, look for the MAC address & interface entry, which looks something like this:
3. Use "arp -a" to query for the IP address.
[testuser@test1-server ~]$ arp -a
test-client1.apollo.com (192.168.1.120) at 63:54:00:3f:46:5a [ether] on br0
test-client2.apollo.com (192.168.1.125) at 63:54:00:bb:e7:90 [ether] on br0
test-client3.apollo.com (192.168.1.9) at 01:25:45:b3:6d:84 [ether] on br0
4. If "arp -a" does not match the xml MAC address you're looking for, use the old reliable "tcpdump".
[testuser@test1-server ~]$ sudo tcpdump -vv -i br0 | grep 63:54:00:49:f4:87
tcpdump: listening on br0, link-type EN10MB (Ethernet), capture size 65535 bytes
12:31:08.887230 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.1.118 is-at 63:54:00:49:f4:87 (oui Unknown), length 28
12:32:08.000218 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.1.118 is-at 63:54:00:49:f4:87 (oui Unknown), length 28
12:32:32.121785 ARP, Ethernet (len 6), IPv4 (len 4), Reply 192.168.1.118 is-at 63:54:00:49:f4:87 (oui Unknown), length 28
Reference:
http://rwmj.wordpress.com/2010/10/26/tip-find-the-ip-address-of-a-virtual-machine/
Subscribe to:
Posts (Atom)