100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > KVM宿主机与虚拟机vm互相传输文件

KVM宿主机与虚拟机vm互相传输文件

时间:2020-03-11 12:49:34

相关推荐

KVM宿主机与虚拟机vm互相传输文件

为何要写:

虽然网上现存类似文章,但大都是复制粘贴,且并不能真正的跑通。

本着造福大众,实事求是的原则,分享已经跑通的解决方法。

大概步骤

宿主机:创建空文件/tmp/file-share宿主机:格式化此文件宿主机:mount此文件至 /mnt/file-share-path宿主机:向/mnt/file-share-path 拷贝您想传输的文件宿主机:添加/tmp/file-share至虚拟机VM虚拟机:fdisk -l 查看此新磁盘,并挂载至/mnt通过/mnt即可互传

具体步骤

宿主机–>虚拟机

[root@kvm_1 /]# dd if=/dev/zero of=/tmp/file-share bs=1024k count=200200+0 records in200+0 records out209715200 bytes (210 MB) copied, 0.131123 s, 1.6 GB/s[root@kvm_1 /]# mkfs.ext4 /tmp/file-share[root@kvm_1 /]# mkdir /mnt/file-share-path[root@kvm_1 /]# mount -t ext4 /tmp/file-share /mnt/file-share-path[root@kvm_1 /]# cd /mnt/file-share-path[root@kvm_1 /mnt/file-share]# lslost+found[root@kvm_1 /mnt/file-share]# touch test-file.txt[root@kvm_1 /mnt/file-share]# lslost+found test-file.txt[root@kvm_1 /]# virsh attach-disk c4e325d5-6d1a-4641-91d1-8d138283c40c /tmp/file-share vdbDisk attached successfully[root@kvm_1 /]# virsh console c4e325d5-6d1a-4641-91d1-8d138283c40cConnected to domain c4e325d5-6d1a-4641-91d1-8d138283c40cEscape character is ^][root@VM_0_14_linux ~]# mount -t ext4 /dev/vdb /mnt[root@VM_0_14_linux ~]# ls /mntlost+found test-file.txt

虚拟机 --> 宿主机

[root@kvm_1 /] umount /mnt/file-share-path[root@kvm_1 /]# virsh detach-disk c4e325d5-6d1a-4641-91d1-8d138283c40c /tmp/file-shareDisk detached successfully[root@kvm_1 /]# virsh attach-disk c4e325d5-6d1a-4641-91d1-8d138283c40c /tmp/file-share vdbDisk attached successfully[root@kvm_10_25_1_18 /]# virsh console c4e325d5-6d1a-4641-91d1-8d138283c40cConnected to domain c4e325d5-6d1a-4641-91d1-8d138283c40cEscape character is ^][root@VM_0_14_linux ~]# mount -t ext4 /dev/vdb /mnt[root@VM_0_14_linux ~]# ls /mntlost+found test-file.txt[root@VM_0_14_linux ~]# cd /mnt; touch 123.txt; touch 456.txt; ls123.txt 456.txt lost+found test-file.txtctrl + ] 退出virsh console 返回宿主机[root@kvm_1 /] mount -t ext4 /tmp/file-share /mnt/file-share-path[root@kvm_1 /] ls /mnt/file-share-path123.txt 456.txt lost+found test-file.txt

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。