Mar 302021
目前红帽已经不支持CentOS 6,也就导致网上的repo全部失效。这个时候,要做一个镜像,就变得比较麻烦。
DIB 已经失效,只能使用更早的版本,pip安装,所以就放弃,全部使用virt来进行定制。需要准备CentOS 6.8的repo,后续会提供。我是这CentOS 7.6 虚拟机里,进行下面的操作。
mkdir cloud-images
cd cloud-images
curl -O https://mirrors.ustc.edu.cn/centos-cloud/centos/6/images/CentOS-6-x86_64-GenericCloud-1605.qcow2
Virt
yum install libguestfs-tools-c libguestfs libguestfs-tools
必须运行这个才能正常使用,退出还需要重新运行
export LIBGUESTFS_BACKEND=direct
cp cloud-images/CentOS-6-x86_64-GenericCloud-1605.qcow2 /root/CentOS-6.8-x86.qcow2
export image_name='CentOS-6.8-x86.qcow2'
virt-customize -a $image_name --timezone "Asia/Shanghai"
virt-customize -a $image_name --edit '/etc/selinux/config:s/SELINUX=enforcing/SELINUX=disabled/'
virt-customize -a $image_name --delete "/etc/yum.repos.d/CentOS-*"
virt-customize -a $image_name --upload /root/CentOS-Base.repo:/etc/yum.repos.d/CentOS-Base.repo
virt-customize -a $image_name --upload /root/epel.repo:/etc/yum.repos.d/epel.repo
virt-customize -a $image_name --run-command 'yum clean all'
virt-customize -a $image_name --run-command 'yum makecache'
virt-customize -a $image_name --install [net-tools,wget,vim,unzip]
virt-customize -a $image_name --run-command "yum -y install qemu-guest-agent"
virt-customize -a $image_name --run-command "chkconfig qemu-ga on"
virt-customize -a $image_name --run-command 'yum -y install cloud-utils-growpart dracut-modules-growroot'
virt-customize -a $image_name --append-line '/etc/profile:alias vi=vim'
ssh相关
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/GSS/#GSS/'
virt-customize -a $image_name --edit '/etc/ssh/sshd_config:s/#UseDNS yes/UseDNS no/'
virt-customize -a $image_name --edit '/etc/cloud/cloud.cfg:s/ssh_pwauth: 0/ssh_pwauth: 1/'
virt-customize -a $image_name --edit '/etc/cloud/cloud.cfg:s/disable_root: 1/disable_root: 0/'
Cloud init
virt-customize -a $image_name --upload /etc/cloud/cloud.cfg.d/91-dib-cloud-init-datasources.cfg:/etc/cloud/cloud.cfg.d/91-dib-cloud-init-datasources.cfg
virt-customize -a $image_name --upload /etc/cloud/cloud.cfg.d/92-ec2-datasource.cfg:/etc/cloud/cloud.cfg.d/92-ec2-datasource.cfg
grub 修改
virt-customize -a $image_name --edit '/etc/grub.conf:s/serial --unit=0 --speed=115200/#serial --unit=0 --speed=115200/'
virt-customize -a $image_name --edit '/etc/grub.conf:s/terminal --timeout=1 serial console/#terminal --timeout=1 serial console/'
virt-customize -a $image_name --edit '/etc/grub.conf:s/rd_NO_DM/rd_NO_DM edd=off/'
virt-customize -a $image_name --edit '/etc/grub.conf:s/console=ttyS0,115200/ /'