Discussion:
[virt-tools-list] Install KVM Virtual machine with virt-install on a LVM partition
arnaud gaboury
2012-04-25 10:27:36 UTC
Permalink
Hello,

I am far from an expert, and I am trying to build a virtual machine
(debian squeeze) on my Arch 64 bits host. The VM will serve as a
server with usual services (http, mail, ftp, media server etc). This
is only for my own purpose and I do it as a hobby.I have no obligation
to success, and more important I want to understand everything i do. I
have some doubts, so why my post here.
 I want to install the VM on a LVM partition.

-I first create successfully a LVM partition on /dev/sda4
$fdisk -l /dev/sda
...
/dev/sda4      1925115904  2949116309   512000203   8e  LVM Linux
...

I will install the VM (named "daffodil") on a 200G Logical Volume on groupe vg0
$ lvcreate –n lv_daffodil –L 200G vg0
Logical volume “lv_daffodil” created

Now I need to create the VM. I want to use virt-install IN COMMAND
LINE. After days an days of reading (and headache), here is what i
think is the correct command :


virt-install --connect qemu:///system --name=daffodil --ram 8192 --cpu host
 --disk path=/dev/vg0/lv_daffodil,size=200,bus=virtio,sparse=false,format=raw
--cdrom /var/lib/libvirt/images/isofiles/debian-6.0.4-amd64-netinst.iso
 --description="daffodil (debian squeeze) - vm guest on host magnolia"
--graphics vnc --os-type=linux --os-variant=debiansqueeze
 --network bridge:br0 --video=vga  --hvm --accelerate


So my questions :

Is the command correct and academic?
I think size=200 is maybe not needed, as the LV has already be created. Right?
format=raw seems weird to me and not needed. Right?
My host has 16G RAM. Shall I put 16 as --ram argument or stay with 8 ?
How about the filesystem? I want an ext4. Shall I create it on
lv_daffodil BEFORE the install or will I do it under the install
process when partitioning?
Any advantage in creating smaller than 200G logical volume, even if I
want my VM have enough space (The whole HD is 2T)?
Not sure about the --accelerate argument
Any hint for optimization?
As a n00b ++, will I be able to manage SELinux on my server, as it
seems a litle bit tricky?
what about --noautoconsole argument?

Thank you for your help and knowledge.
Richard W.M. Jones
2012-04-26 08:02:57 UTC
Permalink
Post by arnaud gaboury
virt-install --connect qemu:///system --name=daffodil --ram 8192 --cpu host
 --disk path=/dev/vg0/lv_daffodil,size=200,bus=virtio,sparse=false,format=raw
--cdrom /var/lib/libvirt/images/isofiles/debian-6.0.4-amd64-netinst.iso
 --description="daffodil (debian squeeze) - vm guest on host magnolia"
--graphics vnc --os-type=linux --os-variant=debiansqueeze
 --network bridge:br0 --video=vga  --hvm --accelerate
Is the command correct and academic?
I have a "standard" script I use to automate virt-install:

----------------------------------------------------------------------
#!/bin/bash -

# Script used to install VMs.
# You have to lvcreate the disk first!
# lvcreate -L 10G -n $name vg_data

set -e

name=F16x64
cpus="--cpu=host --vcpus=4"
disk="--disk path=/dev/vg_data/$name"
#location="-l http://www.mirrorservice.org/sites/download.fedora.redhat.com/pub/fedora/linux/releases/15/Fedora/x86_64/os/"
location="--cdrom /mnt/media/installers/Fedora-16-x86_64-DVD/Fedora-16-x86_64-DVD.iso"
type="--os-type=linux"
variant="--os-variant=fedora16"
#graphics="--graphics spice"
#options="-x btrfs"
#extra=""

virt-install -n $name -r 1024 \
$cpus $type $variant $disk $location $graphics $options $extra
----------------------------------------------------------------------

