添加一个drive:guestfs_add_drive_opts

add-drive filename [readonly:true|false] [format:..] [iface:..] [name:..] [label:..] [protocol:..] [server:..]

This function adds a disk image called filename to the handle.

When this function is called before "launch" (the usual case) then the first time you call this function, the disk appears in the API as /dev/sda, the second time as /dev/sdb, and so on.

# guestfish -a ubuntutest.img

Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.

Type: 'help' for help on commands
      'man' to read the manual
      'quit' to quit the shell

><fs> add-drive ./ubuntutest1.img format:qcow2
><fs> run

><fs> list-devices
/dev/sda
/dev/sdb

><fs> list-partitions
/dev/sda1
/dev/sda2
/dev/sda5
/dev/sdb1

><fs> list-filesystems
/dev/sda1: ext4
/dev/sda2: unknown
/dev/sda5: swap
/dev/sdb1: ext3

# ps aux | grep guest
root     16128  0.1  0.0  96212  4588 pts/0    S+   20:29   0:00 guestfish -a ubuntutest.img
root     16139 36.1  0.1 1342196 90220 pts/0   Sl   20:29   0:02 /usr/bin/qemu-system-x86_64 -global virtio-blk-pci.scsi=off -nodefconfig -enable-fips -nodefaults -nographic -machine accel=kvm:tcg -m 500 -no-reboot -rtc driftfix=slew -no-hpet -no-kvm-pit-reinjection -kernel /var/tmp/.guestfs-0/kernel.16128 -initrd /var/tmp/.guestfs-0/initrd.16128 -device virtio-scsi-pci,id=scsi -drive file=ubuntutest.img,cache=writeback,id=hd0,if=none -device scsi-hd,drive=hd0 -drive file=./ubuntutest1.img,cache=writeback,format=qcow2,id=hd1,if=none -device scsi-hd,drive=hd1 -drive file=/var/tmp/.guestfs-0/root.16128,snapshot=on,id=appliance,cache=unsafe,if=none -device scsi-hd,drive=appliance -device virtio-serial-pci -serial stdio -device sga -chardev socket,path=/tmp/libguestfscoAfPi/guestfsd.sock,id=channel0 -device virtserialport,chardev=channel0,name=org.libguestfs.channel.0 -append panic=1 console=ttyS0 udevtimeout=600 no_timer_check acpi=off printk.time=1 cgroup_disable=memory root=/dev/sdc selinux=0 TERM=linux
root     16140  0.0  0.0  96212  1300 pts/0    S    20:29   0:00 guestfish -a ubuntutest.img

MOUNTING:guestfs_mount

><fs> mount /dev/sda1 /
><fs> ls
ls should have 1 parameter
type 'help ls' for help on ls
><fs> ls /
bin
boot
dev
etc
home
initrd.img
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
vmlinuz
><fs> ls /home
openstack
><fs> ls /home/openstack
.bash_history
.bash_logout
.bashrc
.cache
.profile
sdb
><fs> ls /home/openstack/sdb
><fs> mount /dev/sdb1 /home/openstack/sdb
><fs> ls /home/openstack/sdb            
a
b
c
d
hello
lost+found
world
><fs>

FILESYSTEM ACCESS AND MODIFICATION

><fs> cat /home/openstack/.bash_history
sudo su

><fs> cat /home/openstack/.bash_logout
# ~/.bash_logout: executed by bash(1) when login shell exits.

# when leaving the console clear the screen to increase privacy

if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi

chown

chmod

cp

……

PARTITIONING

><fs> part-list /dev/sdb
[0] = {
  part_num: 1
  part_start: 1048576
  part_end: 4294967295
  part_size: 4293918720
}
><fs> part-list /dev/sda
[0] = {
  part_num: 1
  part_start: 1048576
  part_end: 3221225471
  part_size: 3220176896
}
[1] = {
  part_num: 2
  part_start: 3222273024
  part_end: 5367660543
  part_size: 2145387520
}
[2] = {
  part_num: 5
  part_start: 3222274048
  part_end: 5367660543
  part_size: 2145386496
}

