[KVM] 从kickstart文件创建虚拟机

环境:宿主机RHEL7.6, iso + kickstart.cfg 拉起虚拟机

1.创建volume

# cd /var/lib/libvirt/images  -> 默认给虚拟机的硬盘会放在该路径
# virsh vol-create-as default test.qcow2 8G --format qcow2

注意:这里给的大小要大于待拉起虚拟机需要的磁盘大小

2.上传iso文件、kickstart文件

kickstart文件需要注意 ==>

1)sda需要改成vda

2)由于不是物理机挂载,可以将类似以下行注释

ignoredisk --drives=disk/by-label/SOMELABEL

补充:这个LABEL对应于如下页面按Tab 修改为从kickstart img启动

vmlinuz initrd=initrd.img inst.stage2-hd:LABEL=RHEL-8-4-0-BaseOS-x86_64 inst.ks=hd:LABEL=SOMELABEL:/test-ks.cfg

3)磁盘分区的总大小在步骤1中要预留出来

3.创建虚拟机

virt-install --name=KVM-1 --ram=16384 --vcpu 4 --autostart --os-type=linux --os-variant=rhel7 --disk vol=default/test.qcow2 --location=/var/www/html/rhel-server-7.6-x86_64-dvd.iso --key=en-us -w bridge:br0 --initrd-inject=/var/ftp/ks/test-ks.cfg -x "ks=file:/test-ks.cfg ksdevice=eth0 ip=10.100.173.34 netmask=255.255.255.192 gateway=10.100.173.1"

说明:

--ram=16384 --vcpu 4   => 内存16G,CPU 4,宿主机CPU个数用命令lscpu查看

--os-variant=rhel7   => 通过命令 osinfo-query os 查看 

# osinfo-query os
 Short ID             | Name                                               | Version  | ID
----------------------+----------------------------------------------------+----------+-----------------------------------------
 alpinelinux3.5       | Alpine Linux 3.5                                   | 3.5      | http://alpinelinux.org/alpinelinux/3.5
……
 centos7.0            | CentOS 7.0                                         | 7.0      | http://centos.org/centos/7.0
……
 rhel7.0              | Red Hat Enterprise Linux 7.0                       | 7.0      | http://redhat.com/rhel/7.0
……

--disk vol=default/test.qcow2    => 步骤1创建的qcow2

--location=/var/www/html/rhel-server-7.6-x86_64-dvd.iso   => 放置iso文件的路径

--initrd-inject=/var/ftp/ks/test-ks.cfg   => 放置kickstart配置文件的路径

-x "ks=file:/test-ks.cfg console=ttyS0,115200 ksdevice=eth0 ip=10.100.173.34 netmask=255.255.255.192 gateway=10.100.173.1"   => 其它参数,如果加了console=ttyS0,115200参数需要用串口console,在主机上 virsh console <vm_name>

(说明:即使命令里也给出了网络参数,安装的过程还是会让输入,配置后环境运行正常)

 附:virt-install --help

# virt-install --help
usage: virt-install --name NAME --memory MB STORAGE INSTALL [options]

Create a new virtual machine from specified install media.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --connect URI         Connect to hypervisor with libvirt URI

General Options:
  -n NAME, --name NAME  Name of the guest instance
  --memory MEMORY       Configure guest memory allocation. Ex:
                        --memory 1024 (in MiB)
                        --memory 512,maxmemory=1024
                        --memory 512,maxmemory=1024,hotplugmemorymax=2048,hotplugmemoryslots=2
  --vcpus VCPUS         Number of vcpus to configure for your guest. Ex:
                        --vcpus 5
                        --vcpus 5,maxcpus=10,cpuset=1-4,6,8
                        --vcpus sockets=2,cores=4,threads=2,
  --cpu CPU             CPU model and features. Ex:
                        --cpu coreduo,+x2apic
                        --cpu host-passthrough
                        --cpu host
  --metadata METADATA   Configure guest metadata. Ex:
                        --metadata name=foo,title="My pretty title",uuid=...
                        --metadata description="My nice long description"

