این مطلب در دو بخش نوشته شده است. بخش اول در اینجا
virt-copy-out: فایل و دایرکتوریهای داخل ماشین مجازی را به بیرون از ماشین کپی میکند.
#virt-copy-out -d name /home/ /home/back_up #virt-copy-out -a image.vm /home/ /home/back_up
virt-df: فضای خالی ماشین مجازی را نشان میدهد.
#virt-df domname #virt-df [--options] -d domname #virt-df [--options] -a disk.img
مثالی از عملکرد برنامه:
#virt-df -a vm Filesystem 1K-blocks Used Available Use% vm:/dev/sda1 330215 119878 193288 37% vm:/dev/sda5 2879612 361160 2372176 13% vm:/dev/sda6 1412048 93520 1246800 7% vm:/dev/sda8 238986 6175 220472 3% vm:/dev/sda9 2913876 69964 2695896 3%
virt-v2v: ماشینهای مجازی Xen و یا VMware را به KVM تبدیل میکند.
virt-p2v: اطلاعات یک سیستم فیزیکی را برای اجرا بروی KVM تبدیل میکند.
guestmount: فایل سیستم ماشین مجازی مهمان را در سیستم میزبان مونت میکند. با توجه به اینکه یک ایمیج ممکن است شامل چند پارتیشن باشد با پارامتر -m پارتیشنی که میخواهیم مونت کنیم را مشخص میکنیم. همچنین با استفاده از پارامتر -i به صورت خودکار پارتیشنها شناسایی شده و مونت میشوند.
#guestmount [--options] -a disk.img -m device [--ro] mountpoint #guestmount [--options] -a disk.img -i [--ro] mountpoint #guestmount [--options] -d name -i [--ro] mountpoint
چند مثال:
پارتیشن روت را از مسیر /dev/VG/LV و پارتیشن /boot را از مسیر /dev/sda1 در دایرکتوری /mnt مونت میکنیم.
#guestmount -a linux.img -m /dev/VG/LV -m /dev/sda1:/boot --ro /mnt
همه پارتیشنهای ایمیج guest به صورت خودکار شناسایی و در /mnt مونت میشوند.
#guestmount -a guest.img -i --ro /mnt
برای از حالت مونت خارج کردن پارتیشنها از دستور guestunmount به صورت زیر استفاده میکنیم.
#guestunmount /mnt
نکته: نوشتن در ماشین مجازی که روشن است ممکن است باعث خراب شدن و از دست رفتن اطلاعات شود. بنابراین بهتر است در هنگام مونت کردن ماشین مجازی که روشن است فایل سیستم را با پارامتر –ro بصورت فقط خواندنی مونت کنیم.
virt-filesystems: فایل سیستمها و پارتینشهای موجود در یک ماشین مجازی را لیست میکند.
#virt-filesystems [--options] -d domname #virt-filesystems [--options] -a disk.img
مثال:
#virt-filesystems -a vm.img /dev/sda1 /dev/sda5 /dev/sda6 /dev/sda8 /dev/sda9
virt-resize: با این ابزار میتوانیم یک ایمیج و یا دیسک ماشین مجازی را کوچک و یا بزرگ کنیم.
#virt-resize [--resize /dev/sdaN=[+/-]<size>[%]] [--expand /dev/sdaN] [--shrink /dev/sdaN] [--ignore /dev/sdaN] [--delete /dev/sdaN] [...] indisk outdisk
virt-win-reg: با استفاده از این دستور میتوانیم رجیستری ویندوز در ماشین مجازی را ویرایش کنیم.
#virt-win-reg domname 'HKLM\Path\To\Subkey' #virt-win-reg domname 'HKLM\Path\To\Subkey' name #virt-win-reg domname 'HKLM\Path\To\Subkey' @ #virt-win-reg --merge domname [input.reg ...] #virt-win-reg [--options] disk.img ... # instead of domname
guestfish:
یک ابزار خط فرمانی و شل است که با استفاده از توابع کتابخانهای و API های libguestfs فایلسیستم ماشینمجازی را بررسی و ویرایش میکند.
#guestfish
برای استفاده از guestfish کافی است دستور را در ماشین مهمان وارد کنیم و دستورات با به صورت ویزارد وارد کنیم.
#guestfish Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. Type: 'help' for help on commands 'man' to read the manual 'quit' to quit the shell ><fs>
بعد از ورود به شل guestfish میتوانیم دستورات را وارد کنیم. بع عنوان مثال با add-ro disk.img یک ایمیج را به صورت فقط خواندنی اضافه میکنیم.
><fs> add-ro vm.img ><fs> run ><fs> mount /dev/vda1 / ><fs> ls /root .aptitude .bashrc .profile ><fs> exit
در حال حاظر guestfish ۵۰۲ دستور متفاوت را پشتیبانی میکند. لیست این دستورات را در لینک زیر مشاهده میکنید.
Command Description help display a list of commands or help on a command quit quit guestfish acl-delete-def-file delete the default POSIX ACL of a directory acl-get-file get the POSIX ACL attached to a file acl-set-file set the POSIX ACL attached to a file add-cdrom add a CD-ROM disc image to examine add-domain add the disc(s) from a named libvirt domain add-drive add an image to examine or modify add-drive-ro add a drive in snapshot mode (read-only) add-drive-ro-with-if add a drive read-only specifying the QEMU block emulation to use add-drive-with-if add a drive specifying the QEMU block emulation to use alloc allocate and add a disc file aug-clear clear Augeas path aug-close close the current Augeas handle aug-defnode define an Augeas node aug-defvar define an Augeas variable aug-get look up the value of an Augeas path aug-init create a new Augeas handle aug-insert insert a sibling Augeas node aug-load load files into the tree aug-ls list Augeas nodes under augpath aug-match return Augeas nodes which match augpath aug-mv move Augeas node aug-rm remove an Augeas path aug-save write all pending Augeas changes to disk aug-set set Augeas path to value available test availability of some parts of the API available-all-groups return a list of all optional groups base64-in upload base64-encoded data to file base64-out download file and encode as base64 blkid print block device attributes blockdev-flushbufs flush device buffers blockdev-getbsz get blocksize of block device blockdev-getro is block device set to read-only blockdev-getsize64 get total size of device in bytes blockdev-getss get sectorsize of block device blockdev-getsz get total size of device in 512-byte sectors blockdev-rereadpt reread partition table blockdev-setbsz set blocksize of block device blockdev-setro set block device to read-only blockdev-setrw set block device to read-write btrfs-device-add add devices to a btrfs filesystem btrfs-device-delete remove devices from a btrfs filesystem btrfs-filesystem-balance balance a btrfs filesystem btrfs-filesystem-resize resize a btrfs filesystem btrfs-filesystem-sync sync a btrfs filesystem btrfs-fsck check a btrfs filesystem btrfs-set-seeding enable or disable the seeding feature of device btrfs-subvolume-create create a btrfs snapshot btrfs-subvolume-delete delete a btrfs snapshot btrfs-subvolume-list list btrfs snapshots and subvolumes btrfs-subvolume-set-default set default btrfs subvolume btrfs-subvolume-snapshot create a writable btrfs snapshot canonical-device-name return canonical device name cap-get-file get the Linux capabilities attached to a file cap-set-file set the Linux capabilities attached to a file case-sensitive-path return true path on case-insensitive filesystem cat list the contents of a file checksum compute MD5, SHAx or CRC checksum of file checksum-device compute MD5, SHAx or CRC checksum of the contents of a device checksums-out compute MD5, SHAx or CRC checksum of files in a directory chmod change file mode chown change file owner and group command run a command from the guest filesystem command-lines run a command, returning lines compress-device-out output compressed device compress-out output compressed file config add qemu parameters copy-device-to-device copy from source device to destination device copy-device-to-file copy from source device to destination file copy-file-to-device copy from source file to destination device copy-file-to-file copy from source file to destination file copy-in copy local files or directories into an image copy-out copy remote files or directories out of an image copy-size copy size bytes from source to destination using dd cp copy a file cp-a copy a file or directory recursively dd copy from source to destination using dd debug debugging and internals debug-drives debug the drives (internal use only) debug-upload upload a file to the appliance (internal use only) delete-event delete a previously registered event handler device-index convert device to index df report file system disk space usage df-h report file system disk space usage (human readable) disk-format detect the disk format of a disk image disk-has-backing-file return whether disk has a backing file disk-virtual-size return virtual size of a disk display display an image dmesg return kernel messages download download a file to the local machine download-offset download a file to the local machine with offset and size drop-caches drop kernel page cache, dentries and inodes du estimate file space usage e2fsck check an ext2/ext3 filesystem e2fsck-f check an ext2/ext3 filesystem echo display a line of text echo-daemon echo arguments back to the client edit edit a file egrep return lines matching a pattern egrepi return lines matching a pattern equal test if two files have equal contents event register a handler for an event or events exists test if file or directory exists fallocate preallocate a file in the guest filesystem fallocate64 preallocate a file in the guest filesystem fgrep return lines matching a pattern fgrepi return lines matching a pattern file determine file type file-architecture detect the architecture of a binary file filesize return the size of the file in bytes filesystem-available check if filesystem is available fill fill a file with octets fill-dir fill a directory with empty files fill-pattern fill a file with a repeating pattern of bytes find find all files and directories find0 find all files and directories, returning NUL-separated list findfs-label find a filesystem by label findfs-uuid find a filesystem by UUID fsck run the filesystem checker fstrim trim free space in a filesystem get-append get the additional kernel options get-attach-method get the attach method get-autosync get autosync mode get-cachedir get the appliance cache directory get-direct get direct appliance mode flag get-e2attrs get ext2 file attributes of a file get-e2generation get ext2 file generation of a file get-e2label get the ext2/3/4 filesystem label get-e2uuid get the ext2/3/4 filesystem UUID get-libvirt-requested-credential-challenge challenge of i'th requested credential get-libvirt-requested-credential-defresult default result of i'th requested credential get-libvirt-requested-credential-prompt prompt of i'th requested credential get-libvirt-requested-credentials get list of credentials requested by libvirt get-memsize get memory allocated to the qemu subprocess get-network get enable network flag get-path get the search path get-pgroup get process group flag get-pid get PID of qemu subprocess get-qemu get the qemu binary get-recovery-proc get recovery process enabled flag get-selinux get SELinux enabled flag get-smp get number of virtual CPUs in appliance get-tmpdir get the temporary directory get-trace get command trace enabled flag get-umask get the current umask get-verbose get verbose mode getcon get SELinux security context getxattr get a single extended attribute getxattrs list extended attributes of a file or directory glob expand wildcards in command glob-expand expand a wildcard path grep return lines matching a pattern grepi return lines matching a pattern grub-install install GRUB 1 head return first 10 lines of a file head-n return first N lines of a file hexdump dump a file in hexadecimal hexedit edit with a hex editor hivex-close close the current hivex handle hivex-commit commit (write) changes back to the hive hivex-node-add-child add a child node hivex-node-children return list of nodes which are subkeys of node hivex-node-delete-child delete a node (recursively) hivex-node-get-child return the named child of node hivex-node-get-value return the named value hivex-node-name return the name of the node hivex-node-parent return the parent of node hivex-node-set-value set or replace a single value in a node hivex-node-values return list of values attached to node hivex-open open a Windows Registry hive file hivex-root return the root node of the hive hivex-value-key return the key field from the (key, datatype, data) tuple hivex-value-type return the data type from the (key, datatype, data) tuple hivex-value-utf8 return the data field from the (key, datatype, data) tuple hivex-value-value return the data field from the (key, datatype, data) tuple initrd-cat list the contents of a single file in an initrd initrd-list list files in an initrd inotify-add-watch add an inotify watch inotify-close close the inotify handle inotify-files return list of watched files that had events inotify-init create an inotify handle inotify-read return list of inotify events inotify-rm-watch remove an inotify watch inspect-get-arch get architecture of inspected operating system inspect-get-distro get distro of inspected operating system inspect-get-drive-mappings get drive letter mappings inspect-get-filesystems get filesystems associated with inspected operating system inspect-get-format get format of inspected operating system inspect-get-hostname get hostname of the operating system inspect-get-icon get the icon corresponding to this operating system inspect-get-major-version get major version of inspected operating system inspect-get-minor-version get minor version of inspected operating system inspect-get-mountpoints get mountpoints of inspected operating system inspect-get-package-format get package format used by the operating system inspect-get-package-management get package management tool used by the operating system inspect-get-product-name get product name of inspected operating system inspect-get-product-variant get product variant of inspected operating system inspect-get-roots return list of operating systems found by last inspection inspect-get-type get type of inspected operating system inspect-get-windows-current-control-set get Windows CurrentControlSet of inspected operating system inspect-get-windows-systemroot get Windows systemroot of inspected operating system inspect-is-live get live flag for install disk inspect-is-multipart get multipart flag for install disk inspect-is-netinst get netinst (network installer) flag for install disk inspect-list-applications get list of applications installed in the operating system inspect-list-applications2 get list of applications installed in the operating system inspect-os inspect disk and return list of operating systems found is-blockdev test if block device is-chardev test if character device is-config is in configuration state is-dir test if a directory is-fifo test if FIFO (named pipe) is-file test if a regular file is-lv test if device is a logical volume is-socket test if socket is-symlink test if symbolic link is-whole-device test if a device is a whole device is-zero test if a file contains all zero bytes is-zero-device test if a device contains all zero bytes isoinfo get ISO information from primary volume descriptor of ISO file isoinfo-device get ISO information from primary volume descriptor of device kill-subprocess kill the qemu subprocess launch launch the qemu subprocess lcd change working directory lchown change file owner and group ldmtool-create-all scan and create Windows dynamic disk volumes ldmtool-diskgroup-disks return the disks in a Windows dynamic disk group ldmtool-diskgroup-name return the name of a Windows dynamic disk group ldmtool-diskgroup-volumes return the volumes in a Windows dynamic disk group ldmtool-remove-all remove all Windows dynamic disk volumes ldmtool-scan scan for Windows dynamic disks ldmtool-scan-devices scan for Windows dynamic disks ldmtool-volume-hint return the hint field of a Windows dynamic disk volume ldmtool-volume-partitions return the partitions in a Windows dynamic disk volume ldmtool-volume-type return the type of a Windows dynamic disk volume lgetxattr get a single extended attribute lgetxattrs list extended attributes of a file or directory list-9p list 9p filesystems list-devices list the block devices list-disk-labels mapping of disk labels to devices list-dm-devices list device mapper devices list-events list event handlers list-filesystems list filesystems list-ldm-partitions list all Windows dynamic disk partitions list-ldm-volumes list all Windows dynamic disk volumes list-md-devices list Linux md (RAID) devices list-partitions list the partitions ll list the files in a directory (long format) llz list the files in a directory (long format with SELinux contexts) ln create a hard link ln-f create a hard link ln-s create a symbolic link ln-sf create a symbolic link lremovexattr remove extended attribute of a file or directory ls list the files in a directory ls0 get list of files in a directory lsetxattr set extended attribute of a file or directory lstat get file information for a symbolic link lstatlist lstat on multiple files luks-add-key add a key on a LUKS encrypted device luks-close close a LUKS device luks-format format a block device as a LUKS encrypted device luks-format-cipher format a block device as a LUKS encrypted device luks-kill-slot remove a key from a LUKS encrypted device luks-open open a LUKS-encrypted block device luks-open-ro open a LUKS-encrypted block device read-only lvcreate create an LVM logical volume lvcreate-free create an LVM logical volume in % remaining free space lvm-canonical-lv-name get canonical name of an LV lvm-clear-filter clear LVM device filter lvm-remove-all remove all LVM LVs, VGs and PVs lvm-set-filter set LVM device filter lvremove remove an LVM logical volume lvrename rename an LVM logical volume lvresize resize an LVM logical volume lvresize-free expand an LV to fill free space lvs list the LVM logical volumes (LVs) lvs-full list the LVM logical volumes (LVs) lvuuid get the UUID of a logical volume lxattrlist lgetxattr on multiple files man open the manual max-disks maximum number of disks that may be added md-create create a Linux md (RAID) device md-detail obtain metadata for an MD device md-stat get underlying devices from an MD device md-stop stop a Linux md (RAID) device mkdir create a directory mkdir-mode create a directory with a particular mode mkdir-p create a directory and parents mkdtemp create a temporary directory mke2fs create an ext2/ext3/ext4 filesystem on device mke2fs-J make ext2/3/4 filesystem with external journal mke2fs-JL make ext2/3/4 filesystem with external journal mke2fs-JU make ext2/3/4 filesystem with external journal mke2journal make ext2/3/4 external journal mke2journal-L make ext2/3/4 external journal with label mke2journal-U make ext2/3/4 external journal with UUID mkfifo make FIFO (named pipe) mkfs make a filesystem mkfs-b make a filesystem with block size mkfs-btrfs create a btrfs filesystem mklost-and-found make lost+found directory on an ext2/3/4 filesystem mkmountpoint create a mountpoint mknod make block, character or FIFO devices mknod-b make block device node mknod-c make char device node mkswap create a swap partition mkswap-L create a swap partition with a label mkswap-U create a swap partition with an explicit UUID mkswap-file create a swap file mktemp create a temporary file modprobe load a kernel module more view a file mount mount a guest disk at a position in the filesystem mount-9p mount 9p filesystem mount-local mount on the local filesystem mount-local-run run main loop of mount on the local filesystem mount-loop mount a file using the loop device mount-options mount a guest disk with mount options mount-ro mount a guest disk, read-only mount-vfs mount a guest disk with mount options and vfstype mountpoints show mountpoints mounts show mounted filesystems mv move a file nr-devices return number of whole block devices (disks) added ntfs-3g-probe probe NTFS volume ntfsclone-in restore NTFS from backup file ntfsclone-out save NTFS to backup file ntfsfix fix common errors and force Windows to check NTFS ntfsresize resize an NTFS filesystem ntfsresize-size resize an NTFS filesystem (with size) parse-environment parse the environment and set handle flags accordingly parse-environment-list parse the environment and set handle flags accordingly part-add add a partition to the device part-del delete a partition part-disk partition whole disk with a single primary partition part-get-bootable return true if a partition is bootable part-get-gpt-type get the type GUID of a GPT partition part-get-mbr-id get the MBR type byte (ID byte) from a partition part-get-parttype get the partition table type part-init create an empty partition table part-list list partitions on a device part-set-bootable make a partition bootable part-set-gpt-type set the type GUID of a GPT partition part-set-mbr-id set the MBR type byte (ID byte) of a partition part-set-name set partition name part-to-dev convert partition name to device name part-to-partnum convert partition name to partition number ping-daemon ping the guest daemon pread read part of a file pread-device read part of a device pvchange-uuid generate a new random UUID for a physical volume pvchange-uuid-all generate new random UUIDs for all physical volumes pvcreate create an LVM physical volume pvremove remove an LVM physical volume pvresize resize an LVM physical volume pvresize-size resize an LVM physical volume (with size) pvs list the LVM physical volumes (PVs) pvs-full list the LVM physical volumes (PVs) pvuuid get the UUID of a physical volume pwrite write to part of a file pwrite-device write to part of a device read-file read a file read-lines read file as lines readdir read directories entries readlink read the target of a symbolic link readlinklist readlink on multiple files realpath canonicalized absolute pathname remove-drive remove a disk image removexattr remove extended attribute of a file or directory rename rename a file on the same filesystem reopen close and reopen libguestfs handle resize2fs resize an ext2, ext3 or ext4 filesystem resize2fs-M resize an ext2, ext3 or ext4 filesystem to the minimum size resize2fs-size resize an ext2, ext3 or ext4 filesystem (with size) rm remove a file rm-f remove a file ignoring errors rm-rf remove a file or directory recursively rmdir remove a directory rmmountpoint remove a mountpoint rsync synchronize the contents of two directories rsync-in synchronize host or remote filesystem with filesystem rsync-out synchronize filesystem with host or remote filesystem scrub-device scrub (securely wipe) a device scrub-file scrub (securely wipe) a file scrub-freespace scrub (securely wipe) free space set-append add options to kernel command line set-attach-method set the attach method set-autosync set autosync mode set-cachedir set the appliance cache directory set-direct enable or disable direct appliance mode set-e2attrs set ext2 file attributes of a file set-e2generation set ext2 file generation of a file set-e2label set the ext2/3/4 filesystem label set-e2uuid set the ext2/3/4 filesystem UUID set-label set filesystem label set-libvirt-requested-credential pass requested credential back to libvirt set-libvirt-supported-credentials set libvirt credentials supported by calling program set-memsize set memory allocated to the qemu subprocess set-network set enable network flag set-path set the search path set-pgroup set process group flag set-qemu set the qemu binary set-recovery-proc enable or disable the recovery process set-selinux set SELinux enabled or disabled at appliance boot set-smp set number of virtual CPUs in appliance set-tmpdir set the temporary directory set-trace enable or disable command traces set-verbose set verbose mode setcon set SELinux security context setenv set an environment variable setxattr set extended attribute of a file or directory sfdisk create partitions on a block device sfdiskM create partitions on a block device sfdisk-N modify a single partition on a block device sfdisk-disk-geometry display the disk geometry from the partition table sfdisk-kernel-geometry display the kernel geometry sfdisk-l display the partition table sh run a command via the shell sh-lines run a command via the shell returning lines shutdown shutdown the qemu subprocess sleep sleep for some seconds sparse create a sparse disk image and add stat get file information statvfs get file system statistics strings print the printable strings in a file strings-e print the printable strings in a file supported list supported groups of commands swapoff-device disable swap on device swapoff-file disable swap on file swapoff-label disable swap on labeled swap partition swapoff-uuid disable swap on swap partition by UUID swapon-device enable swap on device swapon-file enable swap on file swapon-label enable swap on labeled swap partition swapon-uuid enable swap on swap partition by UUID sync sync disks, writes are flushed through to the disk image tail return last 10 lines of a file tail-n return last N lines of a file tar-in unpack tarfile to directory tar-out pack directory into tarfile tgz-in unpack compressed tarball to directory tgz-out pack directory into compressed tarball time print elapsed time taken to run a command touch update file timestamps or create a new file truncate truncate a file to zero size truncate-size truncate a file to a particular size tune2fs adjust ext2/ext3/ext4 filesystem parameters tune2fs-l get ext2/ext3/ext4 superblock details txz-in unpack compressed tarball to directory txz-out pack directory into compressed tarball umask set file mode creation mask (umask) umount unmount a filesystem umount-all unmount all filesystems umount-local unmount a locally mounted filesystem unsetenv unset an environment variable upload upload a file from the local machine upload-offset upload a file from the local machine with offset user-cancel cancel the current upload or download operation utimens set timestamp of a file with nanosecond precision utsname appliance kernel version version get the library version number vfs-label get the filesystem label vfs-type get the Linux VFS type corresponding to a mounted device vfs-uuid get the filesystem UUID vg-activate activate or deactivate some volume groups vg-activate-all activate or deactivate all volume groups vgchange-uuid generate a new random UUID for a volume group vgchange-uuid-all generate new random UUIDs for all volume groups vgcreate create an LVM volume group vglvuuids get the LV UUIDs of all LVs in the volume group vgmeta get volume group metadata vgpvuuids get the PV UUIDs containing the volume group vgremove remove an LVM volume group vgrename rename an LVM volume group vgs list the LVM volume groups (VGs) vgs-full list the LVM volume groups (VGs) vgscan rescan for LVM physical volumes, volume groups and logical volumes vguuid get the UUID of a volume group wc-c count characters in a file wc-l count lines in a file wc-w count words in a file wipefs wipe a filesystem signature from a device write create a new file write-append append content to end of file write-file create a file xfs-admin change parameters of an XFS filesystem xfs-growfs expand an existing XFS filesystem xfs-info get geometry of XFS filesystem xfs-repair repair an XFS filesystem zegrep return lines matching a pattern zegrepi return lines matching a pattern zero write zeroes to the device zero-device write zeroes to an entire device zero-free-space zero free space in a filesystem zerofree zero unused inodes and disk blocks on ext2/3 filesystem zfgrep return lines matching a pattern zfgrepi return lines matching a pattern zfile determine file type inside a compressed file zgrep return lines matching a pattern zgrepi return lines matching a pattern Use -h / help to show detailed help for a command.