RFO SIG:openEuler AWS AMI 制作详解

本文详细介绍了如何通过AWS CLI创建openEuler与Rancher兼容的云原生AMI镜像,包括调整分区、使用cloud-init配置自动启动RKE2集群,以及后续的Base AMI和Packer配置。重点在于解决ARM架构的网络问题与内核模块编译。

作者简介

王瀚兴,SUSE 软件工程师,主要负责 Rancher 产品线相关的研发工作。

欧拉开源社区的 RFO SIG 正在努力将 openEuler 与 Rancher 整合,以推动社区的云原生版图发展。而 openEuler 如何在云环境开箱即用是一个非常重要的基础,承接上篇文章,本篇将主要介绍 openEuler AWS AMI 镜像制作的详细过程。

通过创建 AWS AMI 镜像可将 openEuler 与 AWS 云服务相结合,支持云环境中标准的 ssh key注入、分区扩容、用户数据执行等功能,并使用 cloud-init 机制实现自动启动 Rancher RKE2 集群。今后,openEuler Cloud Images 的工作也将成为 RFO SIG 的一部分,逐步扩展支持更多的云平台。

调整硬盘分区大小

openEuler 官方提供的 qcow2 格式的镜像为一个总磁盘大小为 40G 的虚拟机镜像,在 qemu 中启动虚拟机,查看分区情况。

在这里插入图片描述

可以看到磁盘含有两个分区,其中 2G 为 boot 分区,38G 为 root 分区。

使用 Net Based Disk (NBD) 将 qcow2 镜像的分区加载到 Linux 系统中,之后使用 resize2fs 压缩 ext4 文件系统的体积,并使用分区调整工具 fdisk 调整分区的大小。

# 加载 NBD 内核模块
$ sudo modprobe nbd max_part=3
# 加载 qcow2 镜像中的分区至系统
sudo qemu-nbd -c "/dev/nbd0" "openEuler-22.03-LTS-x86_64.qcow2"
$ lsblk
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nbd0          43:0    0   40G  0 disk
|-nbd0p1      43:1    0    2G  0 part
|-nbd0p2      43:2    0   38G  0 part

# 调整 ext4 文件系统大小至6G
$ sudo resize2fs /dev/nbd0p2 6G
# 使用fdisk调整分区大小至6G
$ sudo fdisk /dev/nbd0

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (2-4, default 2): 2
First sector (4194304-83886079, default 4194304):
Last sector, +/-sectors or +/-size{
   
   K,M,G,T,P} (4194304-83886079, default 83886079): +6G

Created a new partition 2 of type 'Linux' and of size 6 GiB.
Partition 2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# 从系统中卸载 qcow2 镜像的分区
$ sudo qemu-nbd -d /dev/nbd0

之后使用 qemu-img 将 qcow2 镜像缩小至8G,并转换为 RAW 格式。

$ qemu-img resize openEuler-22.03-LTS-x86_64.qcow2 --shrink 8G
$ qemu-img convert openEuler-22.03-LTS-x86_64.qcow2 openEuler-22.03-LTS-x86_64.raw

Snapshot 和 Base AMI 的创建

首先使用 awscli 提供的工具,将 RAW 镜像上传至 AWS S3 bucket 中。

$ aws s3 cp openEuler-22.03-LTS-x86_64.raw s3://${BUCKET_NAME}/

创建 vmimport policy 和 role policy。

$ cat <<
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

openEuler社区

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值