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#

  • 相关阅读:
    P3916 图的遍历 dfs
    P4568 [JLOI2011]飞行路线 分层图最短路
    P1948 [USACO08JAN]电话线Telephone Lines spfa 二分答案
    P1849 [USACO12MAR]拖拉机Tractor bfs
    P1730 最小密度路径 floyed
    P1661 扩散 二分答案 并查集
    使用unittest和Django搭配写一个接口测试平台
    AJAX解决跨域的几种方式
    Django
    基于pytest框架自动化测试脚本的编写
  • 原文地址:https://www.cnblogs.com/dream397/p/14101899.html
Copyright © 2011-2022 走看看