目录

  1. 镜像制作
    1. 手动制作
      1. 准备系统ISO
      2. 安装系统
      3. 安装完成后
        1. 卸载CD-ROM设备
        2. 配置镜像
          1. 安装ACPI服务
          2. 安装cloud-init
          3. 禁用firewalld
          4. 禁用zeroconf
          5. 配置console
          6. 配置qemu-guest-agent服务
          7. 禁用自动退出
          8. 删除网络配置文件
        3. 关闭虚拟机
          1. 清理(移除mac地址等信息)
          2. 镜像压缩
    2. 脚本自动化构建
      1. 构建docker容器
      2. 安装
        1. 依赖环境
        2. DIB
      3. 测试
  2. 镜像修改
    1. 密码修改
      1. 使用guestfish
      2. 使用virt-customize
      3. 使用horizon
  3. 上传镜像
  4. 使用ISO启动实例
    1. UOS镜像
    2. Windows镜像
    3. Ubuntu镜像

镜像制作

镜像制作在云环境是必不可少的步骤,主要分为手动制作和自动化脚本制作两种。

手动制作

以制作一个uos-server 1060a系统镜像为例,简要梳理手动制作一个OpenStack可用镜像的流程。本地系统也使用了uos-server 1060a。

准备系统ISO

此处准备1060a系统ISO(下载地址):uniontechos-server-20-1060a-amd64-RC4-20230421-0106.iso

安装系统

可以使用virt-manager直接在图形化界面操作或者virt-install命令在命令行启动。

使用virt-manager安装时和常规图形界面创建虚拟机操作步骤一致。

使用命令行安装时参考命令如下,首先创建名为1060a,大小为10G的qcow2格式空镜像。

1
qemu-img create -f qcow2 1060a.qcow2 10G

然后使用准备好的ISO和镜像,创建名为1060a的虚拟机

1
2
3
4
5
6
sudo virt-install --virt-type kvm --name 1060a --ram 4096 \
--cdrom=uniontechos-server-20-1060a-amd64-RC4-20230421-0106.iso \
--disk 1060a.qcow2,bus=virtio,size=10,format=qcow2 \
--network network=default \
--graphics vnc,listen=0.0.0.0 \
--os-type=linux --os-variant=generic

安装时注意两点

  1. 设置网络状态为ON(打开)。默认Ethernet设置为OFF(关闭)。修改为ON(打开)。并且,确认IPv4设置的方法为“自动(DHCP)” 。
  2. 在使用lvm分区时应该将swap分区删除,只保留“/”和“/boot”分区;在使用标准分区时只保留“/”分区即可。

安装完成后

卸载CD-ROM设备

使用virt-manager时,直接在图形化界面删除。也可通过命令行操作。先使用virsh命令查看相应设备。

1
virsh dumpxml 1060a
1
2
3
4
5
6
7
8
9
10
11
<domain>  
<name>1060a</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>

然后再利用命令行卸载,并重启虚拟机。

1
2
virsh attach-disk --type cdrom --mode readonly 1060a "" hd
virsh reboot 1060a

配置镜像

进入镜像系统内部,完成如下操作。

安装ACPI服务

acpid是一个用户空间的服务进程, 用来处理电源相关事件。libvirt可以通过向guest虚拟机发送acpid事件触发电源操作,使虚拟机安全关机、重启等操作。

1
2
dnf install acpid -y
systemctl enable acpid
安装cloud-init

cloud-init是虚拟机第一次启动时执行的脚本,主要负责从metadata服务中拉取配置信息,完成虚拟机的初始化工作,比如设置主机名、初始化密码以及注入密钥等。

1
dnf install cloud-init -y

编辑/etc/cloud/cloud.cfg配置文件,允许root通过password ssh登录。

1
2
disable_root: 0
ssh_pwauth: 1

如上配置便于非生产环境使用,生产环境建议disable_root设为1,ssh_pwauth设为0。不开启密码登录功能,使用密钥登录更安全;同时不开启root远程登录。

修改root密码(可选),编辑/etc/cloud/cloud.cfg配置文件。

1
2
3
4
5
# 注意:新版本cloud-ini的chpasswd中的list已经被users取代,可以通过指定type,改变密码的类型,默认是hash。
chpasswd:
   expire: false
   list: |
     root:qwe123!@#

关闭cloud-init网络配置,网络配置应该由openstack控制,所以关闭。

1
2
network:
config: disabled

配置自动扩容,安装cloud-utils-growpart以允许根分区自动扩容。

1
dnf install cloud-utils-growpart -y

编辑cloud-init配置文件。

1
2
3
4
5
6
7
8
9
10
11
#cloud-config
growpart:
mode: auto
devices: [/dev/vda2]
ignore_growroot_disabled: false
bootcmd:
- [cloud-init-per,once,mygrowpart,growpart,/dev/vda,2]
- [cloud-init-per,once,mypartprobe,partprobe,-s,/dev/vda2]
- [cloud-init-per,once,mypvresize,pvresize,/dev/vda2]
- [cloud-init-per,once,mylvextend,lvextend,-l,+100%FREE,/dev/mapper/uos-root]
- [cloud-init-per,once,myxfs_growfs,xfs_growfs,/dev/mapper/uos-root]

需要根据具体环境情况修改配置文件,例如1050a中是uniontechos-root,而1060a中是uos-root。
如果是非lvm分区安装,需要改成下面所示。

1
2
3
bootcmd:
  - [ cloud-init-per, once, grow-partition, growpart, /dev/vda, 1 ]
  - [ cloud-init-per, once, resize-filesystem, xfs_growfs, /dev/vda1 ]

正确设置字符集,否则执行growpart会出错。

1
LANG=en_US.UTF-8
禁用firewalld
1
systemctl disable firewalld.service
禁用zeroconf
1
echo "NOZEROCONF=yes" >> /etc/sysconfig/network
配置console

编辑 /etc/default/grub文件,配置GRUB_CMDLINE_LINUX选项。删除“rhgb quiet”,添加“console=tty0 console=ttyS0,115200n8”。使nova能够获取console log。

1
2
GRUB_CMDLINE_LINUX="crashkernel=auto elevator=none console=tty0 console=ttyS0,115200n8"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=uniontechos/root elevator=none console=tty0 console=ttyS0,115200n8"

运行如下命令,保存更改:

1
grub2-mkconfig -o /boot/grub2/grub.cfg

启用serial-getty服务,使用户可以通过virsh console进入虚拟机。

1
2
systemctl enable serial-getty@ttyS0.service
systemctl start serial-getty@ttyS0.service
配置qemu-guest-agent服务

qemu-guest-agent类似于VMware tools,主要⽤于辅助Hypervisor实现对Guest的管理。通过qemu-guest-agent,openstack可以使用命令行直接修改管理员账户的密码。

安装服务

1
dnf install -y qemu-guest-agent

启用服务

1
systemctl enable qemu-guest-agent

注意,在openstack创建镜像时要指定镜像的属性hw_qemu_guest_agent=yes。

1
openstack image set --property hw_qemu_guest_agent=yes d1d3c1ad-7292-4e64-87a1-4a6069ec4056

使用openstack命令修改管理员密码。

1
openstack server set --root-password test-1060a
禁用自动退出
1
2
3
vim /etc/profile
export TMOUT=0
source /etc/profile
删除网络配置文件

uos采用NetworkManager进行网络的管理,如果遇到同名的网络设备时,系统在第一次启动时会跳过连接流程。

1
rm -f /etc/sysconfig/network-scripts/ifcfg-enp0s3 

关闭虚拟机

在虚拟机内部,以root用户运行:
poweroff

清理(移除mac地址等信息)

在宿主机上运行。

1
sudo virt-sysprep -d 1060a

此时将1060a对应的qcow2文件拷贝走即可使用。

镜像压缩

qemu-img命令可以用来降低镜像大小,回收实际内容为零的空间

1
qemu-img convert -p -c -O qcow2 1060a.qcow2 uniontechos-server-20-1060a-amd64-RC4-20230421-0106-minimal.qcow2

脚本自动化构建

diskimage-builder(简称为DIB)是一个用于自动构建自定义的操作系统镜像的工具,以便在云和其他环境中使用。

构建docker容器

利用docker容器来搭建镜像的环境,这里选择centos镜像,同时将本地目录和容器内的文件目录做一个映射。

1
docker run -itd --privileged=true --name centos -v $PWD:/root centos:7 /sbin/init

安装

依赖环境

进入容器内安装DIB的依赖环境。

1
2
3
4
5
docker exec -it centos bash
yum update
yum install -y epel-release
yum install -y python3 git sudo # DIB需要Python3支持
pip3 install -U pip setuptools wheel

安装qemu-img和kpartx。

1
2
apt-get install qemu-utils kpartx squashfs-tools e4fsprogs # ubuntu
yum install -y qemu-img kpartx squashfs-tools e4fsprogs # centos

DIB

从github将DIB下载下来。

1
git clone https://github.com/openstack/diskimage-builder.git

切换到最近的tag上,我这里是3.7.0。

1
2
cd diskimge-builder
git checkout -b v3.7.0 3.7.0

设置虚环境

1
2
pip install virtualenv
mkdir venv && cd venv && virtualenv -p /usr/bin/python3 diskimage-builder

安装diskimage-builder。

1
cd /root/diskimage-builder && /root/venv/diskimage-builder/bin/pip install -e .

测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[root@centos-linux ~]# disk-image-create -h
Usage: disk-image-create [OPTION]... [ELEMENT]...

Options:
-a i386|amd64|armhf|arm64 -- set the architecture of the image(default amd64)
-o imagename -- set the imagename of the output image file(default image)
-t qcow2,tar,tgz,squashfs,vhd,docker,aci,raw -- set the image types of the output image files (default qcow2)
File types should be comma separated. VHD outputting requires the vhd-util
executable be in your PATH. ACI outputting requires the ACI_MANIFEST
environment variable be a path to a manifest file.
-x -- turn on tracing (use -x -x for very detailed tracing).
-u -- uncompressed; do not compress the image - larger but faster
-c -- clear environment before starting work
--logfile -- save run output to given logfile (implies DIB_QUIET=1)
--checksum -- generate MD5 and SHA256 checksum files for the created image
--image-size size -- image size in GB for the created image
--image-extra-size size -- extra image size in GB for the created image
--image-cache directory -- location for cached images(default ~/.cache/image-create)
--max-online-resize size -- max number of filesystem blocks to support when resizing.
Useful if you want a really large root partition when the image is deployed.
Using a very large value may run into a known bug in resize2fs.
Setting the value to 274877906944 will get you a 1PB root file system.
Making this value unnecessarily large will consume extra disk space
on the root partition with extra file system inodes.
--min-tmpfs size -- minimum size in GB needed in tmpfs to build the image
--mkfs-journal-size -- filesystem journal size in MB to pass to mkfs.
--mkfs-options -- option flags to be passed directly to mkfs.
Options should be passed as a single string value.
--no-tmpfs -- do not use tmpfs to speed image build
--offline -- do not update cached resources
--qemu-img-options -- option flags to be passed directly to qemu-img.
Options need to be comma separated, and follow the key=value pattern.
--root-label label -- label for the root filesystem. Defaults to 'cloudimg-rootfs'.
--ramdisk-element -- specify the main element to be used for building ramdisks.
Defaults to 'ramdisk'. Should be set to 'dracut-ramdisk' for platforms such
as RHEL and CentOS that do not package busybox.
--install-type -- specify the default installation type. Defaults to 'source'. Set to 'package' to use package based installations by default.
--docker-target -- specify the repo and tag to use if the output type is docker. Defaults to the value of output imagename
-n skip the default inclusion of the 'base' element
-p package[,p2...] [-p p3] -- extra packages to install in the image. Runs once, after 'install.d' phase. Can be specified multiple times
-h|--help -- display this help and exit
--version -- display version and exit

Environment Variables:
(this is not a complete list)

* ELEMENTS_PATH: specify external locations for the elements. As for $PATH
* DIB_NO_TIMESTAMP: no timestamp prefix on output. Useful if capturing output
* DIB_QUIET: 1=do not output log output to stdout; 0=always ouptut to stdout. See --logfile

NOTE: At least one distribution root element must be specified.

NOTE: If using the VHD output format you need to have a patched version of vhd-util installed for the image
to be bootable. The patch is available here: https://github.com/emonty/vhd-util/blob/master/debian/patches/citrix
and a PPA with the patched tool is available here: https://launchpad.net/~openstack-ci-core/+archive/ubuntu/vhd-util