By making small adjustments to this, I can install all guests I need.
Post by arnaud gaboury
I think size=200 is maybe not needed, as the LV has already be created. Right?
format=raw seems weird to me and not needed. Right?
You don't need size or format since virt-install will pick that up
from the disk image itself.
Post by arnaud gaboury
My host has 16G RAM. Shall I put 16 as --ram argument or stay with 8 ?
Depends how much you need for the *guest*. It needs to be smaller
than the host size, but will depend on how many concurrent guests you
want to run.
Post by arnaud gaboury
How about the filesystem? I want an ext4. Shall I create it on
lv_daffodil BEFORE the install or will I do it under the install
process when partitioning?
No, the guest installer deals with all that.
Post by arnaud gaboury
Not sure about the --accelerate argument
--accelerate is not required with modern virt-install.

Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
Arno Gaboury
2012-04-26 08:24:10 UTC
Permalink
Post by Richard W.M. Jones
Post by arnaud gaboury
virt-install --connect qemu:///system --name=daffodil --ram 8192 --cpu host
--disk path=/dev/vg0/lv_daffodil,size=200,bus=virtio,sparse=false,format=raw
--cdrom /var/lib/libvirt/images/isofiles/debian-6.0.4-amd64-netinst.iso
--description="daffodil (debian squeeze) - vm guest on host magnolia"
--graphics vnc --os-type=linux --os-variant=debiansqueeze
--network bridge:br0 --video=vga --hvm --accelerate
Is the command correct and academic?
----------------------------------------------------------------------
#!/bin/bash -
# Script used to install VMs.
# You have to lvcreate the disk first!
# lvcreate -L 10G -n $name vg_data
set -e
name=F16x64
cpus="--cpu=host --vcpus=4"
disk="--disk path=/dev/vg_data/$name"
#location="-l http://www.mirrorservice.org/sites/download.fedora.redhat.com/pub/fedora/linux/releases/15/Fedora/x86_64/os/"
location="--cdrom /mnt/media/installers/Fedora-16-x86_64-DVD/Fedora-16-x86_64-DVD.iso"
type="--os-type=linux"
variant="--os-variant=fedora16"
#graphics="--graphics spice"
#options="-x btrfs"
#extra=""
virt-install -n $name -r 1024 \
$cpus $type $variant $disk $location $graphics $options $extra
----------------------------------------------------------------------
By making small adjustments to this, I can install all guests I need.
Post by arnaud gaboury
I think size=200 is maybe not needed, as the LV has already be created. Right?
format=raw seems weird to me and not needed. Right?
You don't need size or format since virt-install will pick that up
from the disk image itself.
Post by arnaud gaboury
My host has 16G RAM. Shall I put 16 as --ram argument or stay with 8 ?
Depends how much you need for the *guest*. It needs to be smaller
than the host size, but will depend on how many concurrent guests you
want to run.
Post by arnaud gaboury
How about the filesystem? I want an ext4. Shall I create it on
lv_daffodil BEFORE the install or will I do it under the install
process when partitioning?
No, the guest installer deals with all that.
Post by arnaud gaboury
Not sure about the --accelerate argument
--accelerate is not required with modern virt-install.
Rich.
Rich,

thank you much for your answer. I first posted one week agon in Arch
forum, usually very active, and I am still with no help.

If I understand correcty, my command line was not so bad. I will adapt
your script.

About this line :
cpus="--cpu=host --vcpus=4"
Why add vcpus=4 as I thought cpu=host would indicate to use same CPU
config as your host?
Richard W.M. Jones
2012-04-26 08:37:01 UTC
Permalink
Post by Richard W.M. Jones
cpus="--cpu=host --vcpus=4"
Why add vcpus=4 as I thought cpu=host would indicate to use same CPU
config as your host?
--cpu=host gives each guest CPU the same CPUID flags as the host.

