OpenStack Mitaka : Add VM-Images2016/05/20 |
Add Virtual Machine image in Glance.
|
|
[1] | Load environment variables first. |
root@dlp:~# unset OS_TOKEN OS_URL
root@dlp:~#
vi ~/keystonerc
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default export OS_PROJECT_NAME=admin export OS_USERNAME=admin export OS_PASSWORD=adminpassword export OS_AUTH_URL=http://10.0.0.30:35357/v3 export OS_IDENTITY_API_VERSION=3 export OS_IMAGE_API_VERSION=2 export PS1='\u@\h \W(keystone)\$ '
root@dlp:~#
chmod 600 ~/keystonerc root@dlp:~# source ~/keystonerc root@dlp ~(keystone)# echo "source ~/keystonerc " >> ~/.bash_profile
# display status (it's OK if no errors are shown) root@dlp ~(keystone)# glance image-list
+----+------+ | ID | Name | +----+------+ +----+------+ |
[2] | For example, Create a Virtual Machine image of ubuntu 16.04. |
# create a disk image root@dlp ~(keystone)# qemu-img create -f qcow2 /var/kvm/images/ubuntu1604.img 10G
# install OS root@dlp ~(keystone)# virt-install \
--name ubuntu1604 \ --ram 2048 \ --disk path=/var/kvm/images/ubuntu1604.img,format=qcow2 \ --vcpus 2 \ --os-type linux \ --os-variant ubuntu16.04 \ --network network=default \ --graphics none \ --console pty,target_type=serial \ --location 'http://jp.archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/' \ --extra-args 'console=ttyS0,115200n8 serial'
Starting install...
# installation starts
# after finishing installation, back to KVM Host ans shutdown VM root@dlp ~(keystone)# virsh shutdown ubuntu1604
# mount the disk image of the VM root@dlp ~(keystone)# guestmount -d ubuntu1604 -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 ubuntu1604 --console
# configure some settings for openstack instance on VM root@ubuntu:~# apt-get -y install ssh cloud-init linux-virtual pollinate
root@ubuntu:~#
vi /etc/default/grub # line 11: 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 35,36: 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 # near line 13: add (if you'd like to allow SSH password authentication to login)
ssh_pwauth: true
root@ubuntu:~#
vi /etc/network/interfaces # comment out except loopback interface
# The primary network interface
# auto ens2# iface ens2 inet dhcp
root@ubuntu:~#
systemctl enable serial-getty@ttyS0.service
# shutdown to finish root@ubuntu:~# shutdown -h now
|
[3] | Add the virtual machine image to Glance. |
root@dlp ~(keystone)# glance image-create --name "Ubuntu1604" --file /var/kvm/images/ubuntu1604.img --disk-format qcow2 --container-format bare --visibility public +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | 765d8cab1b830ed53ed8c63e23c433f2 | | container_format | bare | | created_at | 2016-05-20T11:55:33Z | | disk_format | qcow2 | | id | 6af2b695-b82d-4ba0-b4e4-1855848f61aa | | min_disk | 0 | | min_ram | 0 | | name | Ubuntu1604 | | owner | 61bb62a97e394b8db8f95aa05a678771 | | protected | False | | size | 2034368512 | | status | active | | tags | [] | | updated_at | 2016-05-20T11:56:02Z | | virtual_size | None | | visibility | public | +------------------+--------------------------------------+root@dlp ~(keystone)# glance image-list +--------------------------------------+------------+ | ID | Name | +--------------------------------------+------------+ | 6af2b695-b82d-4ba0-b4e4-1855848f61aa | Ubuntu1604 | +--------------------------------------+------------+ |
[4] | By the way, if you got an image from internet, it's OK to simply add it like follows. |
root@dlp ~(keystone)#
root@dlp ~(keystone)# wget http://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P /var/kvm/images
glance image-create --name "Ubuntu1604" --file /var/kvm/images/ubuntu-16.04-server-cloudimg-amd64-disk1.img --disk-format qcow2 --container-format bare --visibility public +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | 29c4d152758268383323b86208105960 | | container_format | bare | | created_at | 2016-05-20T13:23:45Z | | disk_format | qcow2 | | id | ddb8037e-8648-4b88-b7e6-0b10aba3383d | | min_disk | 0 | | min_ram | 0 | | name | Ubuntu1604 | | owner | 61bb62a97e394b8db8f95aa05a678771 | | protected | False | | size | 303824896 | | status | active | | tags | [] | | updated_at | 2016-05-20T13:23:47Z | | virtual_size | None | | visibility | public | +------------------+--------------------------------------+ |
Sponsored Link |
|