@ -2,222 +2,282 @@
Example: Fedora image
=====================
Download a `Fedora <http://getfedora.org/> `_ ISO image.
This procedure lets you create a Fedora 20 image.
This example shows you how to install a Fedora image and focuses
mainly on Fedora 25. Because the Fedora installation process
might differ across versions, the installation steps might
differ if you use a different version of Fedora.
#. Start the installation using :command: `virt-install` as shown below:
Download a Fedora install ISO
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block :: console
#. Visit the `Fedora download site <https://getfedora.org/> `_ .
# qemu-img create -f qcow2 fedora-20.qcow2 8G
# virt-install --connect=qemu:///system --network=bridge:virbr0 \
--extra-args="console=tty0 console=ttyS0,115200 serial rd_NO_PLYMOUTH" \
--name=fedora-20 --disk path=/var/lib/libvirt/images/fedora-20.qcow2,format=qcow2,size=10,cache=none \
--ram 2048 --vcpus=2 --check-cpu --accelerate --os-type linux --os-variant fedora19 \
--hvm --location=http://dl.fedoraproject.org/pub/fedora/linux/releases/20/Fedora/x86_64/os/ \
--nographics
#. Navigate to the
`Download Fedora Server page <https://getfedora.org/en/server/download/> `_
for a Fedora Server ISO image.
This will launch a VM and start the installation process .
#. Choose the ISO image you want to download.
.. code-block :: console
For example, the `` Netinstall Image `` is a good choice because it is a
smaller image that downloads missing packages from the Internet during
installation.
Starting install...
Retrieving file .treeinfo... | 2.2 kB 00:00:00 !!!
Retrieving file vmlinuz... | 9.8 MB 00:00:05 !!!
Retrieving file initrd.img... | 66 MB 00:00:37 !!!
Allocating 'fedora-20.qcow2' | 10 GB 00:00:00
Creating domain... | 0 B 00:00:00
Connected to domain fedora-20
Escape character is ^]
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
...
...
...
[ OK ] Reached target Local File Systems (Pre).
Starting installer, one moment...
anaconda 20.25.15-1 for Fedora 20 started.
========================================================================
========================================================================
#. Choose the VNC or text mode to set the installation options.
Start the installation process
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block :: console
Start the installation process using either the :command: `virt-manager`
or the :command: `virt-install` command as described previously.
If you use the :command: `virt-install` command, do not forget to connect your
VNC client to the virtual machine.
Assume that:
Text mode provides a limited set of installation options.
It does not offer custom partitioning for full control over the
disk layout. Would you like to use VNC mode instead?
* The name of your virtual machine image is `` fedora `` ;
you need this name when you use :command: `virsh` commands
to manipulate the state of the image.
* You saved the netinstall ISO image to the `` /tmp `` directory.
1) Start VNC
If you use the :command: `virt-install` command, the commands should look
something like this:
2) Use text mod e
.. code-block :: console
Please make your choice from above ['q' to quit | 'c' to continue |
'r' to refresh]:
# qemu-img create -f qcow2 /tmp/fedora.qcow2 10G
# virt-install --virt-type kvm --name fedora --ram 1024 \
--disk /tmp/fedora.qcow2,format=qcow2 \
--network network=default \
--graphics vnc,listen=0.0.0.0 --noautoconsole \
--os-type=linux --os-variant=fedora23 \
--location=/tmp/Fedora-Server-netinst-x86_64-25-1.3.iso
#. Set the timezone, network configuration, installation source,
and the root password. Optionally, you can choose to create a user.
Step through the installation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#. Set up the installation destination as shown below:
After the installation program starts, choose your preferred language and click
:guilabel: `Continue` to get to the installation summary. Accept the defaults.
.. code-block :: console
Review the Ethernet status
--------------------------
========================================================================
Probing storage...
Installation Destination
Ensure that the Ethernet setting is `` ON `` . Additionally, make sure that
`` IPv4 Settings' Method `` is `` Automatic (DHCP) `` , which is the default.
[x] 1) Virtio Block Device: 10.24 GB (vda)
Hostname
--------
1 disk selected; 10.24 GB capacity; 10.24 GB free ...
The installer allows you to choose a host name.
The default (`` localhost.localdomain `` ) is fine.
You install the `` cloud-init `` package later,
which sets the host name on boot when a new instance
is provisioned using this image.
Please make your choice from above ['q' to quit | 'c' to continue |
'r' to refresh]: c
========================================================================
========================================================================
Autopartitioning Options
Partition the disks
-------------------
[ ] 1) Replace Existing Linux system(s)
There are different options for partitioning the disks.
The default installation uses LVM partitions, and creates
three partitions (`` /boot `` , `` / `` , `` swap `` ), which works fine.
Alternatively, you might want to create a single ext4
partition that is mounted to `` / `` , which also works fine.
[x] 2) Use All Space
If unsure, use the default partition scheme for the installer.
While no scheme is inherently better than another, having the
partition that you want to dynamically grow at the end of the
list will allow it to grow without crossing another
partition's boundary.
[ ] 3) Use Free Space
Select software to install
--------------------------
Installation requires partitioning of your hard drive. Select what space
to use for the install target.
Step through the installation, using the default options.
The simplest thing to do is to choose the `` Minimal Install ``
install, which installs an SSH server.
Please make your choice from above ['q' to quit | 'c' to continue |
'r' to refresh]: 2
========================================================================
========================================================================
Autopartitioning Options
Set the root password
---------------------
[ ] 1) Replace Existing Linux system(s)
During the installation, remember to set the root password when prompted.
[x] 2) Use All Space
Detach the CD-ROM and reboot
----------------------------
[ ] 3) Use Free Space
Wait until the installation is complete.
Installation requires partitioning of your hard drive. Select what space
to use for the install target.
To eject a disk by using the :command: `virsh` command,
libvirt requires that you attach an empty disk at the same target
that the CD-ROM was previously attached, which may be `` hda `` .
You can confirm the appropriate target using the
:command: `virsh dumpxml vm-image` command.
Please make your choice from above ['q' to quit | 'c' to continue |
'r' to refresh]: c
========================================================================
========================================================================
Partition Scheme Options
.. code-block :: console
[ ] 1) Standard Partition
# virsh dumpxml fedora
<domain type='kvm' id='30'>
<name>fedora</name>
...
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/tmp/Fedora-Server-netinst-x86_64-25-1.3.iso'/>
<backingStore/>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
...
</domain>
[x] 2) LVM
Run the following commands from the host to eject the disk
and reboot using `` virsh `` , as root. If you are using `` virt-manager `` ,
the commands below will work, but you can also use the GUI to detach
and reboot it by manually stopping and starting.
[ ] 3) BTRFS
.. code-block :: console
Select a partition scheme configuration.
# virsh attach-disk --type cdrom --mode readonly fedora "" hda
# virsh reboot fedora
Please make your choice from above ['q' to quit | 'c' to continue |
'r' to refresh]: c
Generating updated storage configuration
Checking storage configuration...
========================================================================
Install the ACPI service
~~~~~~~~~~~~~~~~~~~~~~~~
To enable the hypervisor to reboot or shutdown an instance,
you must install and run the `` acpid `` service on the guest system.
#. Run the following commands from the host to eject the disk and
reboot using the :command: `virsh` command, as root.
Log in as root to the Fedora guest and run the following commands
to install the ACPI service and configure it to start when the
system boots:
.. code-block :: console
.. code-block :: console
# virsh attach-disk --type cdrom --mode readonly fedora-20 "" hdc
# virsh destroy fedora-20
# virsh start fedora-20
# dnf install acpid
# systemctl enable acpid
You can also use the GUI to detach and reboot it by manually
stopping and starting.
Configure cloud-init to fetch metadata
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#. Log in as root user when you boot for the first time after installation.
An instance must interact with the metadata service to perform
several tasks on start up. For example, the instance must get
the ssh public key and run the user data script. To ensure that
the instance performs these tasks, use the `` cloud-init ``
package.
#. Install and run the `` acpid `` service on the guest system to enable
the virtual machine to reboot or shutdown an instance.
The `` cloud-init `` package automatically fetches the public key
from the metadata server and places the key in an account.
Install `` cloud-init `` inside the Fedora guest by
running:
Run the following commands inside the Fedora guest to install the
ACPI service and configure it to start when the system boots:
.. code-block :: console
.. code-block :: console
# yum install cloud-init
# yum install acpid
# chkconfig acpid on
The account varies by distribution. On Fedora-based virtual machines,
the account is called `` fedora `` .
#. Install the `` cloud-init `` package inside the Fedora guest by adding
the EPEL repo:
You can change the name of the account used by `` cloud-init ``
by editing the `` /etc/cloud/cloud.cfg `` file and adding a line
with a different user. For example, to configure `` cloud-init ``
to put the key in an account named `` admin `` , use the following
syntax in the configuration file:
The `` cloud-init `` package automatically fetches the public key
from the metadata server and places the key in an account.
.. code-block :: console
.. code-block :: console
users:
- name: admin
(...)
# yum install http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum install cloud-init
Install cloud-utils-growpart to allow partitions to resize
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can change the name of the account used by `` cloud-init ``
by editing the `` /etc/cloud/cloud.cfg `` file and adding a line with
a different user. For example, to configure `` cloud-init `` to put the
key in an account named admin, add this line to the configuration file:
In order for the root partition to properly resize, install the
`` cloud-utils-growpart `` package, which contains the proper tools
to allow the disk to resize using cloud-init.
.. code-block :: console
.. code-block :: console
user: admin
# dnf install cloud-utils-growpart
#. Disable the default `` zeroconf`` route for the instance to access
the metadata service:
Disable the zeroconf route
~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block :: console
For the instance to access the metadata service,
you must disable the default zeroconf route:
# echo "NOZEROCONF=yes" >> /etc/sysconfig/network
.. code-block :: console
#. For the :command: `nova console-log` command to work properly on
Fedora 20, you might need to add the following lines to
the `` /boot/grub/menu.lst `` file:
# echo "NOZEROCONF=yes" >> /etc/sysconfig/network
.. code-block :: console
Configure console
~~~~~~~~~~~~~~~~~
For the :command: `nova console-log` command to work properly
on Fedora, you might need to do the following steps:
serial --unit=0 --speed=115200
terminal --timeout=10 console serial
# Edit the kernel line to add the console entries
kernel ... console=tty0 console=ttyS0,115200n8
#. Edit the `` /etc/default/grub `` file and configure the
`` GRUB_CMDLINE_LINUX `` option. Delete the `` rhgb quiet ``
and add `` console=tty0 console=ttyS0,115200n8 `` to the option.
For example:
#. Shut down the instance from inside the instance as a root user:
.. code-block :: none
...
GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora/root rd.lvm.lv=fedora/swap console=tty0 console=ttyS0,115200n8"
#. Run the following command to save the changes:
.. code-block :: console
# /sbin/shutdown -h now
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.10.10-200.fc25.x86_64
Found initrd image: /boot/initramfs-4.10.10-200.fc25.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-c613978614c7426ea3e550527f63710c
Found initrd image: /boot/initramfs-0-rescue-c613978614c7426ea3e550527f63710c.img
done
#. Clean up and remove MAC address details.
Shut down the instance
~~~~~~~~~~~~~~~~~~~~~~
The operating system records the MAC address of the virtual Ethernet
card in locations such as `` /etc/sysconfig/network-scripts/ifcfg-eth0 ``
and `` /etc/udev/rules.d/70-persistent-net.rules `` during the instance
process. However, each time the image boots up, the virtual Ethernet
card will have a different MAC address, so this information must be
deleted from the configuration file.
From inside the instance, run as root:
Use the :command: `virt-sysprep` utility. This performs various cleanup
tasks such as removing the MAC address references.
It will clean up a virtual machine image in place:
.. code-block :: console
.. code-block :: console
# poweroff
# virt-sysprep -d fedora-20
Clean up (remove MAC address details)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#. Undefine the domain since you no longer need to have this
virtual machine image managed by libvirt:
The operating system records the MAC address of the virtual Ethernet
card in locations such as `` /etc/sysconfig/network-scripts/ifcfg-eth0 ``
during the instance process. However, each time the image boots up, the virtual
Ethernet card will have a different MAC address, so this information must
be deleted from the configuration file.
.. code-block :: console
There is a utility called :command: `virt-sysprep` , that performs
various cleanup tasks such as removing the MAC address references.
It will clean up a virtual machine image in place:
.. code-block :: console
# virt-sysprep -d fedora
Undefine the libvirt domain
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now that you can upload the image to the Image service, you no
longer need to have this virtual machine image managed by libvirt.
Use the :command: `virsh undefine vm-image` command to inform libvirt:
.. code-block :: console
# virsh undefine fedora
# virsh undefine fedora-20
Image is complete
~~~~~~~~~~~~~~~~~
The underlying image file that you created with the
:command: `qemu-img create` command is ready to be uploaded to the
Image service by using the :command: `openstack image create`
:command: `qemu-img create` command is ready to be uploaded.
For example, you can upload the `` /tmp/fedora.qcow2 ``
image to the Image service by using the :command: `openstack image create`
command. For more information, see the
`Create or update an image
<https://docs.openstack.org/user-guide/common/cli-manage-images.html#create-or-update-an-image-glance> `__.