Examples:
disk-image-create -a amd64 -o ubuntu-amd64 vm ubuntu
export ELEMENTS_PATH=~/source/tripleo-image-elements/elements
disk-image-create -a amd64 -o fedora-amd64-heat-cfntools vm fedora heat-cfntools

创建ubuntu镜像。

1
/root/venv/diskimage-builder/bin/disk-image-create -a amd64 -o ubuntu-amd64 vm ubuntu

镜像修改

密码修改

镜像密码往往是一个比较令人头疼的问题。针对从centos、ubuntu官网上下载的镜像可以在创建完实例后,通过qemu-guest-agent服务修改root密码。需要提前设置镜像的属性打开qemu-guest-agent服务。

1
openstack image set --property hw_qemu_guest_agent=yes <image_id>

然后使用openstack命令修改管理员密码。

1
openstack server set --root-password <server_id>

这样做有几个缺点,每当创建完实例后都需要执行root修改密码操作,而且往往root用户不能直接使用ssh登录,只能通过vnc的方式先连接到实例,再修改ssh的配置,才能远程登录。但好在这些官方的镜像往往都采用cloud-init的方式,可以通过修改cloud-init的配置文件修改root登录。

使用guestfish

在计算节点(运行libvirtd服务的节点)上,使用guestfish命令。

1
2
# 安装依赖包
yum install -y libguestfs-tools

执行guestfish命令。

1
2
3
4
5
6
7
8
guestfish --rw -a CentOS-Stream-GenericCloud-9-x86_64.qcow2
><fs> run
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
><fs> list-filesystems
/dev/sda1: xfs
><fs> mount /dev/sda1 /
><fs> vi /etc/cloud/cloud.cfg # 编辑cloud-init的配置文件
><fs> vi /etc/ssh/sshd_config # 编辑sshd服务的配置文件

编辑cloud-init的配置文件/etc/cloud/cloud.cfg。

1
2
3
4
5
6
7
8
9
10
# 打开root登录
disable_root: false
# 打开ssh 密码登录
ssh_pwauth: true
# 修改root密码。
# 注意:新版本cloud-ini的chpasswd中的list已经被users取代,可以通过指定type,改变密码的类型,默认是hash。
chpasswd:
expire: false
list: |
root:centos

还可以直接修改/etc/shadow来修改密码。shadow文件一般由下面9个字段组成。

1
用户名:加密密码:最后一次修改时间:最小修改时间间隔:密码有效期:密码需要变更前的警告天数:密码过期后的宽限时间:账号失效时间:保留字段

例如。

1
root:$1$w07Q2CQS$6aSP5uit0/sLG6p1uzaOc.:19527:0:99999:7:::

$1$w07Q2CQS$6aSP5uit0/sLG6p1uzaOc.即使加密的密码。其中密码的开头部分,$1$表示使用MD5算法,$2a$表示使用Blowfish算法,”$2y$”是另一算法长度的Blowfish,”$5$”表示SHA-256算法,而”$6$”表示SHA-512算法。

目前Linux的密码采用的是SHA512散列加密算法,原来采用的是MD5或DES加密算法。SHA512散列加密算法的加密等级更高,也更加安全。

使用openssl命令,可简单的生成MD5加密。

1
2
openssl passwd -1 'qwe123!@#'
$1$i7sJan8C$kE9Lin.FiytHTz4QtNjal0

使用python的crypt模块,可生成SHA512加密。

1
2
python3 -c "import crypt;print(crypt.crypt('qwe123\!\@\#'))"
$6$acVoXs6xgUiLxnhS$uyTSoX42qCE6FqqldpLyfV4mDHhI7j2qIL56WiKYKpSFnPRziBOMhgEhgGB/12XKZJNceamTkEk6mfd3/vpgT.

编辑ssh的配置文件/etc/ssh/sshd_config。

1
2
PermitRootLogin yes
PasswordAuthentication yes

保存退出。

1
><fs> quit

使用virt-customize

在计算节点(运行libvirtd服务的节点)上,安装依赖包。

1
yum install -y libguestfs-tools

使用virt-customize命令。

1
sudo virt-customize -a CentOS-Stream-GenericCloud-9-x86_64.qcow2 --root-password password:123456

如果出现下面的错误。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[   0.0] Examining the guest ...
virt-customize: error: libguestfs error: could not create appliance through
libvirt.

Try running qemu directly without libvirt using this environment variable:
export LIBGUESTFS_BACKEND=direct

Original error from libvirt: Cannot access storage file
'/root/CentOS-Stream-GenericCloud-9-x86_64.qcow2' (as uid:107, gid:107):
权限不够 [code=38 int1=13]

If reporting bugs, run virt-customize with debugging enabled and include
the complete output:

virt-customize -v -x [...]

执行下面的操作,修改libvirtd的权限。

1
2
3
4
5
cat >> /etc/libvirt/qemu.conf << EOF
user = "root"
group = "root"
EOF
systemctl restart libvirtd.service

使用horizon

horizon界面支持用户在创建云主机时注入密码,仅针对开启qemu-guest-agent服务的镜像。

修改horizon的local_settings.py文件。

1
2
3
4
OPENSTACK_HYPERVISOR_FEATURES = {
...
'can_set_password': True,
}

修改/etc/nova/nova.conf,kolla部署的nova修改/etc/kolla/nova-compute/nova.conf。

1
2
[libvirt]
inject_password=true

重启horizon和nova-compute服务。

1
systemctl restart httpd nova-compute

查看horizon界面。

上传镜像

使用OpenStack命令上传镜像。

1
2
3
4
openstack image create --disk-format qcow2 \
--container-format bare --public \
--file ./CentOS-Stream-GenericCloud-9-x86_64.qcow2 \
CentOS-Stream-GenericCloud-9-x86_64

使用ISO启动实例

UOS镜像

使用uos镜像创建一个实例,创建时选择不从volume启动。实例ID为a06135f1-4aa9-405d-910d-e398d83c5ecc,其中libvirtd的xml如下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<domain type='kvm' id='63'>
<name>instance-0000138b</name>
<uuid>a06135f1-4aa9-405d-910d-e398d83c5ecc</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/a06135f1-4aa9-405d-910d-e398d83c5ecc/disk' index='1'/>
<backingStore type='file' index='2'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/5318b1004ad87ba4770212c2f6b1c9fc32f23787'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
...
</devices>
</domain>

