lost and found ( for me ? )

Showing posts with label virt-install. Show all posts
Showing posts with label virt-install. Show all posts

KVM : Create CentOS7 VM with zero touch by using virt-install and kickstart

Here are logs when I built a CentOS7 VM with zero touch by using virt-install and kickstart file.

KVM host
$ tail -1 /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"

$ virt-install --version
1.3.2

Download ISO and prepare kickstart file.

ISO
CentOS-7-x86_64-Minimal-1611.iso

kickstart file
$ cat cent7.ks
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use CDROM installation media
cdrom
# Use text mode install
text
# Firewall configuration
firewall --disabled
firstboot --disable
ignoredisk --only-use=vda
# Keyboard layouts
# old format: keyboard jp106
# new format:
keyboard --vckeymap=jp106 --xlayouts='jp'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=eth0 --hostname=localhost --noipv6
# Reboot after installation
reboot
# Root password
rootpw --plaintext password
# SELinux configuration
selinux --disabled
# System services
services --enabled="chronyd"
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Tokyo --isUtc
# System bootloader configuration
bootloader --append="rhgb quiet crashkernel=auto" --location=mbr --boot-drive=vda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
part / --fstype=ext4 --grow --asprimary --size=1

%packages --nobase --ignoremissing
@core
chrony
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

install
$ sudo virt-install  -n cent7-01 --memory 2048 -f /var/lib/libvirt/images/cent7-01.qcow2,size=20,format=qcow2,bus=virtio,cache=none --vcpus=1 --os-type linux --os-variant centos7.0 --location /home/hattori/ISO_images/CentOS-7-x86_64-Minimal-1611.iso --extra-args='ks=file:/cent7.ks console=tty0 console=ttyS0,115200n8' --keymap ja --initrd-inject ./cent7.ks --network=default,model=virtio --noautoconsole

connect to the VM to see progress.
$ virsh console cent7-01
Starting install...
Retrieving file .treeinfo...                                                                        |  366 B  00:00:00
Retrieving file vmlinuz...                                                                          | 5.1 MB  00:00:00
Retrieving file initrd.img...                                                                       |  41 MB  00:00:00
<snip>
Progress
Setting up the installation environment
.
Creating disklabel on /dev/vda
.
Creating ext4 on /dev/vda1
.
Running pre-installation scripts
.
Starting package installation process
Preparing transaction from installation source
Installing libgcc (1/297)
Installing centos-release (2/297)
Installing setup (3/297)
<snip>
[  OK  ] Stopped LVM2 metadata daemon.
[  OK  ] Started Restore /run/initramfs.
[  OK  ] Reached target Shutdown.
dracut Warning: Killing all remaining processes
Rebooting.
[  194.849928] Restarting system.

get things done.
$ virsh list --all
Id    Name                           State
----------------------------------------------------
-     cent7-01                       shut off

$ virsh start cent7-01

$ virsh console cnet7-01
localhost login: root
Password:
[root@localhost ~]#

KVM : build Ubuntu 14.04 VM via CLI(virt-install)

You can easily build VMs with virt-install ( no GUI )

The procedures are:

Download ISO
Mount ISO locally
Build VM with virt-install

Here are logs when building Ubuntu 14.04 VMs within Ubuntu13.10 KVM host.

KVM host
# tail -1 /etc/lsb-release ; uname -ri
DISTRIB_DESCRIPTION="Ubuntu 13.10"
3.11.0-20-generic x86_64

#  qemu-system-x86_64 -version
QEMU emulator version 1.5.0 (Debian 1.5.0+dfsg-3ubuntu5.4), Copyright (c) 2003-2008 Fabrice Bellard

download ISO
ubuntu-14.04-server-amd64.iso

mount ISO
# mount -t iso9660 -o loop ubuntu-14.04-server-amd64.iso /var/iso-mnt

build VM. ( memory 512M, vHDD 10GB )
# virt-install --connect qemu:///system -n ubuntu1404-vm1 -s 10 -r 512 -f /var/lib/KVM_images/ubuntu1404-vm1.img --vcpus=1 --os-type linux --os-variant ubuntutrusty --nographics  --location /var/iso-mnt  --extra-args='console=tty0 console=ttyS0,115200n8' --keymap ja



Ubuntu 13.10 KVM: build VMs without VNC by using virt-install

Here are logs when building VMs via virt-install without VNC.

# virt-install --version
0.600.4