part-add
part-del
part-disk
part-get-bootable
part-get-gpt-type
part-get-mbr-id
part-get-name
part-get-parttype
part-init
part-list
part-set-bootable
part-set-gpt-type
part-set-mbr-id
part-set-name
part-to-dev
part-to-partnum

LVM2

lvcreate
lvcreate-free
lvm-canonical-lv-name
lvm-clear-filter
lvm-remove-all
lvm-set-filter
lvremove
lvrename
lvresize
lvresize-free
lvs
lvs-full
lvuuid

pvcreate
pvremove
pvresize
pvresize-size
pvs
pvs-full
pvuuid

vg-activate
vg-activate-all
vgchange-uuid
vgchange-uuid-all
vgcreate
vglvuuids
vgmeta
vgpvuuids
vgremove
vgrename
vgs
vgs-full
vgscan
vguuid

><fs> add-drive ./centos-5.8.new.qcow2 format:qcow2

><fs> pvs
/dev/sdb2
><fs> vgs
VolGroup00
><fs> vgscan
><fs> vgs-full
[0] = {
  vg_name: VolGroup00
  vg_uuid: mSeGoqicAVmrFmpe8gVnQUpjlNIRFHlJ
  vg_fmt: lvm2
  vg_attr: wzx-n-
  vg_size: 10603200512
  vg_free: 0
  vg_sysid:
  vg_extent_size: 33554432
  vg_extent_count: 316
  vg_free_count: 0
  max_lv: 0
  max_pv: 0
  pv_count: 1
  lv_count: 2
  snap_count: 0
  vg_seqno: 4
  vg_tags:
  vg_mda_count: 1
  vg_mda_free: 94208
}

><fs> vgmeta VolGroup00
# Generated by LVM2 version 2.02.98(2) (2012-10-15): Wed Jul  9 13:07:50 2014

contents = "Text Format Volume Group"
version = 1

description = "vgcfgbackup -f /tmp/vgmetaSV9JB9 VolGroup00"

creation_host = "(none)"        # Linux (none) 3.13.0-27-generic #50-Ubuntu SMP Thu May 15 18:06:16 UTC 2014 x86_64
creation_time = 1404911270      # Wed Jul  9 13:07:50 2014

VolGroup00 {
        id = "mSeGoq-icAV-mrFm-pe8g-VnQU-pjlN-IRFHlJ"
        seqno = 4
        format = "lvm2" # informational
        status = ["EXPORTED", "RESIZEABLE", "READ", "WRITE"]
        flags = []
        extent_size = 65536             # 32 Megabytes
        max_lv = 0
        max_pv = 0
        metadata_copies = 0

physical_volumes {

pv0 {
                        id = "K0B8Rq-HB21-lvo7-Eg3D-b0d9-Ya1I-w7C7AS"
                        device = "/dev/sdb2"    # Hint only

status = ["ALLOCATABLE", "EXPORTED"]
                        flags = []
                        dev_size = 20755980     # 9.89722 Gigabytes
                        pe_start = 384
                        pe_count = 316  # 9.875 Gigabytes
                }
        }

logical_volumes {

LogVol00 {
                        id = "92iHZD-bWrY-LN5I-vgwB-3JQm-jOjN-vOLYuv"
                        status = ["READ", "WRITE", "VISIBLE"]
                        flags = []
                        segment_count = 1

segment1 {
                                start_extent = 0
                                extent_count = 191      # 5.96875 Gigabytes

type = "striped"
                                stripe_count = 1        # linear

stripes = [
                                        "pv0", 0
                                ]
                        }
                }

LogVol01 {
                        id = "xsOBkU-Y1WU-HG8S-wZij-vT7W-152G-IbnnfY"
                        status = ["READ", "WRITE", "VISIBLE"]
                        flags = []
                        segment_count = 1

segment1 {
                                start_extent = 0
                                extent_count = 125      # 3.90625 Gigabytes

type = "striped"
                                stripe_count = 1        # linear

stripes = [
                                        "pv0", 191
                                ]
                        }
                }
        }
}

