Example: CentOS Stream image¶
This example shows you how to install a CentOS Stream image and focuses mainly on CentOS Stream 9. Because the CentOS installation process might differ across versions, the installation steps might differ if you use a different version of CentOS.
Not
This is just an example, adjust paths and commands according to your environment
Bir CentOS kurulum ISO’su indirin¶
Navigate to the CentOS mirrors page.
Choose one of the mirrors and navigate to
9-stream/BaseOS/x86_64/iso
. Download a ISO, chooseboot
to download packages during install, otherwise choosedvd
Kurulum sürecini başlatın¶
Start the installation process using either the virt-manager or the virt-install command as described in the Tools: libvirt and virsh/virt-manager page.
virt-install¶
If you use the virt-install command, do not forget to connect your VNC client to the virtual machine.
The command should look something like this:
$ sudo virt-install --virt-type kvm --name my-centos --ram 2048 \
--network network=default \
--graphics vnc,listen=0.0.0.0 --noautoconsole \
--os-type=linux --os-variant=centos-stream9 \
--location=~/Downloads/CentOS-Stream-9-20240819.0-x86_64-dvd1.iso
virt-manager¶
Not
See here for libvirt wiki about new VM creation in virt-manager
When creating a new VM from the downloaded ISO, virt-manager should automatically detect the OS. If it fails, manually select CentOS Stream as OS. Default settings should be fine.
Kurulum adımını geçin¶
Not
This guide focuses on the steps specific to create a OpenStack image, for a general overview of installation process see CentOS Documentation
In Installation Summary
follow the instructions below.
DHCP and hostname¶
In Network & Host Name
ensure that Ethernet
is on and in
Configure.../IPv4 Settings
the Method
is set to Automatic (DHCP)
.
The same page allows for host name selection - leave it to default as the
cloud-init
package will be installed later.
Kurulum seçeneğini seçin¶
In Software Selection
choose what to install, the default is Server with
GUI
, the smallest choice is Minimal Install
.
Create a working user¶
Configure a root password in Root Password
, as this will be needed later to
finalize the installation. By default it will be then blocked by cloud-init. It
is also possible to create an adiministrator user, as it will be later deleted
by virt-sysprep.
CD-ROM’u ayırın ve yeniden başlatın¶
virt-install
virsh komutunu kullanarak bir diski çıkarmak için, libvirt CD-ROM’un daha önce bağlı olduğu aynı hedefe boş bir disk eklemenizi gerektirir, bu hda
olabilir. Uygun hedefi virsh dumpxml vm-image komutuyla doğrulayabilirsiniz.
$ sudo virsh dumpxml my-centos
<domain type='kvm' id='19'>
<name>centos</name>
...
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hda' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
</disk>
...
</domain>
Run the following commands from the host to eject the disk
and reboot using virsh
, as root.
$ sudo virsh attach-disk --type cdrom --mode readonly my-centos "" hda
$ sudo virsh reboot my-centos
virt-manager
If you are using virt-manager
, the commands above will work, but you can
also use the GUI to detach and reboot.
Finalize installation¶
ACPI sunucusunu kurun¶
Hipervizörün bir sunucuyu yeniden başlatabilmesi ya da kapatabilmesi için, acpid
sunucusunu misafir sistemde kurmalı ve çalıştırmalısınız.
Log in to the CentOS guest and run the following commands to install the ACPI service and configure it to start when the system boots:
# dnf install acpid
# systemctl enable acpid
Metaveri getirmek için yapılandırın¶
Not
Check cloud-init documentation for more information
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, install the cloud-init
utility.
cloud-init
paketi açık anahtarı otomatik olarak metaveri sunucusundan çeker ve anahtarı bir hesaba yerleştirir. Şu komutu çalıştırarak CentOS misafiri içinde cloud-init
kurun:
# dnf install cloud-init
The account varies by distribution. On CentOS Stream virtual machines,
the account is called cloud-user
.
cloud-init
tarafıdan kullanılan hesap ismini /etc/cloud/cloud.cfg
dosyasını düzenleyerek farklı kullanıcı içeren bir satır ekleyerek değiştirebilirsiniz. Örneğin, cloud-init``i ``admin
isimli bir hesaba anahtar koyacak şekilde yapılandırmak için , yapılandırma dosyasında aşağıdaki sözdizimini kullanın.
users:
- name: admin
(...)
Cloud-init alternatives¶
Uyarı
This method is not recommended as only gets the ssh public key from the metadata server. It does not get user data, which is optional data that can be passed by the user when requesting a new instance. User data is often used to run a custom script when an instance boots.
İmajınıza cloud-init
paketini kuramıyorsanız, ssh açık anahtarını çekmek ve root hesabına eklemek için, /etc/rc.d/rc.local
dosyasını düzenleyin ve touch /var/lock/subsys/local
satırıdan önce şu satırları girin:
if [ ! -d /root/.ssh ]; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi
# Fetch public key using HTTP
ATTEMPTS=30
FAILED=0
while [ ! -f /root/.ssh/authorized_keys ]; do
curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key \
> /tmp/metadata-key 2>/dev/null
if [ \$? -eq 0 ]; then
cat /tmp/metadata-key >> /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
restorecon /root/.ssh/authorized_keys
rm -f /tmp/metadata-key
echo "Successfully retrieved public key from instance metadata"
echo "*****************"
echo "AUTHORIZED KEYS"
echo "*****************"
cat /root/.ssh/authorized_keys
echo "*****************"
fi
done
Not
Bazı VNC istemcileri iki noktayı (:
) noktalı virgül ile (;
) ve alt çizgiyi (_
) tire ile (-
) değiştirir. http;
değil http:
belirttiğinize emin olun. authorized-keys
değil authorized_keys
belirttiğinize emin olun.
Not
With this method, previous CentOS versions needed to disable the zeroconf route, this is not needed as of EL8.
Allow partitions to resize¶
Kök bölümün düzgün yeniden boyutlandırılması için, cloud-utils-growpart
paketini kurun, bu paket cloud-init kullanarak diskin yeniden boyutlandırılmasını sağlayan uygun araçları içerir.
# dnf install cloud-utils-growpart
Konsolu yapılandırın¶
Uyarı
Actually this does not work even following https://access.redhat.com/solutions/3443551
For the openstack console log command to work properly, instance must be configured to sent output to a serial console.
Edit the
/etc/default/grub
file and appendconsole=tty0 console=ttyS0,115200n8
toGRUB_CMDLINE_LINUX
.Örneğin:
... GRUB_CMDLINE_LINUX="resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap console=tty0 console=ttyS0,115200n8"
Then regenerate GRUB configuration:
# grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline
Customize¶
If you are building an image manually, you are probably interested in customizing it, now it’s time to apply your edits.
Sunucuyu kapatın¶
Shutdown the VM:
# shutdown now
Clean up¶
The image needs to be cleaned up of details such as the MAC address - the tool used is virt-sysprep, part of libguestfs
sudo virt-sysprep -d my-centos
Resize the image¶
Resize and compress the image to remove unused space (the image will then use available space after initialization) using virt-sparsify, part of libguestfs
sudo virt-sparsify --compress /var/lib/libvirt/images/my-centos.qcow2 ~/upload.qcow2
İmaj tamamlandı¶
The resized image is now ready to be uploaded using openstack image create. For more information, see the python-openstackclient command list.
libvirt alanı tanımını kaldır¶
Now that you can upload the image to the Image service, you no longer need to have this virtual machine image managed by libvirt.
$ sudo virsh undefine my-centos
Or if you used virt-manager, delete it through the GUI.