Installation Method Options:
  --cdrom CDROM         CD-ROM installation media
  -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
  --import              Build guest around an existing disk image
  --livecd              Treat the CD-ROM media as a Live CD
  -x EXTRA_ARGS, --extra-args EXTRA_ARGS
                        Additional arguments to pass to the install kernel
                        booted from --location
  --initrd-inject INITRD_INJECT
                        Add given file to root of initrd from --location
  --os-variant DISTRO_VARIANT
                        The OS variant being installed guests, e.g.
                        'fedora18', 'rhel6', 'winxp', etc.
  --boot BOOT           Configure guest boot settings. Ex:
                        --boot hd,cdrom,menu=on
                        --boot init=/sbin/init (for containers)
  --idmap IDMAP         Enable user namespace for LXC container. Ex:
                        --idmap uid_start=0,uid_target=1000,uid_count=10

Device Options:
  --disk DISK           Specify storage with various options. Ex.
                        --disk size=10 (new 10GiB image in default location)
                        --disk /my/existing/disk,cache=none
                        --disk device=cdrom,bus=scsi
                        --disk=?
  -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...
                        --network none
                        --network help
  --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
  --controller CONTROLLER
                        Configure a guest controller device. Ex:
                        --controller type=usb,model=ich9-ehci1
  --input INPUT         Configure a guest input device. Ex:
                        --input tablet
                        --input keyboard,bus=usb
  --serial SERIAL       Configure a guest serial device
  --parallel PARALLEL   Configure a guest parallel device
  --channel CHANNEL     Configure a guest communication channel
  --console CONSOLE     Configure a text console connection between the guest
                        and host
  --hostdev HOSTDEV     Configure physical USB/PCI/etc host devices to be
                        shared with the guest
  --filesystem FILESYSTEM
                        Pass host directory to the guest. Ex:
                        --filesystem /my/source/dir,/dir/in/guest
                        --filesystem template_name,/,type=template
  --sound [SOUND]       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
  --memballoon MEMBALLOON
                        Configure a guest memballoon device. Ex:
                        --memballoon model=virtio
  --tpm TPM             Configure a guest TPM device. Ex:
                        --tpm /dev/tpm
  --rng RNG             Configure a guest RNG device. Ex:
                        --rng /dev/urandom
  --panic PANIC         Configure a guest panic device. Ex:
                        --panic default
  --memdev MEMDEV       Configure a guest memory device. Ex:
                        --memdev dimm,target_size=1024

Guest Configuration Options:
  --security SECURITY   Set domain security driver configuration.
  --cputune CPUTUNE     Tune CPU parameters for the domain process.
  --numatune NUMATUNE   Tune NUMA policy for the domain process.
  --memtune MEMTUNE     Tune memory policy for the domain process.
  --blkiotune BLKIOTUNE
                        Tune blkio policy for the domain process.
  --memorybacking MEMORYBACKING
                        Set memory backing policy for the domain process. Ex:
                        --memorybacking hugepages=on
  --features FEATURES   Set domain <features> XML. Ex:
                        --features acpi=off
                        --features apic=on,eoi=on
  --clock CLOCK         Set domain <clock> XML. Ex:
                        --clock offset=localtime,rtc_tickpolicy=catchup
  --pm PM               Configure VM power management features
  --events EVENTS       Configure VM lifecycle management policy
  --resource RESOURCE   Configure VM resource partitioning (cgroups)
  --sysinfo SYSINFO     Configure SMBIOS System Information. Ex:
                        --sysinfo emulate
                        --sysinfo host
                        --sysinfo bios_vendor=Vendor_Inc.,bios_version=1.2.3-abc,...
                        --sysinfo system_manufacturer=System_Corp.,system_product=Computer,...
                        --sysinfo baseBoard_manufacturer=Baseboard_Corp.,baseBoard_product=Motherboard,...
  --qemu-commandline QEMU_COMMANDLINE
                        Pass arguments directly to the qemu emulator. Ex:
                        --qemu-commandline='-display gtk,gl=on'
                        --qemu-commandline env=DISPLAY=:0.1

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

Miscellaneous Options:
  --autostart           Have domain autostart on host boot up.
  --transient           Create a transient domain.
  --wait WAIT           Minutes to wait for install to complete.
  --noautoconsole       Don't automatically try to connect to the guest
                        console
  --noreboot            Don't boot guest after completing install.
  --print-xml [XMLONLY]
                        Print the generated domain XML rather than create the
                        guest.
  --dry-run             Run through install process, but do not create devices
                        or define the guest.
  --check CHECK         Enable or disable validation checks. Example:
                        --check path_in_use=off
                        --check all=off
  -q, --quiet           Suppress non-error output
  -d, --debug           Print debugging information

Use '--option=?' or '--option help' to see available suboptions
See man page for examples and full option syntax.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值