error..
# virt-install --name ubuntu1204-varm -r 1024 --vcpus=2 --os-type=linux --os-variant=ubuntuprecise --disk path=/var/lib/KVM_images/ubuntu1204-varm.qcow2,size=10,format=qcow2 --cdrom  /home/hattori/ISO_files/ubuntu-12.04.1-server-amd64.iso --accelerate  --nographics --network network=default,model=virtio --hvm --extra-args='console=tty0 console=ttyS0,115200n8 serial'
ERROR    --extra-args は --location とともに指定する場合のみ機能します。

when using --extra-args option, I need to use --location instead of --cdrom option.

I need to specify nfs or http or ftp path when using --location.
nfs:host:/path or 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

To specify http path, create a directory to mount ISO
# mkdir /var/www/mnt

mount the ISO
# mount -t iso9660 -o loop /home/hattori/ISO_files/ubuntu-12.04.1-server-amd64.iso /var/www/mnt
mount: block device /home/hattori/ISO_files/ubuntu-12.04.1-server-amd64.iso is write-protected, mounting read-only

# ls /var/www/mnt/
boot          dists  efi      isolinux    pics  preseed             ubuntu
cdromupgrade  doc    install  md5sum.txt  pool  README.diskdefines

start apache2
# apache2ctl start

Now, you can specify installable image over http.

try again.
Okay, I can install ubuntu via console without VNC.
virt-install --name ubuntu1204-varm -r 1024 --vcpus=2 --os-type=linux --os-variant=ubuntuprecise --disk path=/var/lib/KVM_images/ubuntu1204-varm.qcow2,size=10,format=qcow2 --location http://127.0.0.1/mnt --accelerate  --nographics --network network=default,model=virtio --hvm --extra-args='console=tty0 console=ttyS0,115200n8 serial'

Starting install...
Retrieving file version.info...                          |  116 B     00:00 ...
Retrieving file linux...                                 | 9.5 MB     00:00 ...
Retrieving file initrd.gz...                             |  33 MB     00:00 ...
Creating domain...                                       |    0 B     00:00     
Connected to domain ubuntu1204-varm
Escape character is ^]
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Linux version 3.2.0-29-generic (buildd@allspice) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 (Ubuntu 3.2.0-29.46-generic 3.2.24)
[    0.000000] Command line: method=http://127.0.0.1/mnt console=tty0 console=ttyS0,115200n8
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
[    0.000000]  BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved)
[    0.000000]  BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved)
[    0.000000]  BIOS-e820: 0000000000100000 - 000000003fffe000 (usable)
[    0.000000]  BIOS-e820: 000000003fffe000 - 0000000040000000 (reserved)
[    0.000000]  BIOS-e820: 00000000feffc000 - 00000000ff000000 (reserved)
[    0.000000]  BIOS-e820: 00000000fffc0000 - 0000000100000000 (reserved)
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI 2.4 present.
[    0.000000] No AGP bridge found





Fedora 20: build a VM with virt-builder

Here are trial and error logs when building VMs for KVM by using virt-builder

reference
http://libguestfs.org/virt-builder.1.html

[root@f20 ~]# cat /etc/fedora-release
Fedora release 20 (Heisenbug)
[root@f20 ~]# uname -ri
3.13.0-0.rc8.git2.1.vanilla.mainline.knurd.1.fc20.x86_64 x86_64
[root@f20 ~]# qemu-system-x86_64 --version
QEMU emulator version 1.7.0, Copyright (c) 2003-2008 Fabrice Bellard

virt-builder includes libguest-tools.
# yum install libguestfs-tools

# libguestfs-test-tool --version
libguestfs-test-tool 1.24.4fedora=20,release=1.fc20,libvirt

list OSes you can build
# virt-builder --list
virt-builder: warning: cache /root/.cache/virt-builder: Unix.Unix_error(20, "mkdir", "/root/.cache/virt-builder")
virt-builder: disabling the cache
centos-6                 CentOS 6.5
cirros-0.3.1             CirrOS 0.3.1
debian-6                 Debian 6 (Squeeze)
debian-7                 Debian 7 (Wheezy)
fedora-18                Fedora® 18
fedora-19                Fedora® 19
fedora-20                Fedora® 20
scientificlinux-6        Scientific Linux 6.4
ubuntu-10.04             Ubuntu 10.04 (Lucid)
ubuntu-12.04             Ubuntu 12.04 (Precise)
ubuntu-13.10             Ubuntu 13.10 (Saucy)

