To use ubuntu cloud image on CentOS 8 Cockpit KVM, we would need to download the daily image
There are many image format, but I only tested 2 of them,
- https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-disk-kvm.img, this is not booting
- https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img, this boots fine
$ wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
After downloading we can verify that this is in qcow format by using
$ file focal-server-cloudimg-amd64.img
focal-server-cloudimg-amd64.img: QEMU QCOW Image (v2), 2361393152 bytes
or
$ qemu-img info focal-server-cloudimg-amd64.img
image: focal-server-cloudimg-amd64.img
file format: qcow2
virtual size: 2.2G (2361393152 bytes)
disk size: 522M
cluster_size: 65536
Format specific information:
compat: 0.10
refcount bits: 16
Let's resize the image, since 2.2 GB looks a bit too small for me
$ qemu-img resize focal-server-cloudimg-amd64.img 15G
You can verify the result of resize by running qemu-img info again.
By default, this image expect cloud-init operation. We will try to bypass that.
First we will resize the partition table to use the extra space allocated from resize operation before, then we mount the image for further adjustment.
$ sudo modprobe nbd
$ sudo qemu-nbd -c /dev/nbd0 focal-server-cloudimg-amd64.img
$ sudo blkid /dev/nbd0p1
/dev/nbd0p1: LABEL="cloudimg-rootfs" UUID="9be2d018-238c-4f91-a3a2-9041df4c3f47" TYPE="ext4" PARTUUID="old-uuid"
we will delete partition 1 and recreate it
$ sudo fdisk /dev/nbd0
(fdisk) p
note the partition start and end
(fdisk) d
delete partition 1
(fdisk) n
create partition 1 again with the same start sector and updated end sector
(fdisk) w
there will be warning about disk signature, leave them as is, and exit fdisk
since we recreate partition 1, the PARTUUID will change and we need to adjust grub.cfg
$ sudo blkid /dev/nbd0p1
/dev/nbd0p1: LABEL="cloudimg-rootfs" UUID="9be2d018-238c-4f91-a3a2-9041df4c3f47" TYPE="ext4" PARTUUID="new-uuid"
note down this new uuid, we will need it later
$ ls /image || mkdir /image
$ sudo mount /dev/nbd0p1 /image/
Then we chroot to the new environment and change root password, so we can login to the VM later
$ sudo chroot /image/
# passwd
set your new password
The default grub.cfg also require serial port to be available, otherwise it will freeze while booting. See here for the discussion https://bugs.launchpad.net/cloud-images/+bug/1573095
We can disable serial port requirement by editing grub.cfg and removing all reference to console=ttyS0. Also edit file /etc/default/ grub.d/ 50-cloudimg- settings. cfg
Do not forget to change all reference to PARTUUID from the old uuid to the new uuid. The following files need to be changed
/boot/grub/grub.cfg
/etc/default/grub.d/40-force-partuuid.cfg
Exit the chroot environment and umount everything
# exit
$ sudo umount /image/
$ sudo qemu-nbd -d /dev/nbd0
Import VM from Cockpit interface, we can use virtio as the disk interface without issue. If cockpit do not list Ubuntu 20.04 as OS choice, we can use the nearest Ubuntu. In my case I am using Ubuntu 19.10.
Test your VM by login as root in the console interface.
To enable ssh, you have to generate hostkey and enable password authentication in sshd_config
# ssh-keygen -A
in sshd_config
PasswordAuthentication yes
# if needed
PermitRootLogin yes
Enjoy !!
Tidak ada komentar:
Posting Komentar