KVM虚拟机--virt-install选项解释

本文详细介绍了virt-install命令的使用方法,包括基本选项、安装方法选项、存储配置、网络配置、图形配置、设备选项、虚拟化平台选项和其他选项。涵盖了如何通过libvirt URI连接虚拟机监控程序,以及如何配置内存、CPU、磁盘、网络接口和图形显示等。
[root@kvm-91 kvm]# virt-install --help
Options:
  --version             show program’s version number and exit
  -h, --help            show this help message and exit
  --connect=URI         Connect to hypervisor with libvirt URI
  ##使用libvirt URI连接到虚拟机监控程序
 *************************************************************************************
  General Options:  ##基本选项
    -n NAME, --name=NAME
                        Name of the guest instance
    --name=NAME  ##虚拟机实例名称
    -r MEMORY, --ram=MEMORY
                        Memory to allocate for guest instance in megabytes
	##--ram=MEMORY   为虚拟机实例分配的内存(兆字节)
    
--vcpus=VCPUS       Number of vcpus to configure for your guest. Ex:
                        --vcpus 5
                        --vcpus 5,maxcpus=10
                        --vcpus sockets=2,cores=4,threads=2
	## 为虚拟机分配cpu个数
--cpuset=CPUSET     Set which physical CPUs domain can use.
##设置可以使用的物理CPU域
--cpu=CPU           CPU model and features. Ex: --cpu coreduo,+x2apic
## CPU型号和特点。示例:--cpu Coredou,+x2apic
    --description=DESCRIPTION
                        Human readable description of the VM to store in the
                        generated XML.
	##要存储在生成的XML中的VM的可读描述
    --security=SECURITY
                        Set domain security driver configuration.
	##设置域安全驱动程序配置。
    --numatune=NUMATUNE
                        Tune NUMA policy for the domain process.
	##调整域进程的NUMA策略。
  ************************************************************************************************************
  Installation Method Options:  ##安装方法选项:
    -c CDROM, --cdrom=CDROM
                        CD-ROM installation media
	## CD-ROM安装介质
    -l LOCATION, --location=LOCATION
                        Installation source (eg, nfs:host:/path,
                        http://host/path, ftp://host/path)
--pxe               Boot from the network using the PXE protocol
##使用PXE协议从网络引导
--import            Build guest around an existing disk image
##在现有的磁盘映像周围构建客户机:--init/path/to/app(包含应用程序)
    --init=INIT         Path to init binary for container guest. Ex:
                        --init /path/to/app (to contain an application)
                        --init /sbin/init (for a full OS container)
	##容器来宾的初始化二进制文件的路径。前任:--init/path/to/app(包含应用程序)
						--init/sbin/init(对于完整的操作系统容器)
--livecd            Treat the CD-ROM media as a Live CD
##将CD-ROM介质视为实时CD
    -x EXTRA, --extra-args=EXTRA
                        Additional arguments to pass to the install kernel
                        booted from –location
	##要传递到从-location引导的安装内核的其他参数
    --initrd-inject=INITRD_INJECTIONS
                        Add given file to root of initrd from --location
    --os-type=DISTRO_TYPE
                        The OS type being installed, e.g. 'linux', 'unix',
                        'windows'
	##正在安装的操作系统类型,
    --os-variant=DISTRO_VARIANT
                        The OS variant being installed guests, e.g. 'fedora6',
                        'rhel5', 'solaris10', 'win2k'
	##正在安装的操作系统变体来宾
    --boot=BOOTOPTS     Optionally configure post-install boot order, menu,
                        permanent kernel boot, etc.
****************************************************************************************************************
  Storage Configuration:   存储配置:
    --disk=DISKOPTS     Specify storage with various options. Ex.
                        --disk path=/my/existing/disk
                        --disk path=/my/new/disk,size=5 (in gigabytes)
                        --disk vol=poolname:volname,device=cdrom,bus=scsi,...
##使用各种选项指定存储。
--nodisks           Don‘t set up any disks for the guest.
##不要为客人设置任何磁盘
    --filesystem=FILESYSTEMS
                        Pass host directory to the guest. Ex:
                        --filesystem /my/source/dir,/dir/in/guest
                        --filesystem template_name,/,type=template

  Networking Configuration:   ##网络配置
    -w NETWORK, --network=NETWORK
                        Configure a guest network interface. Ex:
                        --network bridge=mybr0   ##指定网卡
                        --network network=my_libvirt_virtual_net
                        --network network=mynet,model=virtio,mac=00:11...
    --nonetworks        Don’t create network interfaces for the guest.
****************************************************************************************************************
  Graphics Configuration:   ##图形配置
    --graphics=GRAPHICS
                        Configure guest display settings. Ex:
                        --graphics vnc
                        --graphics spice,port=5901,tlsport=5902
                        --graphics none
                        --graphics vnc,password=foobar,port=5910,keymap=ja
    --noautoconsole     Don’t automatically try to connect to the guest
                        console
    ##不要自动尝试连接到来宾控制台
*************************************************************************************************************
  Device Options:  ##设备选项
    --serial=SERIALS    Configure a guest serial device
    ##配置来宾串行设备
    --parallel=PARALLELS
                        Configure a guest parallel device
    ##配置来宾并行设备
    --channel=CHANNELS  Configure a guest communication channel
    ##配置来宾通信通道
    --console=CONSOLES  Configure a text console connection between the guest
                        and host
    ##配置来宾和主机之间的文本控制台连接
    --host-device=HOSTDEVS
                        Configure physical host devices attached to the guest
    ##配置连接到来宾的物理主机设备
    --soundhw=SOUNDHW   Configure guest sound device emulation
    --watchdog=WATCHDOG
                        Configure a guest watchdog device
    --video=VIDEO       Configure guest video hardware.
    --smartcard=SMARTCARD
                        Configure a guest smartcard device. Ex:
                        --smartcard mode=passthrough
    --redirdev=REDIRDEV
                        Configure a guest redirection device. Ex:
                        --redirdev usb,type=tcp,server=192.168.1.1:4000
    --panic=PANIC       Configure a guest panic device. Ex:
                        --panic default
***************************************************************************************************
  Virtualization Platform Options:  ##虚拟化平台选项
    -v, --hvm           This guest should be a fully virtualized guest
    ##此来宾应该是完全虚拟化的来宾
    -p, --paravirt      This guest should be a paravirtualized guest
    --container         This guest should be a container guest
    --virt-type=HV_TYPE
                        Hypervisor name to use (kvm, qemu, xen, ...)
    ##要使用的虚拟机监控程序名称
    --arch=ARCH         The CPU architecture to simulate
    --machine=MACHINE   The machine type to emulate
    --noapic            Disables APIC for fully virtualized guest (overrides
                        value in os-type/os-variant db)
    --noacpi            Disables ACPI for fully virtualized guest (overrides
                        value in os-type/os-variant db)
    -u UUID, --uuid=UUID
                        UUID for the guest.
***************************************************************************************************************
  Miscellaneous Options:  ##其他选项
    --autostart         Have domain autostart on host boot up.
    ##启动主机时让域自动启动
    --print-xml         Print the generated domain XML rather than define the
                        guest.
    --print-step=XMLSTEP
                        Print XML of a specific install step (1, 2, 3, all)
                        rather than define the guest.
    --noreboot          Don’t boot guest after completing install.
    --wait=WAIT         Time to wait (in minutes)
    --dry-run           Run through install process, but do not create devices
                        or define the guest.
    ##运行整个安装过程,但不要创建设备或定义来宾
    --force             Forces 'yes' for any applicable prompts, terminates
                        for all others
    -q, --quiet         Suppress non-error output
    --prompt            Request user input for ambiguous situations or
                        required options.
    -d, --debug         Print debugging information
    ##打印调试信息
### 如何使用 `virt-install` 命令创建 KVM 虚拟机 #### 创建虚拟机的基本命令结构 为了创建一个基于 KVM虚拟机,可以使用如下基本形式的 `virt-install` 命令: ```bash virt-install \ --name <vm_name> \ --memory <ram_size_in_MB> \ --vcpus=<number_of_vCPUs>,maxvcpus=<maximum_number_of_vCPUs> \ --disk path=<path_to_disk_image>,size=<disk_size_in_GB> \ --cdrom <path_to_iso_image> \ --network bridge=<bridge_interface> \ --graphics vnc,listen=0.0.0.0 \ --os-type linux \ --os-variant generic \ --console pty,target_type=serial \ --location <url_or_path_to_installation_media> ``` 上述命令中的参数可以根据实际需求调整[^2]。 #### 示例:创建名为 "my_vm" 的 CentOS 7 虚拟机 下面给出的是具体实例,该例子展示了怎样利用 ISO 文件来安装操作系统并设置初始硬件规格: ```bash virt-install \ --name my_vm \ --memory 2048 \ --vcpus 2 \ --disk size=10 \ --cdrom /var/lib/libvirt/images/CentOS-7-x86_64-Minimal-2009.iso \ --network bridge=virbr0 \ --graphics vnc,listen=0.0.0.0 \ --os-type linux \ --os-variant centos7.0 ``` 这条命令将会启动一个新的虚拟机,并尝试连接到所提供的 ISO 映像来进行操作系统的安装过程。注意这里的路径 `/var/lib/libvirt/images/CentOS-7-x86_64-Minimal-2009.iso` 应替换为你自己的 ISO 文件位置。 #### 设置高级选项 对于更复杂的场景,还可以添加更多选项来自定义新 VM 的行为。例如: - **指定 Hypervisor 类型**: 如果需要明确指出所使用的 hypervisor 是哪种(比如 kvm),可以通过 `--virt-type=kvm` 来实现。 - **启用自动启动功能**: 若要使虚拟机随宿主机一起开机自启,可加入 `--autostart` 参数。 - **选择虚拟化模式**: 对于那些既支持全虚拟化又支持半虚拟化的环境来说,可以选择特定的一种方式运行 guest OS (`--hvm` 表示完全虚拟化而 `--paravirt` 则表示半虚拟化)[^3]。 #### 注意事项 在执行以上任何一条指令之前,请确保已经正确设置了网络桥接接口 virbr0 或者其他合适的网卡名称作为桥梁设备的一部分。此外,在某些环境中可能还需要额外配置防火墙规则以便允许 VNC 连接访问新建的虚拟机控制台窗口。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值