virt-install


 

 kvm 創建虛擬機
 
virsh console  57  連接 虛擬機
 

virt-install 命令說明

 

基本參數

  • --name
    必須的虛擬機名,唯一的。
  • --memory
    必須的內存容量,單位MB。
  • --vcpus
    可選的虛擬機cpu數量。更進一步可以通過該參數設置cpu熱拔插和其他更復雜的拓撲結構。
  • --os-variant
    可選項,指定guest操作系統,用於優化配置。可以通過命令osinfo-query os查詢支持的操作系統類型。
  • --graphics
    可選項,指定guest圖像顯示配置,如果不需要圖像顯示,可以使用--graphics none
  • --console
    可選項,virt-install會默認配置合適的console,可以不填。

存儲參數

  • --disk
    指定該虛擬機使用的存儲,有多種介質可選。比如指定本地文件可以使用path選項,如果指定文件不存在還需要設置size參數。如果不配置磁盤可以使用--disk none,一般用不到。

安裝源參數

安裝源可以有多種多則。常用的兩種:

  • --location
    指定新創建虛擬機的安裝介質。使用該參數指定安裝介質時,默認是看不到guest安裝過程中的輸出文本的,需要另外配置參數--extra-args 'console=ttyS0'
  • --import
    指定新創建虛擬機跳過安裝階段,使用第一個--disk參數指定的磁盤做啟動設備。

網絡連接

    • --network
      指定虛擬機連接的網絡配置,常用的兩種:
      • bridge=BRIDGE
        指定連接到host上名為BRIDGE的虛擬網橋上。
      • network=NAME
        指定連接到virsh管控的名為NAME的network上。

 

例子

創建一個虛擬機並指定安裝鏡像

1
2
3
4
5
6
7
8
9
10
11
12
#! /usr/bin/env bash

virt-install \
--name domain3 \
--memory 1024 \
--vcpus 2 \
--network network=default \
--graphics none \
--disk path=/var/kvm/images/domain3.img,size=30 \
--os-variant centos7.0 \
--location /var/kvm/CentOS-7-x86_64-Minimal-1804.iso \
--extra-args 'console=ttyS0'

上面的例子如果缺少--graphics none,開始安裝后將不會自動連接到console,可以使用命令virsh console domain3連接到console進行文本模式的安裝過程。操作系統安裝完成后可能會處於關機狀態,可以使用命令virsh start domain3開機。

可以使用如下命令從domain3克隆一個新虛擬機domain4並指定存儲文件,其中name和file參數可以使用--auto-clone替代。克隆的虛擬機必須處於shutdown或pause狀態。
virt-clone --original domain3 --name domain4 --file /var/kvm/images/domain4.img

對domain4關機並從libvirt中刪除。

virsh shutdown domain4,這里如果不能正常關機可以使用virsh destroy domain4做斷電操作。
virsh undefine domain4

這時domain4的磁盤文件並沒有被刪除,這里使用該磁盤文件import一個新虛擬機domain5。

 

從舊磁盤文件導入創建一個新虛擬機

1
2
3
4
5
6
7
8
9
10
11
#! /usr/bin/env bash

virt-install \
--name domain5 \
--memory 2048 \
--vcpus 3 \
--network network=default \
--graphics none \
--disk path=/var/kvm/images/domain4.img \
--os-variant centos7.0 \
--import

 

例子(EXAMPLES)

       Install a KVM guest, creating a new storage file, virtual networking, booting from the host CDROM, using VNC server/viewer

         # virt-install \
              --connect qemu:///system \
              --name demo \
              --ram 500 \
              --disk path=/var/lib/libvirt/images/demo.img,size=5 \
              --network network:default \
              --accelerate \
              --vnc \
              --cdrom /dev/cdrom

       Install a Fedora 9 KVM guest, using LVM partition, virtual networking, booting from PXE, using VNC server/viewer

         # virt-install \
              --connect qemu:///system \
              --name demo \
              --ram 500 \
              --disk path=/dev/HostVG/DemoVM \
              --network network:default \
              --accelerate \
              --vnc \
              --os-variant fedora9

       Install a QEMU guest, with a real partition, for a different architecture using SDL graphics, using a remote kernel and initrd pair:

         # virt-install \
              --connect qemu:///system \
              --name demo \
              --ram 500 \
              --disk path=/dev/hdc \
              --network bridge:eth1 \
              --arch ppc64 \
              --arch ppc64 \
              --sdl \
              --location http://download.fedora.redhat.com/pub/fedora/linux/core/6/x86_64/os/

       Run a Live CD image under Xen fullyvirt, in diskless environment

         # virt-install \
              --hvm \
              --name demo \
              --ram 500 \
              --nodisks \
              --livecd \
              --vnc \
              --cdrom /root/fedora7live.iso

       Install a paravirtualized Xen guest, 500 MB of RAM, a 5 GB of disk, and Fedora Core 6 from a web server, in text-only mode, with old style
       --file options:

         # virt-install \
              --paravirt \
              --name demo \
              --ram 500 \
              --file /var/lib/xen/images/demo.img \
              --file-size 6 \
              --nographics \
              --location http://download.fedora.redhat.com/pub/fedora/linux/core/6/x86_64/os/

       Create a guest from an existing disk image ’mydisk.img’ using defaults for the rest of the options.

         # virt-install \
              --name demo
              --ram 512
              --disk path=/home/user/VMs/mydisk.img
              --import

 

參考:

https://www.cnblogs.com/liang-wei/p/6732055.html

http://www.hyuuhit.com/2018/11/20/virt-install/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM