Ubuntu24-04 server版本OpenStack虚拟机镜像制作

说明:此镜像制作主要针对使用Docker 部署的Openstack机器制作镜像,比如我们用于创建的节点IP为10.250.0.99,此次虚拟机磁盘为100GB。

准备Ubuntu24-04 Server版本镜像iso文件

#将ubuntu-24.04.2-live-server-amd64.iso 文件上传到/var/log/kolla目录

创建磁盘文件和网络

#进入nova_libvirt 容器
docker exec -it nova_libvirt bash

#进入目录/var/log/kolla创建磁盘文件保证物理机根空间大于100GB
cd /var/log/kolla/
qemu-img create -f raw /var/log/kolla/ubuntu2404-02-server-100G-admin@123.raw 100G

#创建虚拟机使用的test网络,此网络使用ovs 名称为test
ovs-vsctl add-br test

编辑虚拟机配置文件

#依然再nova_libvirt 这个容器里面
cd /var/log/kolla/

#编辑配置文件,其它linux操作系统只需要修改ubuntu2404,/var/log/kolla/ubuntu2404-02-server-100G-admin@123.raw
#和/var/log/kolla/ubuntu-24.04.2-live-server-amd64.iso三个地方即可
vi ubuntu2404.xml

<domain type='kvm'>
  <name>ubuntu2404</name>
  <memory unit='MiB'>8192</memory>
  <currentMemory unit='MiB'>8192</currentMemory>
  <vcpu>4</vcpu>
  <os>
    <type arch='x86_64' machine='pc'>hvm</type>
    <boot dev='cdrom'/>
 </os>
 <features>
    <acpi/>
    <apic/>
    <pae/>
 </features>
 <clock offset='localtime'/>
 <on_poweroff>destroy</on_poweroff>
 <on_reboot>restart</on_reboot>
 <on_crash>destroy</on_crash>
 <devices>
   <emulator>/usr/libexec/qemu-kvm</emulator>
   <disk type='file' device='disk'>
     <driver name='qemu' type='raw'/>
     <source file='/var/log/kolla/ubuntu2404-02-server-100G-admin@123.raw'/>
     <target dev='vda' bus='virtio'/>
   </disk>
   <interface type='bridge'>
      <source bridge='test'/>    
      <virtualport type='openvswitch'/>
   </interface>
   <disk type='file' device='cdrom'>
     <source file='/var/log/kolla/ubuntu-24.04.2-live-server-amd64.iso'/>
     <target dev='hdb' bus='ide'/> 
   </disk>
  <input type='mouse' bus='ps2'/>
  <graphics type='vnc' port='-1' autoport='yes' listen = '0.0.0.0' keymap='en-us'/>
  <serial type='pty'>
    <target port='0'/>
  </serial>
  <console type='pty'>
    <target type='serial' port='0'/>
  </console>
 </devices>
</domain>

启动虚拟机

#在容器nova_libvirt操作,启动虚拟机
cd /var/log/kolla

#启动虚拟机
virsh define ubuntu2404.xml
virsh start ubuntu2404

#查看ubuntu2404 虚拟机vnc端口,以下port 5901 为vnc接口
virsh dumpxml ubuntu2404| grep vnc
    <graphics type='vnc' port='5901' autoport='yes' listen='0.0.0.0' keymap='en-us'>

使用vnc viewer软件连接vnc安装操作系统

vnc viewer连接主机

设置语言

选择Done

选择ubuntu Server,选择Done

设置网卡

将网卡ens3设置IP 地址自动获取

设置ens3网卡IP地址自动获取,Save保存

选择Continue without network

proxy选择Done

设置源

选择Done继续

磁盘分区

选择Done继续

将/ Unmount

将/boot Umount

不使用自动分区,使用手动分区,删除ubuntu-lv

重新创建lv

/boot 给2G,点击Create

剩余所有空间都给 /

点击Done

选择Continue

配置ubuntu主机登录用户和密码

选择Continue

配置安装SSH Server

操作系统开始安装

等待操作系统安装完成

以下代表操作系统安装完成

关闭虚拟机

#在容器nova_libvirt操作,关闭虚拟机
virsh destroy ubuntu2404
virsh undefine ubuntu2404

将镜像上传到OpenStack 镜像仓库

将镜像上传到Openstack中启动虚拟机

#将镜像上传到OpenStack 镜像仓库,进入主机系统
#进入虚拟环境
source /root/kolla/bin/activate

#使用账号密码
source /etc/kolla/admin-openrc.sh

#上传镜像
openstack image create --disk-format raw --public --progress --file /var/log/kolla/ubuntu2404-02-server-100G-admin@123.raw ubuntu0703 --progress

使用OpenStack Dashboard创建虚拟机

设置虚拟机的名称为ubuntu

选择镜像,不创建新卷

选择实例类型

选择网络

不使用安全组

点击创建实例,实例创建成功

修改ubuntu镜像,允许root直接登录

进入系统vi /etc/ssh/sshd_config

#将PermitRootLogin 设置为
PermitRootLogin yes

#重启服务
systemctl restart ssh

查看ubuntu使用的rbd磁盘

#登录主机操作系统进入nova_libvirt容器
docker exec -it nova_libvirt bash

#获取rdb磁盘信息,磁盘信息为vms/9a4685b3-45af-4f42-85e0-81f5cf375f28_disk
virsh dumpxml instance-00000032 | grep disk
        <nova:disk>120</nova:disk>
    <disk type='network' device='disk'>
      <source protocol='rbd' name='vms/9a4685b3-45af-4f42-85e0-81f5cf375f28_disk' index='1'>
      <alias name='virtio-disk0'/>
    </disk>

#在OpenStack Dashboard界面将虚拟机关机

将rbd盘导出

#进入主机操作系统,执行以下命令将ubuntu rbd磁盘导出
cd /var/log/kolla
rbd export vms/9a4685b3-45af-4f42-85e0-81f5cf375f28_disk ubuntu-new

#导出后确认导出rbd的磁盘格式
docker exec -it nova_libvirt bash
cd /var/log/kolla

#使用命令确认磁盘格式为raw
qemu-img info ubuntu-new 
image: ubuntu-new
file format: raw
virtual size: 120 GiB (128849018880 bytes)
disk size: 6.07 GiB

#退出nova_libvirt 容器进入主机操作系统,将ubuntu-new导入openstack
#进入虚拟环境
source /root/kolla/bin/activate

#使用账号密码
source /etc/kolla/admin-openrc.sh

#上传镜像
openstack image create --disk-format raw --public --progress --file /var/log/kolla/ubuntu-new ubuntu0703-new --progress

使用新的镜像创建ubuntu虚拟机

使用镜像ubuntu0703-new 在OpenStack Dashboard创建虚拟机,如果虚拟机可以正常创建并进入系统,代表镜像成功,ubuntu-new 就可以做为虚拟机镜像上传到其它OpenStack环境中。

原文链接:,转发请注明来源!