最近更新时间:2023.09.12 17:48:10
首次发布时间:2021.07.09 13:31:09
如果您拥有所需发行版本的基础镜像,您可以参考本文制作并导入您的私有镜像到火山引擎平台。
此方式具有更高的定制化性,适用于需要复杂初始化系统镜像的场景,导入平台后,您可以使用该镜像重新部署复杂初始化系统或多次部署同样配置的云服务器。
下文制作方法支持的基础镜像操作系统及相关版本如下,支持32位/64位。
说明
制作镜像方式较多,本文只介绍使用 virt-manager 制作 qcow2 格式镜像的方法。
本节适用于没有虚拟机的用户,如果您已有虚拟机,请跳过此步骤。
配置宿主机。
宿主机操作系统的发行版无硬性要求,本文宿主机为X86架构并使用安装图形化界面(GUI)的CentOS 7.9操作系统。
egrep '(vmx|svm)' /proc/cpuinfo
vmx
或svm
表示已开启虚拟化。uname -r
安装虚拟化软件。
yum install -y qemu-kvm libvirt libvirt-python libvirt-client
systemctl start libvirtd systemctl enable libvirtd # 执行本命令可配置libvirtd服务开机自启动
systemctl status libvirtd
执行如下命令,安装virt-manager。
yum install -y virt-manager
创建启动模式为UEFI
的虚拟机时,还需完成如下配置
请执行如下命令,安装OVMF。
说明
wget --no-check-certificate http://www.kraxel.org/repos/firmware.repo
-O /etc/yum.repos.d/firmware.repo
命令,安装firmware源。X86_64
架构,若您创建其他架构虚拟机,请安装相应架构的OVMF。yum install -y edk2.git-ovmf-x64.noarch
配置libvirtd以启用UEFI。
执行如下命令,并按i
键进入编辑模式。
vim /etc/libvirt/qemu.conf
在配置文件中插入如下内容,将OVMF和运行时变量模板添加到libvirt配置中。
请将
nvram
参数中路径替换为您安装OVMF的实际路径。
nvram = [ "/usr/share/edk2.git/ovmf-x64/OVMF_CODE-pure-efi.fd:/usr/share/edk2.git/ovmf-x64/OVMF_VARS-pure-efi.fd" ]
按ecs
键,并输入:wq
保存并退出。
执行如下命令,重启libvirtd服务。
systemctl restart libvirtd
开启宿主机ip_forward功能。
执行如下命令,配置ip_forward功能。
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
执行如下命令,使配置生效。
sysctl -p
在宿主机中准备基础镜像,请使用文件系统为ext3、ext4的单分区镜像,并且不要创建任何分区,否则可能出现自动扩容或启动异常问题。
执行如下命令,打开virt-manager。
virt-manager
单击图标,开启新建虚拟机向导。
选择“Loca install media(ISO image or CDROM)”选项并单击“Forward”按钮,使用您准备的基础镜像安装虚拟机操作系统.。
单击“Browse...”按钮,打开选择窗口。
单击“Browse Local”按钮打开宿主机存储目录,选择您在宿主机中准备的基础镜像,单击“Open”按钮确认并返回新建虚拟机向导。
取消勾选“Automatically detect operating system based on install media”选项,根据使用的镜像信息自行选择“OS type”(镜像类型)与“Version”(发行版本)。
单击“Forward”按钮,配置虚拟机内存与CPU信息。
您不能分配超过宿主机系统中可用的物理处理器(或超线程)的虚拟CPU,可用的虚拟CPU数量可查看相应配置框下方
Up to X available
信息。
单击“Forward”按钮,配置创建的磁盘镜像大小。
请考虑虚拟机启用及需要在其中安装的应用程序,为其分配足够的空间。
单击“Forward”按钮,配置虚拟机名称与网络,并勾选“Customize configuration before install”。
说明
Virtual network 'default' : NAT'
,如需更改,请在“Network selection”模块下拉选择。确认虚拟机配置后,单击“Finish”按钮创建虚拟机。
在个性化定制页面中,可以配置虚拟机启动模式为UEFI
或调整虚拟机硬件配置。启动模式调整步骤如下:
UEFI
,单击“Apply”按钮即可配置虚拟机启动模式为UEFI
。跟随安装指引进入虚拟机配置页面时,需要您进入网络配置页面开启网络连接。
单击“NETWORK & HOST NAME”按钮,进入网络配置页面。
单击开启选项,确认开启网络连接后,单击左上角“Done”按钮,保存并回到个性化配置页面。
完成其他个性化配置后,单击“Continue”按钮,跟随指引完成虚拟机安装。
您需要登录创建的虚拟机,注释或删除将/etc/fstab文件中存在的数据盘目录信息。
执行如下命令,打开/etc/fstab文件。
vi /etc/fstab
按i
键进入编辑模式,并注释或删除数据盘目录信息。
按esc
键输入:wq
保存并退出编辑。
若您需要制作UEFI
启动模式的镜像,可根据本节指引登录虚拟机,修改虚拟机的启动引导文件。
在虚拟机中执行如下命令,安装grub2-efi。
CentOS镜像
yum install grub2-efi-64 && yum install grub2-efi-x64-modules
Debian/Ubuntu镜像
apt install --reinstall grub-common grub-efi-amd64
执行如下命令,以UEFI为引导重装grub。
CentOS镜像
grub2-install --target=x86_64-efi --efi-directory=/boot/efi /dev/vda grub2-install --target=x86_64-efi --removable --efi-directory=/boot/efi --bootloader-id=GRUB
Debian/Ubuntu镜像
grub-install --target=x86_64-efi --efi-directory=/boot/efi /dev/vda grub-install --target=x86_64-efi --removable --efi-directory=/boot/efi --bootloader-id=GRUB
执行如下命令,重新生成grub2-config文件。
重新生成grub2-config文件将覆盖原有配置,建议您提前备份。
CentOS镜像
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
Debian/Ubuntu镜像
grub-mkconfig -o /boot/grub/grub.cfg
执行如下命令,修改grub2-mkconfig文件配置。
Debian、Ubuntu镜像请跳过本步骤。
sed -i 's/linux16/linuxefi/g' /boot/grub2/grub.cfg sed -i 's/initrd16/initrdefi/g' /boot/grub2/grub.cfg
执行以下命令下载cloud-init 20.03 版本,建议选择 cloud-init 20.03 版本。wget https://launchpad.net/cloud-init/trunk/20.3/+download/cloud-init-20.3.tar.gz
安装Python3版本和cloud-init依赖。
说明
CentOS 7/8 系列:依次执行以下命令安装Python3和相关依赖。
yum install python3 -y yum install python3-pip -y yum install cloud-utils-growpart -y
Ubuntu/Debian 系列:依次执行以下命令安装Python3和相关依赖。
apt-get install python3 -y apt-get install python3-pip -y apt-get install cloud-guest-utils -y
安装cloud-init: 依次执行以下命令进行安装。
tar zxvf cloud-init-20.3.tar.gz ls cd cloud-init-20.3 pip3 install -r requirements.txt -i https://mirrors.volces.com/pypi/simple/ python3 setup.py build python3 setup.py install --init-system systemd ln -s /usr/local/bin/cloud-init /usr/bin/cloud-init systemctl enable cloud-init-local.service systemctl enable cloud-init.service systemctl enable cloud-config.service systemctl enable cloud-final.service
替换cloud-init 配置文件,执行vi /etc/cloud/cloud.cfg
命令,替换配置文件内的如下内容后,执行:wq
保存修改。
users: - default disable_root: 0 ssh_pwauth: 1 growpart: mode: auto devices: ['/'] ignore_growroot_disabled: false mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service', '0', '2'] resize_rootfs_tmp: /dev ssh_deletekeys: 1 syslog_fix_perms: ~ disable_vmware_customization: false manage_etc_hosts: localhost cloud_init_modules: - disk_setup - migrator - bootcmd - write-files - growpart - resizefs - set_hostname - update_hostname - update_etc_hosts - rsyslog - users-groups - ssh cloud_config_modules: - mounts - locale - set-passwords - rh_subscription - yum-add-repo - package-update-upgrade-install - timezone - puppet - chef - salt-minion - mcollective - disable-ec2-metadata - runcmd cloud_final_modules: - rightscale_userdata - scripts-per-once - scripts-per-boot - scripts-per-instance - scripts-user - ssh-authkey-fingerprints - keys-to-console - phone-home - final-message - power-state-change system_info: # distro: rhel # centos则打开此配置 paths: cloud_dir: /var/lib/cloud templates_dir: /etc/cloud/templates ssh_svcname: sshd
更换cloud-init 数据源,创建文件/etc/cloud/cloud.cfg.d/90_dpkg.cfg,并写入以下内容。
datasource_list: [ConfigDrive, OpenStack] datasource: OpenStack: metadata_urls: ["http://100.96.0.96"] max_wait: -1 timeout: 5 retries: 5 apply_network_config: True
制作弹性裸金属、通用型(g3i、g3a)、计算型(c3i、c3a)及内存型(r3i、r3a)规格实例使用的Linux镜像时,需按本节指引安装Virtio驱动。规格详情可查看实例规格介绍。
说明
通过脚本检测虚拟机中的Virtio驱动版本是否符合要求。
执行如下命令,创建脚本文件。
vim check_virtio110.sh
按i
键进入编辑模式,复制并粘贴如下内容至脚本文件。
#!/bin/bash function check_dpu_virtio110() { pkg=virtio version=1.1.0 uspath=/usr/src/$pkg-$version kernelheaderspath="/usr/include/linux" virtio110=$kernelheaderspath/"virtio_config.h" f_ring_packed_nums=$(grep "VIRTIO_F_RING_PACKED" ${virtio110}|grep 34|wc -l) if [[ -d $uspath ]] || [[ $f_ring_packed_nums -eq 1 ]] then echo "OK" else echo "FAILED" fi } check_dpu_virtio110
按esc
键,输入:wq
保存并退出文件。
执行如下命令,为脚本文件添加执行权限。
chmod u+x check_virtio110.sh
在脚本文件所在目录中,执行如下命令,检查Virtio驱动版本是否符合要求。
./check_virtio110.sh
OK
,表示您的虚拟机中已安装符合要求的Virtio驱动,请跳过本节。FAILED
,表示您的虚拟机中未安装符合要求的Virtio驱动,请继续执行本节操作。安装Virtio1.1驱动。
CentOS 7.x 64位:依次执行以下命令安装驱动。
yum -y install rpm-build redhat-lsb-core yum -y install epel-release sed -e 's!^metalink=!#metalink=!g' \ -e 's!^#baseurl=!baseurl=!g' \ -e 's!//download\.fedoraproject\.org/pub!//mirrors.ivolces.com!g' \ # 若您使用非火山引擎ECS实例制作镜像,请使用: -e 's!//download\.fedoraproject\.org/pub!/mirrors.volces.com!g' \ -i /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo yum -y install --enablerepo=epel dkms wget https://virtio11-drivers.tos-cn-beijing.volces.com/virtio_centos-7.8-7.9-v11.noarch.rpm rpm -i virtio_centos-7.8-7.9-v11.noarch.rpm rm -rf virtio_centos-7.8-7.9-v11.noarch.rpm
Ubuntu Server 18.04 LTS 64位:依次执行以下命令安装驱动。
apt install -y dkms fakeroot dh-make wget https://virtio11-drivers.tos-cn-beijing.volces.com/virtio_ubuntu-18.04-v11.tar tar xf virtio_ubuntu-18.04-v11.tar cd virtio_ubuntu-18.04-v11/ ./install.sh cd .. rm -rf virtio_ubuntu-18.04-v11*
Ubuntu Server 16.04 LTS 64位:依次执行以下命令安装驱动。
apt-get install -y dkms fakeroot dh-make wget https://virtio11-drivers.tos-cn-beijing.volces.com/virtio_ubuntu-16.04-kernel-4.4-v11.tar tar xf virtio_ubuntu-16.04-kernel-4.4-v11.tar cd virtio_ubuntu-16.04-kernel-4.4-v11 ./install.sh cd .. rm -rf virtio_ubuntu-16.04-kernel-4.4-v11*
Debian 10 64位:依次执行以下命令安装驱动。
apt install -y dkms fakeroot dh-make apt install -y linux-image-$(uname -r) apt install -y linux-headers-$(uname -r) apt install -y linux-tools wget https://virtio11-drivers.tos-cn-beijing.volces.com/virtio-dkms_1.1.0_amd64.deb dpkg -i virtio-dkms_1.1.0_amd64.deb rm -rf virtio-dkms_1.1.0_amd64.deb
添加内核启动参数。
Centos 7 系列:执行以下命令,添加内核启动参数。
sed -i 's/\(^GRUB_CMDLINE_LINUX=.*\)"/\1 pci=realloc intel_idle.max_cstate=1 processor.max_cstate=1 iommu=pt"/g' /etc/default/grub grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg dracut --force /boot/initramfs-$(uname -r).img $(uname -r)
Ubuntu/Debian 系列:执行以下命令,添加内核启动参数。
sed -i 's/\(^GRUB_CMDLINE_LINUX=.*\)"/\1 pci=realloc intel_idle.max_cstate=1 processor.max_cstate=1 iommu=pt"/g' /etc/default/grub update-grub
本节仅适用于制作弹性裸金属实例并采用LTS-内核方式使用的Linux镜像,如果您的镜像不用于该规格实例,请跳过此步骤。
说明
删除旧的virtio1.1驱动(可选)
CentOS 7.x 64位:依次执行以下命令删除已有的virtio1.1.0驱动。
# 先删除旧的virtio,如果存在 [root@xxxxxx~]# yum remove -y virtio-1.1.0-1dkms
Debian 10 64位:依次执行以下命令删除已有的virtio1.1.0驱动。
# 先删除旧的virtio,如果存在 [root@xxxxxx~]# apt remove --purge -y virtio-dkms
Ubuntu Server 16.04/18.04 64位:依次执行以下命令删除已有的virtio1.1.0驱动。
# 先删除旧的virtio,如果存在 [root@xxxxxx~]# apt remove --purge -y virtio-dkms [root@xxxxxx~]# sed -i --follow-symlinks '/v11/d' /etc/initramfs-tools/modules [root@xxxxxx~]# rm -fr /etc/initramfs-tools/scripts/init-premount/rebind.sh [root@xxxxxx~]# rm -fr /usr/share/initramfs-tools/hooks/flock
安装LTS-内核
CentOS 7.x 64位:依次执行以下命令安装LTS-内核并重启到指定版本。
LTS-4.9内核:依次执行以下命令安装LTS-内核。
[root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-rpm/kernel-4.9.324-1.x86_64.rpm [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-rpm/kernel-devel-4.9.324-1.x86_64.rpm [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-rpm/kernel-headers-4.9.324-1.x86_64.rpm [root@xxxxxx~]# yum install -y kernel-headers-4.9.324-1.x86_64.rpm kernel-devel-4.9.324-1.x86_64.rpm [root@xxxxxx~]# yum install -y kernel-4.9.324-1.x86_64.rpm
LTS-4.14内核:依次执行以下命令安装LTS-内核。
[root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-rpm/kernel-4.14.289-1.x86_64.rpm [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-rpm/kernel-devel-4.14.289-1.x86_64.rpm [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-rpm/kernel-headers-4.14.289-1.x86_64.rpm [root@xxxxxx~]# yum install -y kernel-headers-4.14.289-1.x86_64.rpm kernel-devel-4.14.289-1.x86_64.rpm [root@xxxxxx~]# yum install -y kernel-4.14.289-1.x86_64.rpm
LTS-4.19内核:依次执行以下命令安装LTS-内核。
[root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-rpm/kernel-4.19.253-1.x86_64.rpm [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-rpm/kernel-devel-4.19.253-1.x86_64.rpm [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-rpm/kernel-headers-4.19.253-1.x86_64.rpm [root@xxxxxx~]# yum install -y kernel-headers-4.19.253-1.x86_64.rpm kernel-devel-4.19.253-1.x86_64.rpm [root@xxxxxx~]# yum install -y kernel-4.19.253-1.x86_64.rpm
Centos 依次执行以下命令切换内核并重启到指定的LTS内核版本(以LTS-4.9为例)。
# 查看当前系统有几个内核. [root@xxxxxx~]# cat /boot/efi/EFI/centos/grub.cfg |grep menuentry if [ x"${feature_menuentry_id}" = xy ]; then menuentry_id_option="--id" menuentry_id_option="" export menuentry_id_option menuentry 'CentOS Linux (4.9.324) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1127.19.1.el7.x86_64-advanced-bf734ac7-0328-4e7f-8ada-ca0917a32945' { menuentry 'CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1127.19.1.el7.x86_64-advanced-bf734ac7-0328-4e7f-8ada-ca0917a32945' { menuentry 'CentOS Linux (0-rescue-ccc58c7f32cb4030969ada15e4ae0d0f) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-ccc58c7f32cb4030969ada15e4ae0d0f-advanced-bf734ac7-0328-4e7f-8ada-ca0917a32945' { # 设置默认的启动内核。 #比如我们选择上一步回显中的“CentOS Linux (4.9.324) 7 (Core)”内核为默认启动。 [root@xxxxxx~]# grub2-set-default "CentOS Linux (4.9.324) 7 (Core)" # 查看默认启动的系统内核。 [root@xxxxxx~]# grub2-editenv list saved_entry=CentOS Linux (4.9.324) 7 (Core) # 重启之后使用uname -r可以查看当前的系统内核。 [root@xxxxxx~]# reboot [root@xxxxxx~]# uname -r 4.9.324
Debian 10 64位:依次执行以下命令安装LTS-内核并重启到指定版本。
[root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-deb/linux-image-4.9.324_4.9.324-1_amd64.deb [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-deb/linux-headers-4.9.324_4.9.324-1_amd64.deb [root@xxxxxx~]# apt install -y ./linux*4.9*.deb
[root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-deb/linux-image-4.14.289_4.14.289-1_amd64.deb [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-deb/linux-headers-4.14.289_4.14.289-1_amd64.deb [root@xxxxxx~]# apt install -y ./linux*4.14*.deb
[root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-deb/linux-image-4.19.253_4.19.253-1_amd64.deb [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/lts-deb/linux-headers-4.19.253_4.19.253-1_amd64.deb [root@xxxxxx~]# apt install -y ./linux*4.19*.deb
# 查看当前系统有几个内核. [root@xxxxxx~]# cat /boot/grub/grub.cfg | grep menuentry if [ x"${feature_menuentry_id}" = xy ]; then menuentry_id_option="--id" menuentry_id_option="" export menuentry_id_option menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-8b9ce818-459e-4024-83f6-a5165ae179f2' { submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option 'gnulinux-advanced-8b9ce818-459e-4024-83f6-a5165ae179f2' { menuentry 'Debian GNU/Linux, with Linux 4.19.0-18-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.19.0-18-amd64-advanced-8b9ce818-459e-4024-83f6-a5165ae179f2' { menuentry 'Debian GNU/Linux, with Linux 4.9.324' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.324-advanced-8b9ce818-459e-4024-83f6-a5165ae179f2' { menuentry 'System setup' $menuentry_id_option 'uefi-firmware' { # 设置默认的启动内核。 #比如我们选择上一步回显中的'Debian GNU/Linux, with Linux 4.9.324'内核为默认启动 [root@xxxxxx~]# vim /etc/default/grub GRUB_DEFAULT=0 修改为 GRUB_DEFAULT="Advanced options for Debian GNU/Linux>Debian GNU/Linux, with Linux 4.9.324" 其中Advanced options for Debian GNU/Linux是一级菜单,Debian GNU/Linux, with Linux 4.9.324是二级菜单,两者之间用>连接。 # 更新grub文件 [root@xxxxxx~]# update-grub # 重启之后使用uname -r可以查看当前的系统内核。 [root@xxxxxx~]# reboot [root@xxxxxx~]# uname -r 4.9.324
Ubuntu Server 16.04/18.04 64位:依次执行以下命令安装LTS-内核并重启到指定版本。
LTS-4.x内核:参考上篇 Debian 10 64位 安装方式
Ubuntu Server 依次执行以下命令切换内核并重启到指定的LTS内核版本(以LTS-4.9为例)。
# 查看当前系统有几个内核. [root@xxxxxx~]# cat /boot/grub/grub.cfg | grep menuentry if [ x"${feature_menuentry_id}" = xy ]; then menuentry_id_option="--id" menuentry_id_option="" export menuentry_id_option menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-832b0bb8-00f9-41b6-9d0d-8387e07a4f8c' { submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-832b0bb8-00f9-41b6-9d0d-8387e07a4f8c' { menuentry 'Ubuntu, with Linux 4.15.0-174-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-174-generic-advanced-832b0bb8-00f9-41b6-9d0d-8387e07a4f8c' { menuentry 'Ubuntu, with Linux 4.9.324' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.9.324-advanced-832b0bb8-00f9-41b6-9d0d-8387e07a4f8c' { menuentry 'System setup' $menuentry_id_option 'uefi-firmware' { # 设置默认的启动内核。 比如我们选择上一步回显中的'Ubuntu, with Linux 4.9.324'内核为默认启动 [root@xxxxxx~]# vim /etc/default/grub GRUB_DEFAULT=0 修改为 GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.9.324" 其中Advanced options for Ubuntu是一级菜单,Ubuntu, with Linux 4.9.324是二级菜单,两者之间用>连接。 # 更新grub文件 [root@xxxxxx~]# update-grub # 重启之后使用uname -r可以查看当前的系统内核。 [root@xxxxxx~]# reboot [root@xxxxxx~]# uname -r 4.9.324
安装LTS-Virtio1.1驱动,前提是已经成功切换到LTS-内核版本
安装依赖的dkms包工具。
CentOS 7.x 64位:依次执行以下命令安装dkms。
# 安装dkms工具 [root@xxxxxx~]# yum -y install rpm-build redhat-lsb-core [root@xxxxxx~]# yum -y install epel-release [root@xxxxxx~]# sed -e 's!^metalink=!#metalink=!g' \ -e 's!^#baseurl=!baseurl=!g' \ -e 's!//download\.fedoraproject\.org/pub!//mirrors.ivolces.com!g' \ # 若您使用非火山引擎ECS实例制作镜像,请使用: -e 's!//download\.fedoraproject\.org/pub!/mirrors.volces.com!g' \ -i /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo [root@xxxxxx~]# yum -y install --enablerepo=epel dkms
Debian 10 64位:依次执行以下命令安装dkms。
# 安装dkms工具 [root@xxxxxx~]# apt install -y dkms fakeroot dh-make
Ubuntu Server 16.04/18.04 64位:依次执行以下命令安装dkms。
# 安装dkms工具 [root@xxxxxx~]# apt install -y dkms fakeroot dh-make
安装LTS-Virtio1.1驱动,依次执行以下命令安装驱动。
# 下载适配LTS的virtio1.1 dkms包 [root@xxxxxx~]# wget https://virtio11-drivers.tos-cn-beijing.volces.com/virtio-1.1.0.dkms.tar.gz # 安装 [root@xxxxxx~]# dkms ldtarball virtio-1.1.0.dkms.tar.gz [root@xxxxxx~]# dkms build virtio/1.1.0 [root@xxxxxx~]# dkms install virtio/1.1.0
添加内核启动参数。
Centos 7/8 系列:执行以下命令,添加内核启动参数。
sed -i 's/\(^GRUB_CMDLINE_LINUX=.*\)"/\1 pci=realloc intel_idle.max_cstate=1 processor.max_cstate=1 iommu=pt"/g' /etc/default/grub grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg dracut --force /boot/initramfs-$(uname -r).img $(uname -r)
Ubuntu/Debian 系列:执行以下命令,添加内核启动参数。
sed -i 's/\(^GRUB_CMDLINE_LINUX=.*\)"/\1 pci=realloc intel_idle.max_cstate=1 processor.max_cstate=1 iommu=pt"/g' /etc/default/grub update-grub
如需使用网卡Offload特性,请在虚拟机上安装MLNX驱动,操作详情可查看Linux Drivers。
说明
若您使用支持网卡Offload特性的规格(例如GPU计算型gni2),需要安装MLNX驱动。
为实现用于重置、绑定/解绑密码功能,您制作的自定义镜像必须安装密码插件,否则可能导致镜像无法正常使用。安装操作可查看安装密码插件。
您还可以为自定义镜像安装云监控插件,从实例内部进行监控,以获取更深层、更准确的实例运行情况。安装操作可查看安装插件。
您可以按照业务的需求,自行将个性化软件安装在系统盘中,例如JDK、Linux图形化桌面。
您可以在虚拟机中运行自定义镜像规范检测工具,检测当前操作系统各项配置是否符合创建云服务器实例规范,避免通过自定义镜像创建出功能不齐全的实例,操作详情可查看使用工具检测自定义镜像规范。
在虚拟机界面顶部选择“Virtual Machine > Shut Down > Shut Down”关闭虚拟机。
在宿主机中执行如下命令,打开存放镜像的文件夹,通过虚拟机名称即可查看镜像文件。
xdg-open /var/lib/libvirt/images/
说明
目前仅支持上传qcow2或者raw两种格式的镜像,如果镜像不满足以下两种格式,则需要在宿主机中执行如下命令将镜像格式进行转换。
qemu-img convert -f raw -O qcow2 ${image} ${image}.qcow2
参数说明:
-f
: 指定镜像源格式-O
: 指定镜像转换后格式您可以将创建的镜像文件上传至火山引擎作为自定义镜像,上传成功后,即可使用该镜像创建实例,操作详情可查看导入自定义镜像。