libguestfs手册(3): virt命令

本文详细介绍了如何使用virt-builder工具快速构建虚拟机,包括设置虚拟机格式、大小、根密码、主机名、安装软件及首次启动脚本等步骤,并展示了如何通过命令行管理虚拟机的文件系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

guestmount

root# guestmount -a ubuntutest1.img -m /dev/sda1 ubuntutestp1
root# cd ubuntutestp1/
root:/home/cliu8/images/ubuntutestp1# ls
a  b  c  d  hello  lost+found  world
root:/home/cliu8/images/ubuntutestp1# ps aux | grep guest
root     31067  2.5  0.1 2895156 90544 pts/0   Sl   22:05   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.31058 -initrd /var/tmp/.guestfs-0/initrd.31058 -device virtio-scsi-pci,id=scsi -drive file=ubuntutest1.img,cache=writeback,id=hd0,if=none -device scsi-hd,drive=hd0 -drive file=/var/tmp/.guestfs-0/root.31058,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/libguestfsgJ82Aq/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/sdb selinux=0 TERM=linux
root     31092  0.0  0.0  91024  1688 ?        Ss   22:05   0:00 guestmount -a ubuntutest1.img -m /dev/sda1 ubuntutestp1

root:/home/cliu8/images# guestunmount ubuntutestp1
root:/home/cliu8/images# ps aux | grep guest
root     31477  0.0  0.0  10464   920 pts/0    S+   22:09   0:00 grep --color=auto guest

virt-builder

Virt-builder is a tool for quickly building new virtual machines. You can build a variety of VMs for local or cloud use, usually within a few minutes or less. Virt-builder also has many ways to customize these VMs. Everything is run from the command line and nothing requires root privileges, so automation and scripting is simple.

List the virtual machines available

# virt-builder --list                               
centos-6                 CentOS 6.5
centos-7.0               CentOS 7.0
cirros-0.3.1             CirrOS 0.3.1
debian-6                 Debian 6 (Squeeze)
debian-7                 Debian 7 (Wheezy)
fedora-18                Fedora庐 18
fedora-19                Fedora庐 19
fedora-20                Fedora庐 20
rhel-7rc                 Red Hat Enterprise Linux庐 7 Release Candidate
scientificlinux-6        Scientific Linux 6.5
ubuntu-10.04             Ubuntu 10.04 (Lucid)
ubuntu-12.04             Ubuntu 12.04 (Precise)
ubuntu-14.04             Ubuntu 14.04 (Trusty)

Build a virtual machine
virt-builder fedora-20
virt-builder fedora-20 -o mydisk.img
virt-builder fedora-20 --format qcow2
virt-builder fedora-20 --size 20G
Setting the root password
virt-builder fedora-20 --root-password file:/tmp/rootpw
Set the hostname
virt-builder fedora-20 --hostname virt.example.com
Installing software
virt-builder fedora-20 --install "inkscape,@Xfce Desktop"
Customizing the installation
 cat <<'EOF' > /tmp/yum-update.sh
 yum -y update
 EOF
 
 virt-builder fedora-20 --firstboot /tmp/yum-update.sh

virt系列

root:/home/cliu8/images# virt-ls -a ubuntutest.img /home/openstack
.bash_history
.bash_logout
.bashrc
.cache
.profile
sdb
testupload

root:/home/cliu8/images# while true; do sleep 1; ps aux | grep guest; done;
root      2381  0.0  0.0  10464   920 pts/22   S+   22:21   0:00 grep --color=auto guest
root      2392 22.0  0.0 938600 25116 pts/0    Sl+  22:21   0:00 /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.2383 -initrd /var/tmp/.guestfs-0/initrd.2383 -device virtio-scsi-pci,id=scsi -drive file=ubuntutest.img,snapshot=on,cache=writeback,id=hd0,if=none -device scsi-hd,drive=hd0 -drive file=/var/tmp/.guestfs-0/root.2383,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/libguestfsxG2Amp/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/sdb selinux=0 TERM=linux
root      2417  0.0  0.0  10464   920 pts/22   S+   22:21   0:00 grep --color=auto guest
root      2426  0.0  0.0  10464   924 pts/22   S+   22:21   0:00 grep --color=auto guest

virt-cat(1) — display a file
virt-copy-in(1) — copy files and directories into a VM
virt-copy-out(1) — copy files and directories out of a VM
virt-customize(1) — customize virtual machines
virt-df(1) — free space
virt-diff(1) — differences
virt-edit(1) — edit a file
virt-filesystems(1) — display information about filesystems, devices, LVM
virt-format(1) — erase and make blank disks
virt-inspector(1) — inspect VM images
virt-list-filesystems(1) — list filesystems
virt-list-partitions(1) — list partitions
virt-log(1) — display log files
virt-ls(1) — list files
virt-make-fs(1) — make a filesystem
virt-rescue(1) — rescue shell
virt-resize(1) — resize virtual machines
virt-sparsify(1) — make virtual machines sparse (thin-provisioned)
virt-sysprep(1) — unconfigure a virtual machine before cloning
virt-tar(1) — archive and upload files
virt-tar-in(1) — archive and upload files
virt-tar-out(1) — archive and download files
virt-win-reg(1) — export and merge Windows Registry keys

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值