--vcpus=N chooses how many guest vCPUs you want, where N should
usually be <= the number of host CPUs.

Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
Arno Gaboury
2012-04-26 08:36:31 UTC
Permalink
Post by Richard W.M. Jones
Post by arnaud gaboury
virt-install --connect qemu:///system --name=daffodil --ram 8192 --cpu host
--disk path=/dev/vg0/lv_daffodil,size=200,bus=virtio,sparse=false,format=raw
--cdrom /var/lib/libvirt/images/isofiles/debian-6.0.4-amd64-netinst.iso
--description="daffodil (debian squeeze) - vm guest on host magnolia"
--graphics vnc --os-type=linux --os-variant=debiansqueeze
--network bridge:br0 --video=vga --hvm --accelerate
Is the command correct and academic?
----------------------------------------------------------------------
#!/bin/bash -
# Script used to install VMs.
# You have to lvcreate the disk first!
# lvcreate -L 10G -n $name vg_data
set -e
name=F16x64
cpus="--cpu=host --vcpus=4"
disk="--disk path=/dev/vg_data/$name"
#location="-l http://www.mirrorservice.org/sites/download.fedora.redhat.com/pub/fedora/linux/releases/15/Fedora/x86_64/os/"
location="--cdrom /mnt/media/installers/Fedora-16-x86_64-DVD/Fedora-16-x86_64-DVD.iso"
type="--os-type=linux"
variant="--os-variant=fedora16"
#graphics="--graphics spice"
#options="-x btrfs"
#extra=""
virt-install -n $name -r 1024 \
$cpus $type $variant $disk $location $graphics $options $extra
----------------------------------------------------------------------
By making small adjustments to this, I can install all guests I need.
Post by arnaud gaboury
I think size=200 is maybe not needed, as the LV has already be created. Right?
format=raw seems weird to me and not needed. Right?
You don't need size or format since virt-install will pick that up
from the disk image itself.
Post by arnaud gaboury
My host has 16G RAM. Shall I put 16 as --ram argument or stay with 8 ?
Depends how much you need for the *guest*. It needs to be smaller
than the host size, but will depend on how many concurrent guests you
want to run.
Post by arnaud gaboury
How about the filesystem? I want an ext4. Shall I create it on
lv_daffodil BEFORE the install or will I do it under the install
process when partitioning?
No, the guest installer deals with all that.
Post by arnaud gaboury
Not sure about the --accelerate argument
--accelerate is not required with modern virt-install.
Rich.
Rich,

sorry to coma back again, but I take the opportunity to deep my knowledges.

Why don't you specify --network? Not needed ?
Is graohics spice best than vnc?
I do not want to use btrfs but ext4, but my host (Archlinux) use btfrs.
Is this the reason I shall add #options="-x btrfs" ? Or shall I remove?
What about sparse=false ? Not needed? Obsolete, or not a good solution?

TY again for sharing
Richard W.M. Jones
2012-04-26 08:40:09 UTC
Permalink
Post by Arno Gaboury
Why don't you specify --network? Not needed ?
It depends. No --network gives you the defaults.
You could also specify: --network bridge=br0
Post by Arno Gaboury
Is graohics spice best than vnc?
Usually yes.
Post by Arno Gaboury
I do not want to use btrfs but ext4, but my host (Archlinux) use
btfrs. Is this the reason I shall add #options="-x btrfs" ? Or shall
I remove?
It's commented out in the script. Only Fedora would use this option.
Post by Arno Gaboury
What about sparse=false ? Not needed? Obsolete, or not a good solution?
I thought you were using an LV as storage? There's no choice for LVs
(except with extremely recent versions of LVM that you're unlikely to
be using).

Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
Arno Gaboury
2012-04-26 09:08:45 UTC
Permalink
Post by Richard W.M. Jones
Post by Arno Gaboury
Why don't you specify --network? Not needed ?
It depends. No --network gives you the defaults.
You could also specify: --network bridge=br0
Post by Arno Gaboury
Is graohics spice best than vnc?
Usually yes.
Post by Arno Gaboury
I do not want to use btrfs but ext4, but my host (Archlinux) use
btfrs. Is this the reason I shall add #options="-x btrfs" ? Or shall
I remove?
It's commented out in the script. Only Fedora would use this option.
Post by Arno Gaboury
What about sparse=false ? Not needed? Obsolete, or not a good solution?
I thought you were using an LV as storage? There's no choice for LVs
(except with extremely recent versions of LVM that you're unlikely to
be using).
Rich.
Here we go :


