CentOS 7 - Using KVM with CLI(console)


  1. Our Server Setup.


  1. Installation media ISO.

2.1 ISO image

We store our Linux ISO images under the storage pool directory "default" [/vm/images] while our KVM guest images will be stored under the storage pool directory "storage-1TB" [/vm/storage-1TB].

Let's download the latest CentOS 7 Minimal ISO and store it under the storage pool directory "default".
[root@node1 ~]# wget http://ftp.belnet.be/ftp.centos.org/7/isos/x86_64/CentOS-7-x86_64-Minimal-1611.iso -P /vm/images
[root@node1 ~]# wget http://ftp.belnet.be/ftp.centos.org/7/isos/x86_64/sha256sum.txt -P /vm/images

Validate the ISO file.
[root@node1 ~]# cd /vm/images
[root@node1 images]# sha256sum -c sha256sum.txt 2>&1 | grep OK
CentOS-7-x86_64-Minimal-1611.iso: OK

[root@node1 images]# cd


2.2 Running virt-install to Build the KVM Guest System.

Overview arguments.
--connect : Connect to a non-default hypervisor.
--accelerate : When installing a QEMU guest, make use of the KVM or KQEMU kernel acceleration capabilities if available. Use of this option is recommended unless a guest OS is known to be incompatible with the accelerators. The KVM accelerator is preferred over KQEMU if both are available.
--arch : Request a non-native CPU architecture for the guest virtual machine. The option is only currently available with QEMU guests, and will not enable use of acceleration. If omitted, the host CPU architecture will be used in the guest.
--check-cpu : Check that the number virtual cpus requested does not exceed physical CPUs and warn if they do.
--disk : To specify media, one of the following options is required:
  • bus - Disk bus type. Value can be ’ide’, ’scsi’, ’usb’, ’virtio’ or ’xen’. The default is hypervisor dependent since not all hypervisors support all bus types.
  • format - Disk image format. For file volumes, this can be 'raw', 'qcow2', 'vmdk', etc.
  • pool - An existing libvirt storage pool name to create new storage on. Requires specifying a ’size’ value.
  • size - size (in GB) to use if creating new storage.
  • sparse - whether to skip fully allocating newly created storage. Value is ’true’ or ’false’. Default is ’true’ (do not fully allocate). The initial time taken to fully-allocate the guest virtual disk (spare=false) will be usually by balanced by faster install times inside the guest. Thus use of this option is recommended to ensure consistently high performance and to avoid I/O errors in the guest should the host filesystem fill up.
--extra-args : Additional kernel command line arguments to pass to the installer when performing a guest install from "--location".
--hvm : Request the use of full virtualization, if both para & full virtualization are available on the host. This parameter may not be available if connecting to a Xen hypervisor on a machine without hardware virtualization support. This parameter is implied if connecting to a QEMU based hypervisor.
--location : Installation source for guest virtual machine kernel+initrd pair. The "LOCATION" can take one of the following forms:
  • DIRECTORY - Path to a local directory containing an installable distribution image.
  • nfs://host/path - An NFS server location containing an installable distribution image.
  • http://host/path - An HTTP server location containing an installable distribution image.
  • ftp://host/path - An FTP server location containing an installable distribution image.
--memory : Memory to allocate for guest instance in megabytes. If the hypervisor does not have enough free memory, it is usual for it to automatically take memory away from the host operating system to satisfy this allocation.
--metadata : Specify metadata values for the guest. Possible options include name, uuid, title, and description.
--name : Name of the new guest virtual machine instance. This must be unique amongst all guests known to the hypervisor on the connection, including those not currently active.
--network : Connect the guest to the host network. The value for "NETWORK" can take one of 3 formats:
  • bridge=BRIDGE - Connect to a bridge device in the host called "BRIDGE". Use this option if the host has static networking config & the guest requires full outbound and inbound connectivity to/from the LAN. Also use this if live migration will be used with this guest.
  • network=NAME - Connect to a virtual network in the host called "NAME". Virtual networks can be listed, created, deleted using the "virsh" command line tool. In an unmodified install of "libvirt" there is usually a virtual network with a name of "default". Use a virtual network if the host has dynamic networking (eg NetworkManager), or using wireless. The guest will be NATed to the LAN by whichever connection is active.
  • user - Connect to the LAN using SLIRP. Only use this if running a QEMU guest as an unprivileged user. This provides a very limited form of NAT.
Other available options are:
  • model - Network device model as seen by the guest. Value can be any nic model supported by the hypervisor, e.g.: 'e1000', 'rtl8139', 'virtio', ... .
  • mac - Fixed MAC address for the guest; If this parameter is omitted, or the value "RANDOM" is specified a suitable address will be randomly generated. For Xen virtual machines it is required that the first 3 pairs in the MAC address be the sequence '00:16:3e', while for QEMU or KVM virtual machines it must be '52:54:00'
