(from Tutorials and videos)
Creating a virtual machine with virt-install involves the same steps as doing it graphically with virt-manager.
First you need to download an ISO of the operating system you want to install or you can do a network install.
There are several decisions you have to make about how and where you want to create the virtual hard disk for the new guest:
virt-resize), so choose this wisely. Even if you choose a format which
grows(like sparse or qcow2), this is a hard limit that you cannot easily grow beyond. Below are some rough guides for minimum operating system only space. Remember if you want to store significant amounts of data in the guest, you must add that requirement on top of these figures.
|Minimal||eg. Debian or FreeBSD, text only, configured with just the essential components.||2048 MB|
|Linux||Typical Linux distribution, base install with graphical components.||8192 MB|
|Windows||Recent version of Windows.||16384 MB|
filethen you also have the option of using a sparse file. Sparse files are allocated on demand (as the guest writes to them), which means you don't need to dedicate disk space up-front. On the other hand, sparse allocation is slow, and if you allow the host to run out of disk space this can cause dangerous data loss in the guest.
With these decisions made, you can now go ahead and create the storage for the guest. The examples below all assume that the disk will be 8192 MB in size (as the hard upper limit). Adjust the number as required.
To create a fully-allocated (non-sparse) raw file:
dd if=/dev/zero of=/var/lib/libvirt/images/guest.img bs=1M count=8192
or for newer versions of Linux, use the faster
fallocate -l 8192M /var/lib/libvirt/images/guest.img
To create a sparse raw file:
rm -f /var/lib/libvirt/images/guest.img truncate --size=8192M /var/lib/libvirt/images/guest.img
To create a qcow2 file:
qemu-img create -f qcow2 /var/lib/libvirt/images/guest.qcow2 8192
To create an LVM2 logical volume in the volume group
lvcreate -n lv_guest -L 8192M /dev/vg_host
SAN LUN creation depends on your SAN, and you should consult that documentation.
To create a libvirt volume in the
storage pool, do:
virsh vol-create-as default guest 8192M
default storage pool is a directory
/var/lib/libvirt/images, and you'll find the disk image
virsh vol-create-as has several other
options, and you might want to consult the
Now you can create the virtual machine itself from the ISO which you downloaded and the disk image that you created.
This is the basic virt-install command:
virt-install -r 1024 --accelerate -n Fedora14 \ -f /path/to/guest.img \ --cdrom Fedora-14-x86_64-Live.iso
-r option specifies the amount of RAM (in megabytes).
This depends on the operating system, but 768 MB is a good
starting point these days, and I use 1024 MB for modern
graphical Linux and Windows guests.
--accelerate indicates you want to use hardware
acceleration. Recent versions of virt-install default to this.
-n specifies the name of the virtual machine
(as known to libvirt), and this is the name you will see
in listings and use when starting
and stopping the VM.
-f is the full path to the disk image you created before.
For LVs, use the device path,
--cdrom is the path to the ISO file that you downloaded.
The ISO is only needed during installation, and can be deleted
Other virt-install options that might be useful (read
virt-install(1) for the full list) include:
--vcpus=NSpecify an SMP guest with N virtual CPUs.
--descriptionGive a description string which appears in the libvirt XML.
-lUse this to install from a network URL (instead of needing to download an ISO). See network installs below.
--diskThis option lets you specify other aspects of the disk such as the format (qcow2 instead of raw). See the man page for the full details.
--soundhw ac97Give the guest a (virtual) AC'97 soundcard. Without this option no soundcard is provided for the guest.
Instead of downloading the ISO, you can install from public
repositories over HTTP. To do this, remove the
option and instead specify the
-l URL option. Some common locations that virt-install
knows how to handle:
13to the Fedora release, and
x86_64for a 64 bit guest.
usto your country code (for faster access to a local mirror), and
amd64for a 64 bit guest.
maverickto the name of the version of Ubuntu to install, and
amd64for a 64 bit guest.