nova表中block_device_mapping记录了磁盘的映射关系。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
select * from block_device_mapping where instance_uuid="a06135f1-4aa9-405d-910d-e398d83c5ecc" \G
*************************** 1. row ***************************
created_at: 2023-05-11 08:52:48
updated_at: 2023-05-11 08:52:49
deleted_at: NULL
id: 8740
device_name: /dev/hda
delete_on_termination: 1
snapshot_id: NULL
volume_id: NULL
volume_size: NULL
no_device: 0
connection_info: NULL
instance_uuid: a06135f1-4aa9-405d-910d-e398d83c5ecc
deleted: 0
source_type: image
destination_type: local
guest_format: NULL
device_type: disk
disk_bus: NULL
boot_index: 0
image_id: 17200200-24d9-4872-b973-af7a85a12c53
tag: NULL
attachment_id: NULL
uuid: edf44737-4835-47ff-b641-a17e15822ad0
volume_type: NULL
1 row in set (0.000 sec)

此时实例进入安装界面,但是没有磁盘。新建一块磁盘用于安装系统。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
openstack volume create --size 100 --availability-zone nova --bootable wkt-uos-desktop-test-without-volume
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2023-05-11T09:01:06.000000 |
| description | None |
| encrypted | False |
| id | 304d88ac-3460-4c5d-950d-f17528b97e1a |
| migration_status | None |
| multiattach | False |
| name | wkt-uos-desktop-test-without-volume |
| properties | |
| replication_status | None |
| size | 100 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | __DEFAULT__ |
| updated_at | None |
| user_id | 24d08826a98140ce8e2ade2606ff9ad8 |
+---------------------+--------------------------------------+

等待磁盘创建完成后,添加到实例上。

1
openstack server add volume a06135f1-4aa9-405d-910d-e398d83c5ecc 304d88ac-3460-4c5d-950d-f17528b97e1a

此时block_device_mapping表中为。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
select * from block_device_mapping where instance_uuid="a06135f1-4aa9-405d-910d-e398d83c5ecc" \G
*************************** 1. row ***************************
created_at: 2023-05-11 08:52:48
updated_at: 2023-05-11 08:52:49
deleted_at: NULL
id: 8740
device_name: /dev/hda
delete_on_termination: 1
snapshot_id: NULL
volume_id: NULL
volume_size: NULL
no_device: 0
connection_info: NULL
instance_uuid: a06135f1-4aa9-405d-910d-e398d83c5ecc
deleted: 0
source_type: image
destination_type: local
guest_format: NULL
device_type: disk
disk_bus: NULL
boot_index: 0
image_id: 17200200-24d9-4872-b973-af7a85a12c53
tag: NULL
attachment_id: NULL
uuid: edf44737-4835-47ff-b641-a17e15822ad0
volume_type: NULL
*************************** 2. row ***************************
created_at: 2023-05-11 09:03:21
updated_at: 2023-05-11 09:03:28
deleted_at: NULL
id: 8741
device_name: /dev/vda
delete_on_termination: 0
snapshot_id: NULL
volume_id: 304d88ac-3460-4c5d-950d-f17528b97e1a
volume_size: 100
no_device: NULL
connection_info: {"driver_volume_type": "iscsi", "data": {"target_discovered": false, "target_portal": "10.10.15.12:3260", "target_iqn": "iqn.2010-10.org.openstack:volume-304d88ac-3460-4c5d-950d-f17528b97e1a", "target_lun": 0, "volume_id": "304d88ac-3460-4c5d-950d-f17528b97e1a", "auth_method": "CHAP", "auth_username": "h8e7h5iC5kMjFVJN6rfD", "auth_password": "wNmMTBsTMBs8dV67", "encrypted": false, "qos_specs": null, "access_mode": "rw", "device_path": "/dev/sdf"}, "status": "reserved", "instance": "a06135f1-4aa9-405d-910d-e398d83c5ecc", "attached_at": "", "detached_at": "", "volume_id": "304d88ac-3460-4c5d-950d-f17528b97e1a", "serial": "304d88ac-3460-4c5d-950d-f17528b97e1a"}
instance_uuid: a06135f1-4aa9-405d-910d-e398d83c5ecc
deleted: 0
source_type: volume
destination_type: volume
guest_format: NULL
device_type: NULL
disk_bus: NULL
boot_index: NULL
image_id: NULL
tag: NULL
attachment_id: 12cb3da5-a87f-4035-a0f9-c31a1306ce72
uuid: f1f7a8e6-b59b-4fde-a37d-af020979d4a4
volume_type: NULL
2 rows in set (0.001 sec)

此时实例的xml文件已经改变,可以看到新增了一块磁盘,但是系统界面看不到。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<domain type='kvm' id='63'>
<name>instance-0000138b</name>
<uuid>a06135f1-4aa9-405d-910d-e398d83c5ecc</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/a06135f1-4aa9-405d-910d-e398d83c5ecc/disk' index='1'/>
<backingStore type='file' index='2'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/5318b1004ad87ba4770212c2f6b1c9fc32f23787'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdf' index='3'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>304d88ac-3460-4c5d-950d-f17528b97e1a</serial>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
...
</devices>
</domain>

将实例硬重启。

1
openstack server reboot --hard a06135f1-4aa9-405d-910d-e398d83c5ecc

可以看到xml文件中disk的index发生了变化。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/a06135f1-4aa9-405d-910d-e398d83c5ecc/disk' index='2'/>
<backingStore type='file' index='3'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/5318b1004ad87ba4770212c2f6b1c9fc32f23787'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdf' index='1'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>304d88ac-3460-4c5d-950d-f17528b97e1a</serial>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>

这时进入系统的安装界面可以看到多了一块磁盘,然后进行系统的安装。系统安装完成的最后,会提示用户重启,用户点击重启后,又进入到系统的安装界面。此时及时进行硬重启也不解决问题,依旧进入系统的安装界面。

通过修改block_device_mapping表,尝试修改实例磁盘的启动顺序。

1
2
3
4
5
# 先将安装完系统的盘的boot_index设置为0。
update block_device_mapping set boot_index=0 where id=8741;

# 然后将安装盘的boot_index设置为空。
update block_device_mapping set boot_index=NULL where id=8740;

最后将实例硬重启。

1
openstack server reboot --hard a06135f1-4aa9-405d-910d-e398d83c5ecc

