Ubuntu 18.04
Sponsored Link

OpenStack Stein : Add VM images to Glance2019/04/11

 
Add Virtual Machine images to Glance.
[1]
Install KVM HyperVisor on Compute Host, refer to here.
It's unnecessarry to set Bridge networking on the section [3] of the link.
[2] For example, Create a Virtual Machine image of ubuntu 18.04.
# create a directory for disk image

root@dlp ~(keystone)#
mkdir -p /var/kvm/images
# create a disk image

root@dlp ~(keystone)#
qemu-img create -f qcow2 /var/kvm/images/ubuntu1804.img 10G
# install

root@dlp ~(keystone)#
virt-install \
--name ubuntu1804 \
--ram 2048 \
--disk path=/var/kvm/images/ubuntu1804.img,format=qcow2 \
--vcpus 2 \
--os-type linux \
--os-variant ubuntu18.04 \
--network network=default \
--graphics none \
--console pty,target_type=serial \
--location 'http://ftp.riken.go.jp/Linux/ubuntu/dists/bionic/main/installer-amd64/' \
--extra-args 'console=ttyS0,115200n8 serial'
Starting install...    
# installation starts
# after finishing installation, back to KVM Host and shutdown VM

root@dlp ~(keystone)#
virsh shutdown ubuntu1804
# mount the disk image of the VM

root@dlp ~(keystone)#
guestmount -d ubuntu1804 -i /mnt
# enable getty@ttyS0.service

root@dlp ~(keystone)#
ln -s /mnt/lib/systemd/system/getty@.service /mnt/etc/systemd/system/getty.target.wants/getty@ttyS0.service

# unmount and start

root@dlp ~(keystone)#
umount /mnt

root@dlp ~(keystone)#
virsh start ubuntu1804 --console
# line 10: change like follows

root@ubuntu:~#
add-apt-repository cloud-archive:stein

root@ubuntu:~#
apt update

root@ubuntu:~#
apt -y install ssh cloud-init linux-virtual pollinate

root@ubuntu:~#
vi /etc/default/grub
# line 10: change like follows

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="
console=tty1 console=ttyS0
"
GRUB_CMDLINE_LINUX=""
# line 34,35: comment out

#
GRUB_TERMINAL=serial
#
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stopp=1"
root@ubuntu:~#
update-grub
root@ubuntu:~#
vi /etc/cloud/cloud.cfg
# line 13: add (if you'd like to allow SSH password authentication to login)

ssh_pwauth: true
# line 93: change (if you'd like to allow [ubuntu] user's SSH password auth)

default_user:
    name: ubuntu
    lock_passwd:
False
root@ubuntu:~#
systemctl enable serial-getty@ttyS0.service
# shutdown to finish settings

root@ubuntu:~#
shutdown -h now
[3] Add the Virtual Machine image to Glance.
root@dlp ~(keystone)#
openstack image create "Ubuntu1804" --file /var/kvm/images/ubuntu1804.img --disk-format qcow2 --container-format bare --public

+------------------+---------------------------------------------------------------------------------+
| Field            | Value                                                                           |
+------------------+---------------------------------------------------------------------------------+
| checksum         | a03fbb2cdf6f39d50746ed149e5eb3ab                                                |
| container_format | bare                                                                            |
| created_at       | 2019-04-11T02:29:07Z                                                            |
| disk_format      | qcow2                                                                           |
| file             | /v2/images/7690a3c0-99f7-40fe-8cde-343824edc74a/file                            |
| id               | 7690a3c0-99f7-40fe-8cde-343824edc74a                                            |
| min_disk         | 0                                                                               |
| min_ram          | 0                                                                               |
| name             | Ubuntu1804                                                                      |
| owner            | e52584cf60234bc090c7d437b8ca7b62                                                |
| properties       | os_hash_algo='sha512', os_hash_value='fa58ed1974d505cc78...', os_hidden='False' |
| protected        | False                                                                           |
| schema           | /v2/schemas/image                                                               |
| size             | 3131965440                                                                      |
| status           | active                                                                          |
| tags             |                                                                                 |
| updated_at       | 2019-04-11T02:29:28Z                                                            |
| virtual_size     | None                                                                            |
| visibility       | public                                                                          |
+------------------+---------------------------------------------------------------------------------+

root@dlp ~(keystone)#
openstack image list

+--------------------------------------+------------+--------+
| ID                                   | Name       | Status |
+--------------------------------------+------------+--------+
| 7690a3c0-99f7-40fe-8cde-343824edc74a | Ubuntu1804 | active |
+--------------------------------------+------------+--------+
[4] By the way, if you got an image from internet to add it in Glance, it's OK to simply add it like follows.
root@dlp ~(keystone)#
wget http://cloud-images.ubuntu.com/releases/18.04/release/ubuntu-18.04-server-cloudimg-amd64.img -P /var/kvm/images
root@dlp ~(keystone)#
openstack image create "Ubuntu1804" --file /var/kvm/images/ubuntu-18.04-server-cloudimg-amd64.img --disk-format qcow2 --container-format bare --public

+------------------+-------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                           |
+------------------+-------------------------------------------------------------------------------------------------+
| checksum         | 8f92c8890165448793cee1f03264165a                                                                |
| container_format | bare                                                                                            |
| created_at       | 2019-04-11T02:32:59Z                                                                            |
| disk_format      | qcow2                                                                                           |
| file             | /v2/images/21050ab6-dbd7-487f-abf2-cabbab507abe/file                                            |
| id               | 21050ab6-dbd7-487f-abf2-cabbab507abe                                                            |
| min_disk         | 0                                                                                               |
| min_ram          | 0                                                                                               |
| name             | Ubuntu1804                                                                                      |
| owner            | e52584cf60234bc090c7d437b8ca7b62                                                                |
| properties       | os_hash_algo='sha512', os_hash_value='3e1ef6f0d9f90a9a2c21e7c2976c1762e9...', os_hidden='False' |
| protected        | False                                                                                           |
| schema           | /v2/schemas/image                                                                               |
| size             | 343736320                                                                                       |
| status           | active                                                                                          |
| tags             |                                                                                                 |
| updated_at       | 2019-04-11T02:33:02Z                                                                            |
| virtual_size     | None                                                                                            |
| visibility       | public                                                                                          |
+------------------+-------------------------------------------------------------------------------------------------+
Matched Content