qemu和host间传输文件方法之挂载
我们有时希望传输文件到qemu里,那如何做了?官方给的答复:
Simple: Treat the virtual machine as if it was a real machine and
transfer files to and from it.More to the point, the following are the most common methods:
A) If the virtual machine runs Windows, OS/2 or Linux, create a Samba
network share on the Linux host (or anywhere else), put files on it,
and access the share over the network from the virtual machine. Some
qemu versions include options to automate this.B) On the Linux host create a disk image of a floppy or CD with the
desired files, then use qemu commands to virtually insert the disk
image file in the virtual floppy or CD drive. Again there are tools
to automate this.
C) Run a file transfer tool such as rsync, ssh, ftp etc. on the virtual
machine and the Linux host and use it to transfer files.D) With the virtual machine not running, loop mount its virtual hard
drive on the Linux host, and copy files to and from it.
我们来看下比较简单的D)方法,可以理解为移动硬盘(-hda
),具体操作如下:
Step1: 创建磁盘镜像
这里是256MB disk:
dd if=/dev/zero of=disk.img bs=1M count=256 |
Step2: 格式化磁盘
这里我们用ext4格式:
mkfs.ext4 disk.img |
Step3: 挂载磁盘
mkdir disk_mnt //建个挂载点 |
看下内容ls -l disk_mnt/
是空的:
total 12 |
ok, cp你想cp的东东。。。然后用sudo umount disk_mnt
卸载。接下来我们就挂到qemu上。
Step4: 挂载磁盘到qemu
就是在末尾加上-hda disk.img
, 进入后能看到如下磁盘信息:
[root@x86 ]# ls -l /dev/sda |
ok, now 我们把这个硬盘挂上去。
[root@x86 ]# mount -t ext4 /dev/sda mnt/ |
then, just use it.
Step5: 自动挂载
上面的退出qemu后就丢失了,因为fstab没有修改,我们回到之前制作rootfs那里,rootfs/ext4/fstab里添加:
/dev/sda /mnt ext4 defaults 0 0 |
then重新制作ramdisk.gz即可。
refer
版权声明:本站所有文章均采用 CC BY-NC-SA 4.0 CN 许可协议。转载请注明原文链接!