查看xml文件,可以看到boot的设备由cdrom变为hd。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<domain type='kvm' id='66'>
<name>instance-0000138b</name>
<uuid>a06135f1-4aa9-405d-910d-e398d83c5ecc</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdf' index='1'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>304d88ac-3460-4c5d-950d-f17528b97e1a</serial>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
...
</devices>
</domain>

此时可以正常进入系统。

Windows镜像

首先windows系统安装时需要virtio的驱动来读取磁盘信息,所以先以virtio的镜像创建一个volume。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
openstack volume create --size 1 --image virtio-win-0.1.225 --availability-zone nova wkt-virtio-win-0.1.225
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2023-05-11T09:45:32.000000 |
| description | None |
| encrypted | False |
| id | 07476fea-b4bc-4bfc-86d4-84520a954ce6 |
| migration_status | None |
| multiattach | False |
| name | wkt-virtio-win-0.1.225 |
| properties | |
| replication_status | None |
| size | 1 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | __DEFAULT__ |
| updated_at | None |
| user_id | 24d08826a98140ce8e2ade2606ff9ad8 |
+---------------------+--------------------------------------+

等到volume状态变为可用时,创建windows实例。

1
2
3
4
5
6
7
nova boot --availability-zone cloud \
--flavor 8-8-0 \
--image 60f8adab-fceb-47a2-a32a-f19d2351177e \
--nic net-id=7b6c69b5-bfa5-4145-901c-26979103da77 \
--block-device id=eb2006ba-6416-4b68-b8bf-b358589fba34,source=image,dest=volume,bus=ide,type=cdrom,size=1 \
wkt-windows-test

实例的ID是5ace35d4-7195-465e-afca-2c81279bb677。

查看block_device_mapping表的映射关系。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
select * from block_device_mapping where instance_uuid="5ace35d4-7195-465e-afca-2c81279bb677" \G
*************************** 1. row ***************************
created_at: 2023-05-12 02:10:28
updated_at: 2023-05-12 02:10:28
deleted_at: NULL
id: 8746
device_name: /dev/hda
delete_on_termination: 1
snapshot_id: NULL
volume_id: NULL
volume_size: NULL
no_device: 0
connection_info: NULL
instance_uuid: 5ace35d4-7195-465e-afca-2c81279bb677
deleted: 0
source_type: image
destination_type: local
guest_format: NULL
device_type: NULL
disk_bus: NULL
boot_index: 0
image_id: 60f8adab-fceb-47a2-a32a-f19d2351177e
tag: NULL
attachment_id: NULL
uuid: 6de66a02-6efb-4ce0-89a1-fa477f976909
volume_type: NULL
*************************** 2. row ***************************
created_at: 2023-05-12 02:10:28
updated_at: 2023-05-12 02:11:02
deleted_at: NULL
id: 8747
device_name: /dev/hdb
delete_on_termination: 0
snapshot_id: NULL
volume_id: c5f26969-397c-491b-8ee6-a2e9df1f9b42
volume_size: 1
no_device: 0
connection_info: {"driver_volume_type": "iscsi", "data": {"target_discovered": false, "target_portal": "10.10.15.12:3260", "target_iqn": "iqn.2010-10.org.openstack:volume-c5f26969-397c-491b-8ee6-a2e9df1f9b42", "target_lun": 0, "volume_id": "c5f26969-397c-491b-8ee6-a2e9df1f9b42", "auth_method": "CHAP", "auth_username": "MDksZ4gonTVKwayfr2fB", "auth_password": "jjEXzRGtzbFKiB6m", "encrypted": false, "qos_specs": null, "access_mode": "rw", "device_path": "/dev/sdg"}, "status": "reserved", "instance": "5ace35d4-7195-465e-afca-2c81279bb677", "attached_at": "", "detached_at": "", "volume_id": "c5f26969-397c-491b-8ee6-a2e9df1f9b42", "serial": "c5f26969-397c-491b-8ee6-a2e9df1f9b42"}
instance_uuid: 5ace35d4-7195-465e-afca-2c81279bb677
deleted: 0
source_type: image
destination_type: volume
guest_format: NULL
device_type: cdrom
disk_bus: ide
boot_index: NULL
image_id: eb2006ba-6416-4b68-b8bf-b358589fba34
tag: NULL
attachment_id: c45a1ce7-16b0-4319-90d0-2a08463cc220
uuid: 94a9eb85-e31b-41cd-bf07-431d7a6f9534
volume_type: NULL
2 rows in set (0.000 sec)

xml配置文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<domain type='kvm' id='69'>
<name>instance-0000138e</name>
<uuid>5ace35d4-7195-465e-afca-2c81279bb677</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/5ace35d4-7195-465e-afca-2c81279bb677/disk' index='2'/>
<backingStore type='file' index='3'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/77a37f6c71682eba3d2f883c4736edd52b431752'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdg' index='1'/>
<backingStore/>
<target dev='hdb' bus='ide'/>
<readonly/>
<serial>c5f26969-397c-491b-8ee6-a2e9df1f9b42</serial>
<alias name='ide0-0-1'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
...
</devices>
</domain>

添加系统盘。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
openstack volume create --size 100 --availability-zone nova --bootable wkt-windows-test-volume
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2023-05-12T02:16:56.000000 |
| description | None |
| encrypted | False |
| id | d1e96c3b-7a2a-478d-ab98-de94aefcbc0e |
| migration_status | None |
| multiattach | False |
| name | wkt-windows-test-volume |
| properties | |
| replication_status | None |
| size | 100 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | __DEFAULT__ |
| updated_at | None |
| user_id | 24d08826a98140ce8e2ade2606ff9ad8 |
+---------------------+--------------------------------------+

等待磁盘创建完成后,添加到实例上。

1
openstack server add volume 5ace35d4-7195-465e-afca-2c81279bb677 d1e96c3b-7a2a-478d-ab98-de94aefcbc0e