--nographics : No graphical console will be allocated for the guest. Fully virtualized guests (Xen FV or QEmu/KVM) will need to have a text console configured on the first serial port in the guest (this can be done via the --extra-args option). Xen PV will set this up automatically. The command ’virsh console NAME’ can be used to connect to the serial device.
--os-type : Optimize the guest configuration for a type of operating system (ex. ’linux’, ’windows’). This will attempt to pick the most suitable ACPI & APIC settings, optimally supported mouse drivers, virtio, and generally accommodate other operating system quirks.
--os-variant : Further optimize the guest configuration for a specific operating system variant (ex. ’fedora8’, ’winxp’).
--vcpus : Number of virtual cpus to configure for the guest. Not all hypervisors support SMP guests, in which case this argument will be silently ignored.

Let’s build the KVM guest machine.
[root@node1 ~]# virt-install --connect qemu:///system --accelerate --arch x86_64 --check-cpu --disk bus=virtio,format=qcow2,pool=storage-1TB,size=5,sparse=false --extra-args='console=tty0 console=ttyS0,115200n8 serial' --hvm --location=/vm/images/CentOS-7-x86_64-Minimal-1611.iso --memory 1024 --metadata title="[CentOS] - test01.server.lab",description="VM Guest" --name test01 --network=bridge:server,model=virtio,mac=52:54:00:4a:a4:44 --nographics --os-type linux --os-variant centos7.0 --vcpus=1
Starting install...
Retrieving file .treeinfo...
Retrieving file vmlinuz...
Retrieving file initrd.img...
Allocating 'test01.qcow2'
Creating domain...
Connected to domain test01
Escape charachter is ^]
....

Escape character ^] is key combination CTRL + ALT GR + ]


2.3 Remove CD-ROM disk.

After your OS installation, you can remove the attach CDROM disk.

Print information about existing domains (active and inactive).
[root@node1 ~]# virsh list --all
Id Name State
------------------------------------- ------------------------------------- -------------------------------------
11 test01 running

Print a table showing the brief information of all block devices associated with domain.
[root@node1 ~]# virsh domblklist test01
Target Source
------------------------------------- --------------------------------------------------------------------------
vda /vm/storage-1TB/test01.qcow2
hda -

Gracefully shuts down our domain "test01".
[root@node1 ~]# virsh shutdown test01
Domain test01 is being shutdown

Detach a disk device.
[root@node1 ~]# virsh detach-disk test01 hda --persistent
Disk detached successfully

Start domain and check.
[root@node1 ~]# virsh start test01
Domain test01 started


# Print a table showing the brief information of all block devices associated with domain.
[root@node1 ~]# virsh domblklist test01

Target Source
------------------------------------- --------------------------------------------------------------------------
vda /vm/storage-1TB/test01.qcow2


  1. Installation via HTTP.

Compare with the installation media ISO we need to alter two virt-install arguments to initiate the installation via HTTP.
With the argument --extra-args we need to add additional parameters like:
  • ksdevice - Define a specific network interface to kickstart.
  • ip - Define an IP address with the IP subnet of your VLAN.
  • netmask - A netmask is a 32-bit mask used to divide an IP address into subnets and specify the network's available hosts.
  • gateway - A networked device which serves as an entry point into another network.
  • dns - Helps to point domain names or hostnames to their associated Internet Protocol address.
Change the --location argument to an HTTP server location containing an installable distribution image.

Let’s build the KVM guest machine.
[root@node1 ~]# virt-install --connect qemu:///system --accelerate --arch x86_64 --check-cpu --disk bus=virtio,format=qcow2,pool=storage-1TB,size=5,sparse=false --extra-args='console=tty0 console=ttyS0,115200n8 serial,ksdevice=eth0 ip=10.0.6.28 netmask=255.255.255.192 dns=8.8.8.8 gateway=10.0.6.1' --hvm --location 'http://ftp.belnet.be/ftp.centos.org/7/os/x86_64/' --memory 1024 --metadata title="[CentOS] -test02.server.lab",description="VM Guest" --name test02 --network=bridge:server,model=virtio,mac=52:54:00:5a:a5:55 --nographics --os-type linux --os-variant centos7.0 --vcpus=1
Starting install...
Retrieving file .treeinfo...
Retrieving file vmlinuz...
Retrieving file initrd.img...
Allocating 'test02.qcow2'
Creating domain...
Connected to domain test02
Escape charachter is ^]
....

Escape character ^] is key combination CTRL + ALT GR + ]

Geen opmerkingen:

Een reactie posten