Monday, January 24, 2022

Windows-11 + Vagrant + Hyper-V + Ubuntu-20.04 + KVM + CentOS-8.2

   - in this blog-post :

I'm installing Vagrant in Windows 11 ;

With Vagrant I'm creating and starting a VM in Hyper-V ;

In Hyper-V : I'm installing Ubuntu-20.04

In Ubuntu with KVM , QEMU and Libvirt : 

    - I'm playing with 3 CentOS-8.2 boxes .


Enable Hyper-V and Install Vagrant on Windows 10|11:

https://computingforgeeks.com/enable-hyper-v-and-install-vagrant-in-windows/

<<

Ensure you are running Powershell as Administrator:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

Enable-WindowsOptionalFeature -Online -FeatureName "SMB1Protocol" -All

>>


Downlolad and install Vagrant :

https://www.vagrantup.com/downloads

https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_x86_64.msi

https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_i686.msi



After reboot - adding our ( Ubuntu ) Vagrant Box into Hyper-V :

( Ensure you are still running Powershell as Administrator ) 


PS C:\Windows\system32>

PS C:\Windows\system32> vagrant init generic/ubuntu2004

A `Vagrantfile` has been placed in this directory. You are now

ready to `vagrant up` your first virtual environment! Please read

the comments in the Vagrantfile as well as documentation on

`vagrantup.com` for more information on using Vagrant.

PS C:\Windows\system32>

PS C:\Windows\system32>

PS C:\Windows\system32> vagrant up --provider hyperv

Bringing machine 'default' up with 'hyperv' provider...

==> default: Verifying Hyper-V is enabled...

==> default: Verifying Hyper-V is accessible...

==> default: Box 'generic/ubuntu2004' could not be found. Attempting to find and install...

default: Box Provider: hyperv

default: Box Version: >= 0

==> default: Loading metadata for box 'generic/ubuntu2004'

default: URL: https://vagrantcloud.com/generic/ubuntu2004

==> default: Adding box 'generic/ubuntu2004' (v3.6.4) for provider: hyperv

Downloading:

https://vagrantcloud.com/generic/boxes/ubuntu2004/versions/3.6.4/providers/hyperv.box

default: Calculating and comparing box checksum...

==> default: Successfully added box 'generic/ubuntu2004' (v3.6.4) for 'hyperv'!

==> default: Importing a Hyper-V instance

default: Creating and registering the VM...

default: Successfully imported VM

default: Configuring the VM...

default: Setting VM Enhanced session transport type to disabled/default (VMBus)

==> default: Starting the machine...

==> default: Waiting for the machine to report its IP address...

default: Timeout: 120 seconds

default: IP: 172.23.90.135

==> default: Waiting for machine to boot. This may take a few minutes...

default: SSH address: 172.23.90.135:22

default: SSH username: vagrant

default: SSH auth method: private key

default:

default: Vagrant insecure key detected. Vagrant will automatically replace

default: this with a newly generated keypair for better security.

default:

default: Inserting generated public key within guest...

default: Removing insecure key from the guest if it's present...

default: Key inserted! Disconnecting and reconnecting using new SSH key...

==> default: Machine booted and ready!

PS C:\Windows\system32>






PS C:\Windows\system32>

PS C:\Windows\system32> vagrant status

Current machine states:

              default running (hyperv)

PS C:\Windows\system32>

PS C:\Windows\system32>

PS C:\Windows\system32> vagrant ssh default

vagrant@ubuntu2004:~$

vagrant@ubuntu2004:~$ sudo su -

root@ubuntu2004:~#

root@ubuntu2004:~# cat /etc/*rele*

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=20.04

DISTRIB_CODENAME=focal

DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"

NAME="Ubuntu"

VERSION="20.04.3 LTS (Focal Fossa)"

ID=ubuntu

ID_LIKE=debian

PRETTY_NAME="Ubuntu 20.04.3 LTS"

VERSION_ID="20.04"

HOME_URL="https://www.ubuntu.com/"

SUPPORT_URL="https://help.ubuntu.com/"

BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"

PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"

VERSION_CODENAME=focal

UBUNTU_CODENAME=focal

root@ubuntu2004:~#


root@ubuntu2004:~# sudo apt update && sudo apt -y upgrade

root@ubuntu2004:~# apt install -y qemu-kvm libvirt-daemon-system bridge-utils genisoimage

root@ubuntu2004:~# systemctl status libvirtd

root@ubuntu2004:~# apt install libguestfs-tools libguestfs-xfs virt-top


root@ubuntu2004:~# apt install sshpass

root@ubuntu2004:~# apt install net-tools

root@ubuntu2004:~# apt install virtinst


# uncomment user & group "root" & restart libvirtd service : 

root@ubuntu2004:~# cat /etc/libvirt/qemu.conf | grep root

# By default libvirt runs VMs as non-root and uses AppArmor profiles

# root, /dev/vhost-net, /dev/vhost-vsock and /dev/vhost-scsi access is

# running as root would have direct access to this file. If changing this

# to run as root, you may want to remove this access from

user = "root"

group = "root"

# Minimum must be greater than 0, however when QEMU is not running as root,

# and uses; alternative is 'root'

root@ubuntu2004:~#

root@ubuntu2004:~# systemctl restart libvirtd


root@ubuntu2004:~/kvm# pwd

/root/kvm

root@ubuntu2004:~/kvm#


# virt-builder -l

# export LIBGUESTFS_BACKEND=direct


# virt-builder centos-8.2 --format qcow2 --size 12G \

   -o centos82a.qcow2 --root-password password


# virt-builder centos-8.2 --format qcow2 \

   -o centos82b.qcow2 --root-password password