#!/bin/bash

#created Thursday April 26
#following Richard W.M.Jones <***@redhat.com> advices and script
#this script can be changed according your own need. This one will
#install a debian VM called daffodil on a LVM partition, with 2 CPU,
8192 RAM

# Script used to install VMs.
# You have to lvcreate the disk first!
# lvcreate -L sizeG -n $name vg_data

set -e

name=daffodil
cpus="--cpu=host --vcpus=2"
disk="--disk path=/dev/vg0/lv_daffodil"
location="--cdrom
/var/lib/libvirt/images/isofiles/debian-6.0.4-amd64-netinst.iso
type="--os-type=linux"
variant="--os-variant=debiansqueeze"
graphics="--graphics spice"
extra="bus=virtio"
network="--network bridge=br0"


virt-install -n $name -r 8192 \
$cpus $type $variant $disk $location $graphics $extra $network



Hope everything is correctly set up and it can help other users. I
realised KVM is not so straightforward and could be very different
depending on your source.
Richard W.M. Jones
2012-04-26 09:33:05 UTC
Permalink
Post by Arno Gaboury
extra="bus=virtio"
What does this do?

Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
Arno Gaboury
2012-04-26 09:54:54 UTC
Permalink
Post by Richard W.M. Jones
Post by Arno Gaboury
extra="bus=virtio"
What does this do?
Rich.
According to the wiki libvirt (http://wiki.libvirt.org/page/Virtio):

Virtio is a Linux standard for network and disk device drivers where
just the guest's device driver "knows" it is running in a virtual
environment, and cooperates with the hypervisor. This enables guests to
get high performance network and disk operations, and gives most of the
performance benefits of paravirtualization.

and KVM official website (http://www.linux-kvm.org/page/Virtio)

Networking:
QEMU defaults to user-mode networking (slirp), which is available
without prior setup and without administrative privileges on the host.
It is also unfortunately very slow. To get high performance networking,
switch to a bridged setup via the -net tap command line switches.

qemu -net nic,model=virtio,mac=... -net tap,ifname=...
QEMU also defaults to the RTL8139 network interface card (NIC) model.
Again this card is compatible with most guests, but does not offer the
best performance. If your guest supports it, switch to the virtio model:

qemu -net nic,model=virtio,mac=... -net tap,ifname=...
Richard W.M. Jones
2012-04-26 10:13:48 UTC
Permalink
Yes I'm aware of what virtio is. The script is wrong though:

extra="bus=virtio"
[...]
virt-install -n $name -r 8192 \
$cpus $type $variant $disk $location $graphics $extra $network

Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
Arno Gaboury
2012-04-26 10:33:36 UTC
Permalink
Post by Arno Gaboury
extra="bus=virtio"
[...]
virt-install -n $name -r 8192 \
$cpus $type $variant $disk $location $graphics $extra $network
Rich.
Sorry, but what is wrong? The way I write the argument? I do not see any
diff between what I wrote and the example given in the debianwiki:


virt-install -d --name=lin01-quake --ram 512 --disk
path=/dev/vg0/lin01-boot,bus=virtio,cache=none

Should be something like this :

bus="virtio"
Post by Arno Gaboury
[...]
virt-install -n $name -r 8192 \
$cpus $type $variant $disk $location $graphics $bus $network
??

Loading...