There are many methods and tools for KVM mount disks, as follows:
(1) The RAW format disk can be mounted directly, or the QCOW2 format disk can be converted into raw format and mounted. Eg: the converted command is:
[Email protected] ~]# qemu-img convert-f raw-o qcow2 yz3_add.qcow2 yz3_add.img
Refer to the previous section for details.
(2) Mount the QCOW2 format disk by compiling the Install QEMU-NBD tool. The QEMU-NBD tool is not installed by default and needs to be compiled for installation.
(3) Create a KVM virtual machine profile by creating a KVM environment mount the virtual machine disk to boot the virtual machine. This content lesson refers to six of the contents (KVM Virtualization Note (vi)------The cloning of a KVM virtual machine)
(4) Test with the Libguestfs-tools tool.
This article is mainly testing the Libguest-tools tool for testing, the steps are as follows:
1, first confirm whether the Libguestfs-tools tool is installed, do not have the words can be installed yum.
[[email protected] ~] #install libguestfs-tools[[email protected] ~]# rpm -qa|grep libguestfs-toolslibguestfs-tools-1.20.11-14.el6.x86_ 64libguestfs-tools-c-1.20.11-14.el6.x86_64[[email protected] ~]# virvirsh virt-image virt-resizevirt-alignment-scan virt-inspector virt-sparsifyvirt-cat virt-inspector2 virt-sysprepvirt-clone virt-install virt-tarvirt-convert virt-list-filesystems virt-tar-invirt-copy-in virt-list-partitions virt-tar-outvirt-copy-out virt-ls virt-topvirt-df virt-make-fs virt-v2vvirt-edit virt-manager virt-viewervirt-filesystems virt-p2v-server virt-win-regvirt-format virt-pki-validate &nbsP; virt-xml-validatevirt-host-validate virt-rescue
Command format:-D with domain name,-A is the way to get the disk file directly
VIRT-DF [--options]-D DOMNAMEVIRT-DF [--options]-a disk.img [-a disk.img ...]
2,virt-cat命令,可直接查看虚拟机的文件,类似于cat,(开关机都可以)
[[Email protected] ~]# virt-cat -d hadoop1 /etc/passwdroot:x:0:0:root:/root:/bin /bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/ nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/ sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinuucp:x:10:14:uucp:/ var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/ Nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:ftp user:/var/ftp:/sbin/nologinnobody:x : 99:99:nobody:/:/sbin/nologinvcsa:x:69:69:virtual console memory owner:/dev:/sbin/ nologinsaslauth:x:499:76: "Saslauthd user":/var/empty/saslauth:/sbin/nologinpostfix:x:89:89::/var/spool/ postfix:/sbin/nologinsshd:x:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologin[[email protected] ~]#
3,virt-edit命令,可直接编辑虚拟机里面的文件,类似于vi编辑器(注意:该虚拟机必须处于关机状态)
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7A/C7/wKiom1a1YsuRG22hAACC-8M8WCI275.png "title=" 1.png "alt=" Wkiom1a1ysurg22haacc-8m8wci275.png "/>
[[email protected] ~]# virt-edit -d hadoop3 /etc/sysconfig/selinux # this file controls the state of selinux on the system.# SELINUX= can take one of these three values:# enforcing - selinux security policy is Enforced.# permissive - selinux prints warnings instead of enforcing.# disabled - No SELinux policy Is loaded. selinux=disabled# selinuxtype= can take one of these two values:# targeted - Targeted processes are protected,# mls - multi level security protection. Selinuxtype=targeted
4,virt-df command, you can directly see the virtual machine inside the disk usage, similar to the df-h command, (switch can).
[[email protected] ~]# virt-df -h hadoop1filesystem Size Used Available Use%hadoop1:/dev/sda1 484M 32m 427m 7 %hadoop1:/dev/volgroup/lv_root 18g 733m 17g 4%[[email protected] ~]# virt-df -h hadoop4Filesystem Size Used available use%hadoop4:/dev/sda1 484M 32m 427m 7% hadoop4:/dev/volgroup/lv_root 12g 731m 11g 6%[[email protected] ~]# virsh list --all Id Name &nbsP; state---------------------------------------------------- 1 win7 running 17 hadoop1 running 18 hadoop4 running 20 hadoop2 running - hadoop3 &nbSp; shut off
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7A/C6/wKioL1a1Y_mjVCD0AACBq829jrA248.png "title=" 2.png " alt= "Wkiol1a1y_mjvcd0aacbq829jra248.png"/>
5,virt-filesystems command, but also view the use of the disk, and the VIRT-DF command similar (switching machine can be) 650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7A/C6/wKioL1a1ZP_g4EyOAABlBKeAhWY373.png "title=" 3. PNG "alt=" Wkiol1a1zp_g4eyoaablbkeahwy373.png "/>
The 6,virt-copy-out command directly copies the disk files from the virtual machine to the local disk, similar to the CP command, and is divided into two scenarios, such as:
(1) Copy the disk file from the virtual machine HADOOP1 to the local directory/tmp/install (copy file)
[Email protected] ~]# virt-copy-out-d Hadoop1/etc/passwd/tmp/install
(2) Copy the directory from the virtual machine Hadoop1/etc/init.d/to the local/tmp/install/(copy directory)
[Email protected] ~]# virt-copy-out-d hadoop1/etc/init.d//tmp/install
Results such as:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7A/C7/wKiom1a1ZkqS53fnAABut6vdbok503.png "title=" Qq20160205164819.png "alt=" Wkiom1a1zkqs53fnaabut6vdbok503.png "/>7, view all the disk files for the virtual machine.
[Email protected] ~]# Virsh domblklist hadoop1target Source------------------------------------------------VDA /IMAGES/TEST/HADOOP1.QCOW2VDB/IMAGES/TEST/HADOOP1_ADD01.QCOW2HDC-
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7A/C7/wKioL1a1Z3_ymfxXAACBdVODVPE212.png "title=" 1.png " alt= "Wkiol1a1z3_ymfxxaacbdvodvpe212.png"/>8, directly read the contents of the disk File
[Email protected] ~]# virt-copy-out-a/images/test/hadoop2.img-a/images/test/hadoop1_add01.qcow2/etc/sysconfig/ network-scripts/ifcfg-eth0/root/
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7A/C7/wKioL1a1bKjBLcqoAADarYCP07k339.png "title=" Qq20160205164819.png "alt=" Wkiol1a1bkjblcqoaadarycp07k339.png "/>9,virt-copy-in command, directly virtualize the local disk on the platform to the virtual machine disk, Similar to CP (virtual machine must be in shutdown state, power-on verification)
[[email protected] install]# virt-copy-in-d hadoop1/tmp/install/nginx.tar.gz/tmp/[[email protected] install]# Virsh St Art Hadoop1domain Hadoop1 started
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7A/C7/wKiom1a1ca7w7MCgAAAvka8n5uQ971.png "title=" 1.png " alt= "Wkiom1a1ca7w7mcgaaavka8n5uq971.png"/>
If an error occurs:" errors:[email protected]:/usr/bin# virt-copy-in-d yz/tmp/install/jdk-8u51-linux-x64.rpm/ Root
/usr/bin/virt-copy-in:line 19:exec:guestfish:not found"cause is not installed guestfish cause, can be installed to execute this command yum install GUESTFISH-Y automatic installation can be viewed.
This article is from the "Breght Moon" blog, make sure to keep this source http://liqingbiao.blog.51cto.com/3044896/1741306
KVM Virtualization Notes (12)------The read of the KVM virtual machine disk File