build a Fedora20 VM
error.
# virt-builder fedora-20 --root-password file:./rootpw.txt -o f20-vm.qcow2 --format qcow2 --size 20G --hostname f20-vm.example.com --install "@core" --firstboot-command 'yum update -y' --firstboot-command 'localectl set-locale LANG=ja_JP.utf8' --firstboot-command 'set-keymap jp'
virt-builder: warning: cache /root/.cache/virt-builder: Unix.Unix_error(20, "mkdir", "/root/.cache/virt-builder")
virt-builder: disabling the cache
[   1.0] Downloading: http://libguestfs.org/download/builder/fedora-20.xz
#######################################################################  100.0%
[ 510.0] Planning how to build this image
[ 510.0] Uncompressing
[ 521.0] Resizing (using virt-resize) to expand the disk to 20.0G
Fatal error: exception Guestfs.Error("could not create appliance through libvirt.

Try running qemu directly without libvirt using this environment variable:
export LIBGUESTFS_BACKEND=direct

Original error from libvirt: 内部エラー: モニターに接続中にプロセス

Configure LIBGUESTFS_BACKEND environment.
# export LIBGUESTFS_BACKEND=direct

# echo $LIBGUESTFS_BACKEND
direct

okay.
# virt-builder fedora-20 --root-password file:./rootpw.txt -o f20-vm.qcow2 --format qcow2 --size 20G --hostname f20-vm.example.com --install "@core" --firstboot-command 'yum update -y' --firstboot-command 'localectl set-locale LANG=ja_JP.utf8' --firstboot-command 'set-keymap jp'
virt-builder: warning: cache /root/.cache/virt-builder: Unix.Unix_error(20, "mkdir", "/root/.cache/virt-builder")
virt-builder: disabling the cache
[   1.0] Downloading: http://libguestfs.org/download/builder/fedora-20.xz
#######################################################################  100.0%
[ 518.0] Planning how to build this image
[ 518.0] Uncompressing
[ 529.0] Resizing (using virt-resize) to expand the disk to 20.0G
[ 561.0] Opening the new disk
[ 565.0] Setting a random seed
[ 565.0] Setting the hostname: f20-vm.example.com
[ 565.0] Setting root password
[ 565.0] Installing packages: @core
[ 624.0] Installing firstboot command: [1] yum update -y
[ 624.0] Installing firstboot command: [2] localectl set-locale LANG=ja_JP.utf8
[ 624.0] Installing firstboot command: [3] set-keymap jp
[ 624.0] Finishing off
Output: f20-vm.qcow2
Output size: 20.0G
Output format: qcow2
Total usable space: 19.0G
Free space: 18.1G (95%)

the VM image has been created under the directory where you issued virt-builder command.

# file f20-vm.qcow2
f20-vm.qcow2: QEMU QCOW Image (unknown version)

copy the original VM image to KVM pool ( in my case, /var/lib/libvit/images/disk1 )

# cp f20-vm.qcow2 /var/lib/libvirt/images/disk1/f20.qcow2

deploy the VM.
# yum install virt-install


# virt-install --import --name f20-vm1 --ram 512 --disk path=/var/lib/libvirt/images/disk1/f20-vm1.qcow2,format=qcow2,device=disk,bus=virtio,20G
ERROR    Error with storage parameters: Size must be specified for non existent volume path '/var/lib/libvirt/images/disk1/f20-vm1.qcow2'
[root@f20 Virtbuilder_works]# virt-install
ERROR    
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.11.10-301.fc20.x86_64 (mockbuild@bkernel01.phx2.fedoraproject.org) (gcc version 4.8.2 20131017 (Red Hat 4.8.2-1) (GCC) ) #1 SMP Thu Dec 5 14:01:17 UTC 2013
[    0.000000] Command line: BOOT_IMAGE=/vmlinuz-3.11.10-301.fc2


when booting the VM for the  first time, execute “yum update” automatically.
[  112.857596] firstboot.sh[408]: Transaction test succeeded
[  112.859440] firstboot.sh[408]: Running transaction
[  114.431092] firstboot.sh[408]: Updating   : libselinux-2.2.1-6.fc20.x86_64                             1/129
[  115.127248] firstboot.sh[408]: Updating   : nspr-4.10.2-1.fc20.x86_64                                  2/129
[  115.797586] firstboot.sh[408]: Updating   : nss-util-3.15.3-1.fc20.x86_64                              3/129
[  116.429433] firstboot.sh[408]: Updating   : audit-libs-2.3.3-1.fc20.x86_64                             4/129