zoukankan      html  css  js  c++  java
  • kata 9p

    Manually, using qemu-kvm command line

    There are a nice set of details on the QEMU wiki describing this, so this section will be quite short. To share host files w/ the guest, we use 9p over virtio in conjunction w/ a filesystem device exporting the portion of the host filesystem that we'd like to share with the guest.

    # /usr/bin/qemu-kvm -m 1024 -name f15 -drive file=/images/f15.img,if=virtio
    -fsdev local,security_model=passthrough,id=fsdev0,path=/tmp/share -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare
    

    This tells qemu to create a 9pvirtio device exposing the mount_tag hostshare (just a name to identify the mount point). That device is coupled to an fsdev named fsdev0, which specifies which portion of the host filesystem we are sharing, and in which mode (see QEMU wiki for details on the security models).

    Now, in the guest we need to mount the 9p filesystem from the host using the virtio transport. The mount_tag is used to identify the host's share.

    # mkdir /tmp/host_files
    # mount -t 9p -o trans=virtio,version=9p2000.L hostshare /tmp/host_files
    

    That's it...now we can read/write files in that directory from either the host or the guest.

    root@(none):/# mount -t 9p -o trans=virtio,version=9p2000.L kataShared tmp
    root@(none):/# ls
    bin dev home lost+found mnt proc run srv tmp var
    boot etc lib media opt root sbin sys usr
    root@(none):/# ls /tmp/
    hello.txt
    root@(none):/#

    root@(none):/# ls
    bin   dev  home  lost+found  mnt  proc  run   srv  tmp  var
    boot  etc  lib   media       opt  root  sbin  sys  usr
    root@(none):/# mkdir kata1
    mkdir: cannot create directory 'kata1': Read-only file system
    root@(none):/# cd run/
    root@(none):/run# ls
    lock  systemd  utmp
    root@(none):/run# mkdir kata1
    mkdir: cannot create directory 'kata1': Read-only file system
    root@(none):/run# ls
    lock  systemd  utmp
    root@(none):/run# 
    -device virtio-9p-pci,disable-modern=false,fsdev=fsdev0,mount_tag=label1,romfile=: 9pfs device couldn't find fsdev with the id = fsdev0

     原来是fsdev=fsdev0 和id=label1不一致

     -device virtio-9p-pci,disable-modern=false,fsdev=fsdev0,mount_tag=label1,romfile= 
            -fsdev local,id=label1,path=share1,security_model=none 

    改成这个就可以哦

       -device virtio-9p-pci,disable-modern=false,fsdev=fsdev0,mount_tag=label1,romfile= 
            -fsdev local,id=fsdev0,path=share1,security_model=none 
    > sudo qemu-kvm --no-kvm -m 1024 -kernel
    > /mnt/test/usr/src/linux-3.13-rc1/arch/x86/boot/bzImage -append
    > 'root=/dev/root rootfstype=9p rootflags=trans=virtio,version=9p2000.L ro
    > console=ttyS0' -serial stdio -fsdev
    > local,id=root,path=/mnt/test,security_model=none -device
    > virtio-9p-pci,fsdev=root,mount_tag=/dev/root
    #  mkdir -p /mnt/host
    #  mount -t 9p -o trans=virtio host /mnt/host
    9pnet_virtio: no channels available for device host
    mount: mounting host on /mnt/host failed: No such file or directory
    # ls -al /mnt
    total 0
    drwxr-xr-x    3 root     root            60 May 29 08:04 .
    drwxr-xr-x   18 root     root           420 May 29 08:02 ..
    drwxr-xr-x    2 root     root            40 May 29 08:04 host
    # 

    挂多个

    root@(none):/var# ls
    backups lib local lock mail opt run spool tmp
    root@(none):/var# mount -t 9p -o trans=virtio label1 opt
    root@(none):/var# mount -t 9p -o trans=virtio kataShared tmp
    root@(none):/var# ls opt/
    kata.txt
    root@(none):/var# ls tmp/
    hello.txt
    root@(none):/var# cat opt/kata.txt
    hello3
    root@(none):/var# cat tmp/hello.txt
    kata1
    root@(none):/var#

  • 相关阅读:
    gitlab备份及迁移
    python paramiko 进行文件上传处理
    秒杀场景简介
    nmon--非常棒的LINUX/AIX性能计数器监测和分析工具
    使用wait()与notify()实现线程间协作
    【转】Spring bean处理——回调函数
    ldconfig和ldd用法
    tcpdump 获取http请求url
    clearfix清除浮动
    git push命令
  • 原文地址:https://www.cnblogs.com/dream397/p/14101899.html
Copyright © 2011-2022 走看看