><fs> pvs-full
[0] = {
  pv_name: /dev/sdb2
  pv_uuid: K0B8RqHB21lvo7Eg3Db0d9Ya1Iw7C7AS
  pv_fmt: lvm2
  pv_size: 10603200512
  dev_size: 10627061760
  pv_free: 0
  pv_used: 10603200512
  pv_attr: ax-
  pv_pe_count: 316
  pv_pe_alloc_count: 316
  pv_tags:
  pe_start: 196608
  pv_mda_count: 1
  pv_mda_free: 94208
}

http://www.tldp.org/HOWTO/LVM-HOWTO/

DOWNLOADING

><fs> download /home/openstack/.bash_history testdownload

><fs> upload instance01.xml /home/openstack/testupload
><fs> ls /home/openstack                             
.bash_history
.bash_logout
.bashrc
.cache
.profile
sdb
testupload

命令集合

COMMANDS
    acl-delete-def-file
    acl-get-file
    acl-set-file
    add-cdrom
    add-domain
    domain
    add-drive
    add
    add-drive-opts
    add-drive-ro
    add-ro
    add-drive-ro-with-if
    add-drive-scratch
    scratch
    add-drive-with-if
    aug-clear
    aug-close
    aug-defnode
    aug-defvar
    aug-get
    aug-init
    aug-insert
    aug-label
    aug-load
    aug-ls
    aug-match
    aug-mv
    aug-rm
    aug-save
    aug-set
    aug-setm
    available
    available-all-groups
    base64-in
    base64-out
    blkdiscard
    blkdiscardzeroes
    blkid
    blockdev-flushbufs
    blockdev-getbsz
    blockdev-getro
    blockdev-getsize64
    blockdev-getss
    blockdev-getsz
    blockdev-rereadpt
    blockdev-setbsz
    blockdev-setro
    blockdev-setrw
    btrfs-device-add
    btrfs-device-delete
    btrfs-filesystem-balance
    btrfs-filesystem-resize
    btrfs-filesystem-sync
    btrfs-fsck
    btrfs-set-seeding
    btrfs-subvolume-create
    btrfs-subvolume-delete
    btrfs-subvolume-list
    btrfs-subvolume-set-default
    btrfs-subvolume-snapshot
    canonical-device-name
    cap-get-file
    cap-set-file
    case-sensitive-path
    cat
    checksum
    checksum-device
    checksums-out
    chmod
    chown
    clear-backend-setting
    command
    command-lines
    compress-device-out
    compress-out
    config
    copy-attributes
    copy-device-to-device
    copy-device-to-file
    copy-file-to-device
    copy-file-to-file
    copy-size
    cp
    cp-a
    cp-r
    cpio-out
    dd
    device-index
    df
    df-h
    disk-create
    disk-format
    disk-has-backing-file
    disk-virtual-size
    dmesg
    download
    download-offset
    drop-caches
    du
    e2fsck
    e2fsck-f
    echo-daemon
    egrep
    egrepi
    equal
    exists
    extlinux
    fallocate
    fallocate64
    feature-available
    fgrep
    fgrepi
    file
    file-architecture
    filesize
    filesystem-available
    fill
    fill-dir
    fill-pattern
    find
    find0
    findfs-label
    findfs-uuid
    fsck
    fstrim
    get-append
    get-attach-method
    get-autosync
    get-backend
    get-backend-setting
    get-backend-settings
    get-cachedir
    get-direct
    get-e2attrs
    get-e2generation
    get-e2label
    get-e2uuid
    get-hv
    get-libvirt-requested-credential-challenge
    get-libvirt-requested-credential-defresult
    get-libvirt-requested-credential-prompt
    get-libvirt-requested-credentials
    get-memsize
    get-network
    get-path
    get-pgroup
    get-pid
    pid
    get-program
    get-qemu
    get-recovery-proc
    get-selinux
    get-smp
    get-tmpdir
    get-trace
    get-umask
    get-verbose
    getcon
    getxattr
    getxattrs
    glob-expand
    grep
    grep-opts
    grepi
    grub-install
    head
    head-n
    hexdump
    hivex-close
    hivex-commit
    hivex-node-add-child
    hivex-node-children
    hivex-node-delete-child
    hivex-node-get-child
    hivex-node-get-value
    hivex-node-name
    hivex-node-parent
    hivex-node-set-value
    hivex-node-values
    hivex-open
    hivex-root
    hivex-value-key
    hivex-value-type
    hivex-value-utf8
    hivex-value-value
    initrd-cat
    initrd-list
    inotify-add-watch
    inotify-close
    inotify-files
    inotify-init
    inotify-read
    inotify-rm-watch
    inspect-get-arch
    inspect-get-distro
    inspect-get-drive-mappings
    inspect-get-filesystems
    inspect-get-format
    inspect-get-hostname
    inspect-get-icon
    inspect-get-major-version
    inspect-get-minor-version
    inspect-get-mountpoints
    inspect-get-package-format
    inspect-get-package-management
    inspect-get-product-name
    inspect-get-product-variant
    inspect-get-roots
    inspect-get-type
    inspect-get-windows-current-control-set
    inspect-get-windows-systemroot
    inspect-is-live
    inspect-is-multipart
    inspect-is-netinst
    inspect-list-applications
    inspect-list-applications2
    inspect-os
    is-blockdev
    is-blockdev-opts
    is-chardev
    is-chardev-opts
    is-config
    is-dir
    is-dir-opts
    is-fifo
    is-fifo-opts
    is-file
    is-file-opts
    is-lv
    is-socket
    is-socket-opts
    is-symlink
    is-whole-device
    is-zero
    is-zero-device
    isoinfo
    isoinfo-device
    journal-close
    journal-get
    journal-get-data-threshold
    journal-get-realtime-usec
    journal-next
    journal-open
    journal-set-data-threshold
    journal-skip
    kill-subprocess
    launch
    run
    lchown
    ldmtool-create-all
    ldmtool-diskgroup-disks
    ldmtool-diskgroup-name
    ldmtool-diskgroup-volumes
    ldmtool-remove-all
    ldmtool-scan
    ldmtool-scan-devices
    ldmtool-volume-hint
    ldmtool-volume-partitions
    ldmtool-volume-type
    lgetxattr
    lgetxattrs
    list-9p
    list-devices
    list-disk-labels
    list-dm-devices
    list-filesystems
    list-ldm-partitions
    list-ldm-volumes
    list-md-devices
    list-partitions
    ll
    llz
    ln
    ln-f
    ln-s
    ln-sf
    lremovexattr
    ls
    ls0
    lsetxattr
    lstat
    lstatlist
    luks-add-key
    luks-close
    luks-format
    luks-format-cipher
    luks-kill-slot
    luks-open
    luks-open-ro
    lvcreate
    lvcreate-free
    lvm-canonical-lv-name
    lvm-clear-filter
    lvm-remove-all
    lvm-set-filter
    lvremove
    lvrename
    lvresize
    lvresize-free
    lvs
    lvs-full
    lvuuid
    lxattrlist
    max-disks
    md-create
    md-detail
    md-stat
    md-stop
    mkdir
    mkdir-mode
    mkdir-p
    mkdtemp
    mke2fs
    mke2fs-J
    mke2fs-JL
    mke2fs-JU
    mke2journal
    mke2journal-L
    mke2journal-U
    mkfifo
    mkfs
    mkfs-opts
    mkfs-b
    mkfs-btrfs
    mklost-and-found
    mkmountpoint
    mknod
    mknod-b
    mknod-c
    mkswap
    mkswap-opts
    mkswap-L
    mkswap-U
    mkswap-file
    mktemp
    modprobe
    mount
    mount-9p
    mount-local
    mount-local-run
    mount-loop
    mount-options
    mount-ro
    mount-vfs
    mountpoints
    mounts
    mv
    nr-devices
    ntfs-3g-probe
    ntfsclone-in
    ntfsclone-out
    ntfsfix
    ntfsresize
    ntfsresize-opts
    ntfsresize-size
    parse-environment
    parse-environment-list
    part-add
    part-del
    part-disk
    part-get-bootable
    part-get-gpt-type
    part-get-mbr-id
    part-get-name
    part-get-parttype
    part-init
    part-list
    part-set-bootable
    part-set-gpt-type
    part-set-mbr-id
    part-set-name
    part-to-dev
    part-to-partnum
    ping-daemon
    pread
    pread-device
    pvchange-uuid
    pvchange-uuid-all
    pvcreate
    pvremove
    pvresize
    pvresize-size
    pvs
    pvs-full
    pvuuid
    pwrite
    pwrite-device
    read-file
    read-lines
    readdir
    readlink
    readlinklist
    realpath
    remount
    remove-drive
    removexattr
    rename
    resize2fs
    resize2fs-M
    resize2fs-size
    rm
    rm-f
    rm-rf
    rmdir
    rmmountpoint
    rsync
    rsync-in
    rsync-out
    scrub-device
    scrub-file
    scrub-freespace
    set-append
    append
    set-attach-method
    attach-method
    set-autosync
    autosync
    set-backend
    backend
    set-backend-setting
    set-backend-settings
    set-cachedir
    cachedir
    set-direct
    direct
    set-e2attrs
    set-e2generation
    set-e2label
    set-e2uuid
    set-hv
    hv
    set-label
    set-libvirt-requested-credential
    set-libvirt-supported-credentials
    set-memsize
    memsize
    set-network
    network
    set-path
    path
    set-pgroup
    pgroup
    set-program
    program
    set-qemu
    qemu
    set-recovery-proc
    recovery-proc
    set-selinux
    selinux
    set-smp
    smp
    set-tmpdir
    tmpdir
    set-trace
    trace
    set-uuid
    set-verbose
    verbose
    setcon
    setxattr
    sfdisk
    sfdiskM
    sfdisk-N
    sfdisk-disk-geometry
    sfdisk-kernel-geometry
    sfdisk-l
    sh
    sh-lines
    shutdown
    sleep
    stat
    statvfs
    strings
    strings-e
    swapoff-device
    swapoff-file
    swapoff-label
    swapoff-uuid
    swapon-device
    swapon-file
    swapon-label
    swapon-uuid
    sync
    syslinux
    tail
    tail-n
    tar-in
    tar-in-opts
    tar-out
    tar-out-opts
    tgz-in
    tgz-out
    touch
    truncate
    truncate-size
    tune2fs
    tune2fs-l
    txz-in
    txz-out
    umask
    umount
    unmount
    umount-opts
    umount-all
    unmount-all
    umount-local
    upload
    upload-offset
    user-cancel
    utimens
    utsname
    version
    vfs-label
    vfs-type
    vfs-uuid
    vg-activate
    vg-activate-all
    vgchange-uuid
    vgchange-uuid-all
    vgcreate
    vglvuuids
    vgmeta
    vgpvuuids
    vgremove
    vgrename
    vgs
    vgs-full
    vgscan
    vguuid
    wc-c
    wc-l
    wc-w
    wipefs
    write
    write-append
    write-file
    xfs-admin
    xfs-growfs
    xfs-info
    xfs-repair
    zegrep
    zegrepi
    zero
    zero-device
    zero-free-space
    zerofree
    zfgrep
    zfgrepi
    zfile
    zgrep
    zgrepi

