Centos7 Kvm vm 磁盘文件读取
1、多种方式读取磁盘文件
#挂载读取,
#libguestfs-tools工具直接读取磁盘文件
2、libguestfs-tools工具
#libguestfs-tools-c命令工具
[root@node71 ~]# rpm -ql libguestfs-tools-c | grep /usr/bin
/usr/bin/guestfish
/usr/bin/guestmount
/usr/bin/guestunmount
/usr/bin/virt-alignment-scan
/usr/bin/virt-builder
/usr/bin/virt-cat
/usr/bin/virt-copy-in
/usr/bin/virt-copy-out
/usr/bin/virt-customize
/usr/bin/virt-df
/usr/bin/virt-diff
/usr/bin/virt-edit
/usr/bin/virt-filesystems
/usr/bin/virt-format
/usr/bin/virt-index-validate
/usr/bin/virt-inspector
/usr/bin/virt-log
/usr/bin/virt-ls
/usr/bin/virt-make-fs
/usr/bin/virt-rescue
/usr/bin/virt-resize
/usr/bin/virt-sparsify
/usr/bin/virt-sysprep
/usr/bin/virt-tar-in
/usr/bin/virt-tar-out
[root@node71 ~]#
#命令测试
[root@node71 ~]# vir
virsh virt-edit virt-make-fs virt-tar-out
virt-alignment-scan virt-filesystems virt-manager virt-v2v
virt-builder virt-format virt-p2v-make-disk virt-viewer
virt-cat virt-host-validate virt-p2v-make-kickstart virt-what
virt-clone virt-index-validate virt-pki-validate virt-win-reg
virt-copy-in virt-inspector virt-rescue virt-xml
virt-copy-out virt-install virt-resize virt-xml-validate
virt-customize virtlockd virt-sparsify
virt-df virt-log virt-sysprep
virt-diff virt-ls virt-tar-in
[root@node71 ~]# vir
3、virt-cat 查看vm中的文件信息
#vm可以是开机状态
[root@node71 ~]# virt-cat -d oel1 /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Oct 10 23:08:01 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
UUID=80333690-f7de-44e3-aa17-a58c6a4c9e03 /boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@node71 ~]# virsh list
Id 名称 状态
----------------------------------------------------
18 oel1 running
[root@node71 ~]# virt-cat -a /home/data/vm/oel1/oel1_qcow2.img /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Oct 10 23:08:01 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
UUID=80333690-f7de-44e3-aa17-a58c6a4c9e03 /boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@node71 ~]# virsh console oel1
连接到域 oel1
换码符为 ^]
Oracle Linux Server release 6.6
Kernel 3.8.13-44.1.1.el6uek.x86_64 on an x86_64
localhost.localdomain login: root
Password:
Last login: Fri Oct 14 05:12:26 on ttyS0
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Oct 10 23:08:01 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
UUID=80333690-f7de-44e3-aa17-a58c6a4c9e03 /boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@localhost ~]#
4、virt-df 查看磁盘使用情况
# 显示磁盘分区使用情况
[root@node71 ~]# virt-df oel1
Filesystem 1K-blocks Used Available Use%
oel1:/dev/sda1 487652 56871 401085 12%
oel1:/dev/VolGroup/lv_root 19003260 1581740 16433156 9%
[root@node71 ~]# virsh console oel1
连接到域 oel1
换码符为 ^]
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
19003260 1581740 16433156 9% /
tmpfs 251068 0 251068 0% /dev/shm
/dev/vda1 487652 56871 401085 13% /boot
[root@localhost ~]#
5、virt-log
#显示虚拟机的日志,vm可以是开机
[root@node71 ~]# virt-log -a /home/data/vm/oel1/oel1_qcow2.img
Oct 24 03:30:01 localhost rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="963" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
Oct 24 04:29:44 localhost init: serial (ttyS0) main process (1142) killed by TERM signal
Oct 24 04:29:44 localhost init: tty (/dev/tty2) main process (1146) killed by TERM signal
Oct 24 04:29:44 localhost init: tty (/dev/tty3) main process (1148) killed by TERM signal
Oct 24 04:29:44 localhost init: tty (/dev/tty4) main process (1150) killed by TERM signal
Oct 24 04:29:44 localhost init: tty (/dev/tty5) main process (1152) killed by TERM signal
Oct 24 04:29:44 localhost init: tty (/dev/tty6) main process (1154) killed by TERM signal
Oct 24 04:29:45 localhost acpid: exiting
Oct 24 04:29:45 localhost auditd[941]: The audit daemon is exiting.
Oct 24 04:29:45 localhost kernel: type=1305 audit(1477297785.679:49): audit_pid=0 old=941 auid=4294967295 ses=4294967295 subj=system_u:system_r:auditd_t:s0 res=1
Oct 24 04:29:45 localhost kernel: type=1305 audit(1477297785.808:50): audit_enabled=0 old=1 auid=4294967295 ses=4294967295 subj=system_u:system_r:auditctl_t:s0 res=1
Oct 24 04:29:45 localhost kernel: Kernel logging (proc) stopped.
Oct 24 04:29:45 localhost rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="963" x-info="http://www.rsyslog.com"] exiting on signal 15.
Oct 25 02:57:31 localhost kernel: imklog 5.8.10, log source = /proc/kmsg started.
Oct 25 02:57:31 localhost rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="963" x-info="http://www.rsyslog.com"] start
Oct 25 02:57:31 localhost kernel: Initializing cgroup subsys cpuset
Oct 25 02:57:31 localhost kernel: Initializing cgroup subsys cpu
Oct 25 02:57:31 localhost kernel: Linux version 3.8.13-44.1.1.el6uek.x86_64 (mockbuild@ca-build44.us.oracle.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #2 SMP Wed Sep 10 06:10:25 PDT 2014
Oct 25 02:57:31 localhost kernel: Command line: ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM console=ttyS0 rhgb quiet
……
……
……
Oct 25 02:57:31 localhost kernel: NET: Registered protocol family 10
Oct 25 02:57:31 localhost kernel: type=1305 audit(1477378651.397:4): audit_pid=943 old=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:auditd_t:s0 res=1
Oct 25 02:57:31 localhost kdump: No crashkernel parameter specified for running kernel
Oct 25 02:57:31 localhost acpid: starting up with proc fs
Oct 25 02:57:31 localhost acpid: skipping incomplete file /etc/acpi/events/video.conf
Oct 25 02:57:31 localhost acpid: 1 rule loaded
Oct 25 02:57:31 localhost acpid: waiting for events: event logging is off
网友评论