# qemu-img resize /root/kvm/centos82b.qcow2 12G



root@ubuntu2004:~/kvm# virt-builder centos-8.2 \


            --format qcow2 --size 
12G -o centos82c.qcow2 \

            --root-password password

[   3.3] Downloading: http://builder.libguestfs.org/centos-8.2.xz

[   7.4] Planning how to build this image

[   7.4] Uncompressing

[  35.6] Resizing (using virt-resize) to expand the disk to 12.0G

[ 165.0] Opening the new disk

[ 185.1] Setting a random seed

[ 185.3] Setting passwords

[ 195.2] Finishing off

Output file: centos82c.qcow2

Output size: 12.0G

Output format: qcow2

Total usable space: 11.3G

Free space: 9.9G (87%)

root@ubuntu2004:~/kvm#

root@ubuntu2004:~/kvm#


root@ubuntu2004:~/kvm# 

     virt-install --name centos82a --ram 1024 \

                  --disk path=/root/kvm/centos82a.qcow2 \

                  --vcpus 1 --os-type linux --os-variant centos8 \

                  --network bridge=virbr0 --graphics none \

                  --serial pty --console pty --boot hd --import


# virt-install --name centos82b --ram 2048 \

               --disk path=/root/kvm/centos82b.qcow2 \

               --vcpus 2 --os-type linux --os-variant centos8 \

               --network bridge=virbr0 --graphics none \

               --serial pty --console pty --boot hd –import


#  virsh setmaxmem centos82b 8G

#  virsh setmem centos82b 6G --config


root@ubuntu2004:~/kvm# virt-install --name centos82c --ram 2048 \

      --disk path=/root/kvm/centos82c.qcow2 --vcpus 2 \

      --os-type linux --os-variant centos8 --network bridge=virbr0 \

      --graphics none --serial pty --console pty --boot hd --import




CentOS Linux 8 (Core)

Kernel 4.18.0-193.6.3.el8_2.x86_64 on an x86_64


localhost login: root

[root@localhost ~]#

[root@localhost ~]# passwd root



root@ubuntu2004:~#

root@ubuntu2004:~# arp -n

Address HWtype HWaddress Flags Mask Iface

172.23.80.1 ether 00:15:5d:36:52:16 C eth0

192.168.122.197 ether 52:54:00:5d:75:91 C virbr0

root@ubuntu2004:~#

root@ubuntu2004:~#


root@ubuntu2004:~# virsh start centos82b

Domain centos82b started


root@ubuntu2004:~# virsh shutdown centos82b

Domain centos82b is being shutdown



root@ubuntu2004:~#

root@ubuntu2004:~# virsh list --all

Id Name State

----------------------------

1 centos82c running

- centos82a shut off

- centos82b shut off


root@ubuntu2004:~#

root@ubuntu2004:~#

root@ubuntu2004:~# ssh root@192.168.122.197

The authenticity of host '192.168.122.197 (192.168.122.197)' can't be established.

ECDSA key fingerprint is SHA256:LAo3p2USa4Dmy5F3nTpkX7Uugs7ElZVhgb6Oh5ZJO+8.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added '192.168.122.197' (ECDSA) to the list of known hosts.

root@192.168.122.197's password:

Last login: Mon Jan 24 16:10:00 2022

[root@localhost ~]#

[root@localhost ~]# logout

Connection to 192.168.122.197 closed.

root@ubuntu2004:~#

root@ubuntu2004:~#

root@ubuntu2004:~# sshpass -p"toor" ssh root@192.168.122.197

Last login: Mon Jan 24 16:13:15 2022 from 192.168.122.1

[root@localhost ~]#


[root@localhost ~]# cat /etc/*rele*

CentOS Linux release 8.2.2004 (Core)

Derived from Red Hat Enterprise Linux 8.2 (Source)

NAME="CentOS Linux"

VERSION="8 (Core)"

ID="centos"

ID_LIKE="rhel fedora"

VERSION_ID="8"

PLATFORM_ID="platform:el8"

PRETTY_NAME="CentOS Linux 8 (Core)"

ANSI_COLOR="0;31"

CPE_NAME="cpe:/o:centos:centos:8"

HOME_URL="https://www.centos.org/"

BUG_REPORT_URL="https://bugs.centos.org/"


CENTOS_MANTISBT_PROJECT="CentOS-8"

CENTOS_MANTISBT_PROJECT_VERSION="8"

REDHAT_SUPPORT_PRODUCT="centos"

REDHAT_SUPPORT_PRODUCT_VERSION="8"


CentOS Linux release 8.2.2004 (Core)

CentOS Linux release 8.2.2004 (Core)

cpe:/o:centos:centos:8

[root@localhost ~]#




KVM on CentOS-7.5

https://www.server-world.info/en/note?os=CentOS_7&p=kvm&f=1

https://www.server-world.info/en/note?os=CentOS_7&p=kvm&f=2

https://www.server-world.info/en/note?os=CentOS_7&p=kvm&f=4

https://www.server-world.info/en/note?os=CentOS_7&p=kvm&f=9


Other nice KVM articles :

https://ostechnix.com/manage-kvm-virtual-machines-with-virsh-program/

https://ostechnix.com/how-to-find-the-ip-address-of-a-kvm-virtual-machine/

https://libguestfs.org/virt-builder.1.html

https://yping88.medium.com/building-and-installing-terraform-provider-for-libvirt-a08a29f93135

https://yping88.medium.com/provisioning-multiple-linux-distributions-using-terraform-provider-for-libvirt-632186f1c007

https://blog.programster.org/kvm-cheatsheet

https://linux.goffinet.org/administration/virtualisation-linux/virtualisation-kvm/


No comments:

Post a Comment