libguestfs手册(2):guestfish command的更多相关文章

  1. libguestfs手册(1): 架构

    要编辑一个image,则运行下面的命令 guestfish -a ubuntutest.img ><fs> 会弹出一个命令行工具 运行run ><fs> run 我 ...

  2. libguestfs手册(3): virt命令

    guestmount root# guestmount -a ubuntutest1.img -m /dev/sda1 ubuntutestp1 root# cd ubuntutestp1/root: ...

  3. guestfish 修改 image file

    Example guestfish sessionSometimes, you must modify a virtual machine image to remove any traces of ...

  4. 别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点(3)

    四.Nova-compute 步骤17:nova-compute接收到请求后,通过Resource Tracker将创建虚拟机所需要的资源声明占用 步骤18:调用Neutron API配置Networ ...

  5. nova file injection的原理和调试过程

    file injection代码 file injection原理来讲是比较简单的,在nova boot命令中,有参数--file,是将文件inject到image中 nova boot --flav ...

  6. [原创]Linux-day1

    原创:转发务必注明出处http://www.cnblogs.com/0zcl/p/6077298.html 一.Linux的基本原则 由目的单一的小程序组成:组合小程序完成复杂任务 一切皆文件 尽量避 ...

  7. 常用命令[Linux]

    Linux文件类型 -:普通文件(f) d:目录文件 b:块设备文件(block) c:字符设备文件(character) l:符号链接文件(symbolic link file) p:命名管道文件( ...

  8. linux man使用方法 和centos安装中文man包 --转

    http://blog.chinaunix.net/uid-25100840-id-302308.html 这两天学习<linux设备驱动程序开发详解>中的异步通知,其中有一个fcntl( ...

  9. 10 分钟学会Linux常用 bash命令

    目录 基本操作 1.1. 文件操作 1.2. 文本操作 1.3. 目录操作 1.4. SSH, 系统信息 & 网络操作 基本 Shell 编程 2.1. 变量 2.2. 字符串替换 2.3. ...

随机推荐

  1. C#QQ邮箱验证

    注意: QQ邮箱的简单邮件传输协议(SMTP)使用了SSL加密,必须启用SSL加密.指定端口. QQ邮箱POP3/SMTP服务默认是关闭的,需要开启服务(设置=>账户=>开启服务). QQ ...

  2. 如何kill掉tomcat服务

    一般我们使用tomcat使用的都是8080端口,今天我在使用eclipse的时候连续启动了两次tomcat,发现被占用了. 第一想法便是重启eclipse,重启后发现tomcat的8080仍然是已经被 ...

  3. 图的最小环floyed

    最优的路线 问题描述 学校里面有N个景点.两个景点之间可能直接有道路相连,用Dist[I,J]表示它的长度:否则它们之间没有直接的道路相连.这里所说的道路是没有规定方向的,也就是说,如果从I到J有直接 ...

  4. 奇葩最小生成树--->走廊泼水节(tyvj1391)

    题目描述 话说,中中带领的OIER们打算举行一次冬季泼水节,当然这是要秘密进行的,绝对不可以让中中知道.不过中中可是老江湖了,当然很快就发现了我们的小阴谋,于是他准备好水枪迫不及待的想要加入我们了. ...

  5. PHP微信商户支付 - 企业付款到零钱功能(即提现)技术资料汇总

    PHP实现微信开发中提现功能(企业付款到用户零钱) 一.实现该功能目的 这几天在小程序里要实现用户从系统中提现到零钱的功能,查了一下文档可以使用 企业付款到用户零钱 来实现: 官方文档:https:/ ...

  6. C# 调用继电器api usb_relay_device.dll

    C# 调用继电器api usb_relay_device.dll 代码封装 usb_relay_device.dll 为C++编写 using System; using System.Collect ...

  7. 563. Binary Tree Tilt

    https://leetcode.com/problems/binary-tree-tilt/description/ 挺好的一个题目,审题不清的话很容易做错.主要是tilt of whole tre ...

  8. git 仓库中删除历史大文件

    git 仓库中删除历史大文件 在git中增加了一个很大的文件,而且被保存在历史提交记录中,每次拉取代码都很大,速度很慢.而且用删除 提交历史记录的方式不是很实际. 以下分几个步骤介绍如何减小.git文 ...

  9. 了解 ptyhon垃圾回收机制

    Python的GC模块主要运用了“引用计数”(reference counting)来跟踪和回收垃圾.在引用计数的基础上,还可以通过“标记-清除”(mark and sweep)解决容器对象可能产生的 ...

  10. 20175305张天钰Java结对编程四则运算

    Java结对编程四则运算 一.题目描述:如何对表达式进行求值运算呢 1.中缀表达式与后缀表达式(娄老师讲解) 中缀表达式就是运算符号在运算数中间的表达式,比如1+2,顾名思义,后缀表达式就是运算符在运 ...