查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
select * from block_device_mapping where instance_uuid="5ace35d4-7195-465e-afca-2c81279bb677" \G
*************************** 1. row ***************************
created_at: 2023-05-12 02:10:28
updated_at: 2023-05-12 02:10:28
deleted_at: NULL
id: 8746
device_name: /dev/hda
delete_on_termination: 1
snapshot_id: NULL
volume_id: NULL
volume_size: NULL
no_device: 0
connection_info: NULL
instance_uuid: 5ace35d4-7195-465e-afca-2c81279bb677
deleted: 0
source_type: image
destination_type: local
guest_format: NULL
device_type: NULL
disk_bus: NULL
boot_index: 0
image_id: 60f8adab-fceb-47a2-a32a-f19d2351177e
tag: NULL
attachment_id: NULL
uuid: 6de66a02-6efb-4ce0-89a1-fa477f976909
volume_type: NULL
*************************** 2. row ***************************
created_at: 2023-05-12 02:10:28
updated_at: 2023-05-12 02:11:02
deleted_at: NULL
id: 8747
device_name: /dev/hdb
delete_on_termination: 0
snapshot_id: NULL
volume_id: c5f26969-397c-491b-8ee6-a2e9df1f9b42
volume_size: 1
no_device: 0
connection_info: {"driver_volume_type": "iscsi", "data": {"target_discovered": false, "target_portal": "10.10.15.12:3260", "target_iqn": "iqn.2010-10.org.openstack:volume-c5f26969-397c-491b-8ee6-a2e9df1f9b42", "target_lun": 0, "volume_id": "c5f26969-397c-491b-8ee6-a2e9df1f9b42", "auth_method": "CHAP", "auth_username": "MDksZ4gonTVKwayfr2fB", "auth_password": "jjEXzRGtzbFKiB6m", "encrypted": false, "qos_specs": null, "access_mode": "rw", "device_path": "/dev/sdg"}, "status": "reserved", "instance": "5ace35d4-7195-465e-afca-2c81279bb677", "attached_at": "", "detached_at": "", "volume_id": "c5f26969-397c-491b-8ee6-a2e9df1f9b42", "serial": "c5f26969-397c-491b-8ee6-a2e9df1f9b42"}
instance_uuid: 5ace35d4-7195-465e-afca-2c81279bb677
deleted: 0
source_type: image
destination_type: volume
guest_format: NULL
device_type: cdrom
disk_bus: ide
boot_index: NULL
image_id: eb2006ba-6416-4b68-b8bf-b358589fba34
tag: NULL
attachment_id: c45a1ce7-16b0-4319-90d0-2a08463cc220
uuid: 94a9eb85-e31b-41cd-bf07-431d7a6f9534
volume_type: NULL
*************************** 3. row ***************************
created_at: 2023-05-12 02:19:10
updated_at: 2023-05-12 02:19:11
deleted_at: NULL
id: 8748
device_name: /dev/vda
delete_on_termination: 0
snapshot_id: NULL
volume_id: d1e96c3b-7a2a-478d-ab98-de94aefcbc0e
volume_size: NULL
no_device: NULL
connection_info: NULL
instance_uuid: 5ace35d4-7195-465e-afca-2c81279bb677
deleted: 0
source_type: volume
destination_type: volume
guest_format: NULL
device_type: NULL
disk_bus: NULL
boot_index: NULL
image_id: NULL
tag: NULL
attachment_id: 418d9322-eef3-4b15-9ca0-fbda0d7c9140
uuid: b5f6b25d-44f3-416e-aab3-3ce350607d4a
volume_type: NULL
3 rows in set (0.001 sec)

xml配置文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<domain type='kvm' id='69'>
<name>instance-0000138e</name>
<uuid>5ace35d4-7195-465e-afca-2c81279bb677</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/5ace35d4-7195-465e-afca-2c81279bb677/disk' index='2'/>
<backingStore type='file' index='3'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/77a37f6c71682eba3d2f883c4736edd52b431752'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdg' index='1'/>
<backingStore/>
<target dev='hdb' bus='ide'/>
<readonly/>
<serial>c5f26969-397c-491b-8ee6-a2e9df1f9b42</serial>
<alias name='ide0-0-1'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdh' index='4'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>d1e96c3b-7a2a-478d-ab98-de94aefcbc0e</serial>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
...
</devices>
</domain>

硬重启实例5ace35d4-7195-465e-afca-2c81279bb677。

1
openstack server reboot --hard 5ace35d4-7195-465e-afca-2c81279bb677
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
select * from block_device_mapping where instance_uuid="5ace35d4-7195-465e-afca-2c81279bb677" \G
*************************** 1. row ***************************
created_at: 2023-05-12 02:10:28
updated_at: 2023-05-12 02:10:28
deleted_at: NULL
id: 8746
device_name: /dev/hda
delete_on_termination: 1
snapshot_id: NULL
volume_id: NULL
volume_size: NULL
no_device: 0
connection_info: NULL
instance_uuid: 5ace35d4-7195-465e-afca-2c81279bb677
deleted: 0
source_type: image
destination_type: local
guest_format: NULL
device_type: NULL
disk_bus: NULL
boot_index: 0
image_id: 60f8adab-fceb-47a2-a32a-f19d2351177e
tag: NULL
attachment_id: NULL
uuid: 6de66a02-6efb-4ce0-89a1-fa477f976909
volume_type: NULL
*************************** 2. row ***************************
created_at: 2023-05-12 02:10:28
updated_at: 2023-05-12 02:22:46
deleted_at: NULL
id: 8747
device_name: /dev/hdb
delete_on_termination: 0
snapshot_id: NULL
volume_id: c5f26969-397c-491b-8ee6-a2e9df1f9b42
volume_size: 1
no_device: 0
connection_info: {"driver_volume_type": "iscsi", "data": {"target_discovered": false, "target_portal": "10.10.15.12:3260", "target_iqn": "iqn.2010-10.org.openstack:volume-c5f26969-397c-491b-8ee6-a2e9df1f9b42", "target_lun": 0, "volume_id": "c5f26969-397c-491b-8ee6-a2e9df1f9b42", "auth_method": "CHAP", "auth_username": "MDksZ4gonTVKwayfr2fB", "auth_password": "jjEXzRGtzbFKiB6m", "encrypted": false, "qos_specs": null, "access_mode": "rw", "device_path": "/dev/sdh"}, "status": "reserved", "instance": "5ace35d4-7195-465e-afca-2c81279bb677", "attached_at": "", "detached_at": "", "volume_id": "c5f26969-397c-491b-8ee6-a2e9df1f9b42", "serial": "c5f26969-397c-491b-8ee6-a2e9df1f9b42"}
instance_uuid: 5ace35d4-7195-465e-afca-2c81279bb677
deleted: 0
source_type: image
destination_type: volume
guest_format: NULL
device_type: cdrom
disk_bus: ide
boot_index: NULL
image_id: eb2006ba-6416-4b68-b8bf-b358589fba34
tag: NULL
attachment_id: c45a1ce7-16b0-4319-90d0-2a08463cc220
uuid: 94a9eb85-e31b-41cd-bf07-431d7a6f9534
volume_type: NULL
*************************** 3. row ***************************
created_at: 2023-05-12 02:19:10
updated_at: 2023-05-12 02:22:45
deleted_at: NULL
id: 8748
device_name: /dev/vda
delete_on_termination: 0
snapshot_id: NULL
volume_id: d1e96c3b-7a2a-478d-ab98-de94aefcbc0e
volume_size: 100
no_device: NULL
connection_info: {"driver_volume_type": "iscsi", "data": {"target_discovered": false, "target_portal": "10.10.15.12:3260", "target_iqn": "iqn.2010-10.org.openstack:volume-d1e96c3b-7a2a-478d-ab98-de94aefcbc0e", "target_lun": 0, "volume_id": "d1e96c3b-7a2a-478d-ab98-de94aefcbc0e", "auth_method": "CHAP", "auth_username": "7KCnU2hmY9nkUuAoM5Nc", "auth_password": "4SMDpNsTFFmzjJi5", "encrypted": false, "qos_specs": null, "access_mode": "rw", "device_path": "/dev/sdg"}, "status": "reserved", "instance": "5ace35d4-7195-465e-afca-2c81279bb677", "attached_at": "", "detached_at": "", "volume_id": "d1e96c3b-7a2a-478d-ab98-de94aefcbc0e", "serial": "d1e96c3b-7a2a-478d-ab98-de94aefcbc0e"}
instance_uuid: 5ace35d4-7195-465e-afca-2c81279bb677
deleted: 0
source_type: volume
destination_type: volume
guest_format: NULL
device_type: disk
disk_bus: virtio
boot_index: NULL
image_id: NULL
tag: NULL
attachment_id: 418d9322-eef3-4b15-9ca0-fbda0d7c9140
uuid: b5f6b25d-44f3-416e-aab3-3ce350607d4a
volume_type: NULL
3 rows in set (0.001 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<domain type='kvm' id='70'>
<name>instance-0000138e</name>
<uuid>5ace35d4-7195-465e-afca-2c81279bb677</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/5ace35d4-7195-465e-afca-2c81279bb677/disk' index='3'/>
<backingStore type='file' index='4'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/77a37f6c71682eba3d2f883c4736edd52b431752'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdh' index='2'/>
<backingStore/>
<target dev='hdb' bus='ide'/>
<readonly/>
<serial>c5f26969-397c-491b-8ee6-a2e9df1f9b42</serial>
<alias name='ide0-0-1'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdg' index='1'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>d1e96c3b-7a2a-478d-ab98-de94aefcbc0e</serial>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
...
</devices>
</domain>

进入系统的安装界面后开始安装windows系统。安装完成后,在实例内部重启系统,会进入系统安装界面,硬重启后解决。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<domain type='kvm' id='70'>
<name>instance-0000138e</name>
<uuid>5ace35d4-7195-465e-afca-2c81279bb677</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/5ace35d4-7195-465e-afca-2c81279bb677/disk' index='3'/>
<backingStore type='file' index='4'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/77a37f6c71682eba3d2f883c4736edd52b431752'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdh' index='2'/>
<backingStore/>
<target dev='hdb' bus='ide'/>
<readonly/>
<serial>c5f26969-397c-491b-8ee6-a2e9df1f9b42</serial>
<alias name='ide0-0-1'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdg' index='1'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>d1e96c3b-7a2a-478d-ab98-de94aefcbc0e</serial>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
...
</devices>
</domain>

Ubuntu镜像

创建磁盘。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
openstack volume create --size 100 --availability-zone nova --bootable wkt-ubuntu-test-volume
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| attachments | [] |
| availability_zone | nova |
| bootable | false |
| consistencygroup_id | None |
| created_at | 2023-05-12T06:50:54.000000 |
| description | None |
| encrypted | False |
| id | 9275c580-6679-4f60-810b-06ca11ae8742 |
| migration_status | None |
| multiattach | False |
| name | wkt-ubuntu-test-volume |
| properties | |
| replication_status | None |
| size | 100 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| type | __DEFAULT__ |
| updated_at | None |
| user_id | 24d08826a98140ce8e2ade2606ff9ad8 |
+---------------------+--------------------------------------+

创建实例,ID是dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361。

1
2
3
4
5
openstack server create --availability-zone cloud \
--flavor 8-8-0 \
--image 82f524ed-4d97-445f-b527-f5299c5d0b3b \
--network 7b6c69b5-bfa5-4145-901c-26979103da77 \
wkt-ubuntu-test

查看block_device_mapping表。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
select * from block_device_mapping where instance_uuid="dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361" \G
*************************** 1. row ***************************
created_at: 2023-05-12 06:54:05
updated_at: 2023-05-12 06:54:06
deleted_at: NULL
id: 8751
device_name: /dev/hda
delete_on_termination: 1
snapshot_id: NULL
volume_id: NULL
volume_size: NULL
no_device: 0
connection_info: NULL
instance_uuid: dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361
deleted: 0
source_type: image
destination_type: local
guest_format: NULL
device_type: disk
disk_bus: NULL
boot_index: 0
image_id: 82f524ed-4d97-445f-b527-f5299c5d0b3b
tag: NULL
attachment_id: NULL
uuid: 8e57c44d-9fb5-44d9-807d-ae4c675a1c91
volume_type: NULL
1 row in set (0.001 sec)

xml配置文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<domain type='kvm' id='73'>
<name>instance-00001391</name>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361/disk' index='1'/>
<backingStore type='file' index='2'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/d2db90ced7b2064373138e505ea3ed5a0b6374c7'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
...
</devices>
</domain>

添加磁盘。

1
openstack server add volume dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361 9275c580-6679-4f60-810b-06ca11ae8742

查看block_device_mapping表。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
select * from block_device_mapping where instance_uuid="dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361" \G
*************************** 1. row ***************************
created_at: 2023-05-12 06:54:05
updated_at: 2023-05-12 06:54:06
deleted_at: NULL
id: 8751
device_name: /dev/hda
delete_on_termination: 1
snapshot_id: NULL
volume_id: NULL
volume_size: NULL
no_device: 0
connection_info: NULL
instance_uuid: dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361
deleted: 0
source_type: image
destination_type: local
guest_format: NULL
device_type: disk
disk_bus: NULL
boot_index: 0
image_id: 82f524ed-4d97-445f-b527-f5299c5d0b3b
tag: NULL
attachment_id: NULL
uuid: 8e57c44d-9fb5-44d9-807d-ae4c675a1c91
volume_type: NULL
*************************** 2. row ***************************
created_at: 2023-05-12 07:00:52
updated_at: 2023-05-12 07:00:58
deleted_at: NULL
id: 8752
device_name: /dev/vda
delete_on_termination: 0
snapshot_id: NULL
volume_id: 9275c580-6679-4f60-810b-06ca11ae8742
volume_size: 100
no_device: NULL
connection_info: {"driver_volume_type": "iscsi", "data": {"target_discovered": false, "target_portal": "10.10.15.12:3260", "target_iqn": "iqn.2010-10.org.openstack:volume-9275c580-6679-4f60-810b-06ca11ae8742", "target_lun": 0, "volume_id": "9275c580-6679-4f60-810b-06ca11ae8742", "auth_method": "CHAP", "auth_username": "WEXNsUK3tjc7fB7Y7NoH", "auth_password": "CHpWUeYpQTmA4UMQ", "encrypted": false, "qos_specs": null, "access_mode": "rw", "device_path": "/dev/sdi"}, "status": "reserved", "instance": "dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361", "attached_at": "", "detached_at": "", "volume_id": "9275c580-6679-4f60-810b-06ca11ae8742", "serial": "9275c580-6679-4f60-810b-06ca11ae8742"}
instance_uuid: dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361
deleted: 0
source_type: volume
destination_type: volume
guest_format: NULL
device_type: NULL
disk_bus: NULL
boot_index: NULL
image_id: NULL
tag: NULL
attachment_id: 95e2231a-919a-4a3e-8b2f-7549756fb293
uuid: 5158750e-4680-4a13-990b-6ee735087162
volume_type: NULL
2 rows in set (0.000 sec)

xml配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<domain type='kvm' id='73'>
<name>instance-00001391</name>
<uuid>dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361/disk' index='1'/>
<backingStore type='file' index='2'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/d2db90ced7b2064373138e505ea3ed5a0b6374c7'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdi' index='3'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>9275c580-6679-4f60-810b-06ca11ae8742</serial>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
...
</devices>
</domain>

将实例硬重启。

1
openstack server reboot --hard dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361

查看block_device_mapping表。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
select * from block_device_mapping where instance_uuid="dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361" \G
*************************** 1. row ***************************
created_at: 2023-05-12 06:54:05
updated_at: 2023-05-12 06:54:06
deleted_at: NULL
id: 8751
device_name: /dev/hda
delete_on_termination: 1
snapshot_id: NULL
volume_id: NULL
volume_size: NULL
no_device: 0
connection_info: NULL
instance_uuid: dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361
deleted: 0
source_type: image
destination_type: local
guest_format: NULL
device_type: disk
disk_bus: NULL
boot_index: 0
image_id: 82f524ed-4d97-445f-b527-f5299c5d0b3b
tag: NULL
attachment_id: NULL
uuid: 8e57c44d-9fb5-44d9-807d-ae4c675a1c91
volume_type: NULL
*************************** 2. row ***************************
created_at: 2023-05-12 07:00:52
updated_at: 2023-05-12 07:04:11
deleted_at: NULL
id: 8752
device_name: /dev/vda
delete_on_termination: 0
snapshot_id: NULL
volume_id: 9275c580-6679-4f60-810b-06ca11ae8742
volume_size: 100
no_device: NULL
connection_info: {"driver_volume_type": "iscsi", "data": {"target_discovered": false, "target_portal": "10.10.15.12:3260", "target_iqn": "iqn.2010-10.org.openstack:volume-9275c580-6679-4f60-810b-06ca11ae8742", "target_lun": 0, "volume_id": "9275c580-6679-4f60-810b-06ca11ae8742", "auth_method": "CHAP", "auth_username": "WEXNsUK3tjc7fB7Y7NoH", "auth_password": "CHpWUeYpQTmA4UMQ", "encrypted": false, "qos_specs": null, "access_mode": "rw", "device_path": "/dev/sdi"}, "status": "reserved", "instance": "dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361", "attached_at": "", "detached_at": "", "volume_id": "9275c580-6679-4f60-810b-06ca11ae8742", "serial": "9275c580-6679-4f60-810b-06ca11ae8742"}
instance_uuid: dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361
deleted: 0
source_type: volume
destination_type: volume
guest_format: NULL
device_type: disk
disk_bus: virtio
boot_index: NULL
image_id: NULL
tag: NULL
attachment_id: 95e2231a-919a-4a3e-8b2f-7549756fb293
uuid: 5158750e-4680-4a13-990b-6ee735087162
volume_type: NULL
2 rows in set (0.000 sec)

xml配置文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<domain type='kvm' id='74'>
<name>instance-00001391</name>
<uuid>dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/var/lib/nova/instances/dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361/disk' index='2'/>
<backingStore type='file' index='3'>
<format type='raw'/>
<source file='/var/lib/nova/instances/_base/d2db90ced7b2064373138e505ea3ed5a0b6374c7'/>
<backingStore/>
</backingStore>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdi' index='1'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>9275c580-6679-4f60-810b-06ca11ae8742</serial>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
...
</devices>
</domain>

更改block_device_mapping。

1
2
3
4
5
6
7
update block_device_mapping set boot_index=NULL where id=8751;
Query OK, 1 row affected (0.002 sec)
Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [nova]> update block_device_mapping set boot_index=0 where id=8752;
Query OK, 1 row affected (0.002 sec)
Rows matched: 1 Changed: 1 Warnings: 0

硬重启实例后,xml配置文件已修改。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<domain type='kvm' id='75'>
<name>instance-00001391</name>
<uuid>dc6ee9e7-7f0b-4e97-b0eb-087cf22c7361</uuid>
...
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native'/>
<source dev='/dev/sdi' index='1'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<serial>9275c580-6679-4f60-810b-06ca11ae8742</serial>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
...
</devices>
</domain>