From 993b165959fd79b6a0349aea964efa466b371fa2 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Fri, 3 May 2024 23:34:42 +0800 Subject: [PATCH] =?UTF-8?q?redhat:=20=E6=94=AF=E6=8C=81=E5=AE=89=E8=A3=85?= =?UTF-8?q?=20oracle=20linux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 3 +- README.md | 3 +- cloud-init.yaml | 7 ++- reinstall.bat | 2 +- reinstall.sh | 38 +++++++++++++--- trans.sh | 115 ++++++++++++++++++++++++++++++++++-------------- 6 files changed, 123 insertions(+), 45 deletions(-) diff --git a/README.en.md b/README.en.md index b04b932..346519d 100644 --- a/README.en.md +++ b/README.en.md @@ -26,7 +26,7 @@ One-click reinstallation script | Alpine | 256 MB | 1 GB | | Debian / Kali | 256 MB | 1~1.5 GB ^ | | Ubuntu | 512 MB \* | 2 GB | -| CentOS / Alma / Rocky | 512 MB \* | 5 GB | +| CentOS / Alma / Rocky / Oracle | 512 MB \* | 5 GB | | Fedora | 512 MB \* | 5 GB | | openSUSE | 512 MB \* | 5 GB | | Arch | 512 MB | 5 GB | @@ -85,6 +85,7 @@ All features can be used on both Linux and Windows. ```bash bash reinstall.sh centos 7|8|9 (8|9 for the stream version) + oracle 7|8|9 alma 8|9 rocky 8|9 fedora 38|39|40 diff --git a/README.md b/README.md index 45fe8d1..1499d11 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ | Alpine | 256 MB | 1 GB | | Debian / Kali | 256 MB | 1~1.5 GB ^ | | Ubuntu | 512 MB \* | 2 GB | -| CentOS / Alma / Rocky | 512 MB \* | 5 GB | +| CentOS / Alma / Rocky / Oracle | 512 MB \* | 5 GB | | Fedora | 512 MB \* | 5 GB | | openSUSE | 512 MB \* | 5 GB | | Arch | 512 MB | 5 GB | @@ -85,6 +85,7 @@ certutil -urlcache -f -split https://mirror.ghproxy.com/https://raw.githubuserco ```bash bash reinstall.sh centos 7|8|9 (8|9 为 stream 版本) + oracle 7|8|9 alma 8|9 rocky 8|9 fedora 38|39|40 diff --git a/cloud-init.yaml b/cloud-init.yaml index e8b43ce..729a311 100644 --- a/cloud-init.yaml +++ b/cloud-init.yaml @@ -16,8 +16,11 @@ chpasswd: password: 123@@@ type: text runcmd: - # opensuse tumbleweed 有 /etc/ssh/sshd_config.d/ 文件夹,没有 /etc/ssh/sshd_config,有/usr/etc/ssh/sshd_config - - grep 'Include.*/etc/ssh/sshd_config.d' /etc/ssh/sshd_config && mkdir -p /etc/ssh/sshd_config.d && echo "PermitRootLogin yes" >/etc/ssh/sshd_config.d/01-permitrootlogin.conf || echo "PermitRootLogin yes" >>/etc/ssh/sshd_config + # opensuse tumbleweed 镜像有 /etc/ssh/sshd_config.d/ 文件夹,没有 /etc/ssh/sshd_config,有/usr/etc/ssh/sshd_config + # opensuse tumbleweed cloud-init 直接创建并写入 /etc/ssh/sshd_config,造成默认配置丢失 + # 下面这行删除 clout-init 创建的 sshd_config + - test $(wc -l >/etc/ssh/sshd_config.d/50-cloud-init.conf && rm -f /etc/ssh/sshd_config + - echo "PermitRootLogin yes" >/etc/ssh/sshd_config.d/01-permitrootlogin.conf || sed -Ei 's/^#?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config - systemctl restart sshd || systemctl restart ssh - touch /etc/cloud/cloud-init.disabled # ubuntu 镜像运行 echo -e '\nDone' ,-e 会被显示出来 diff --git a/reinstall.bat b/reinstall.bat index ffd36fc..cbf018f 100644 --- a/reinstall.bat +++ b/reinstall.bat @@ -52,7 +52,7 @@ if not errorlevel 1 ( ) rem pkgs 改动了才重新运行 Cygwin 安装程序 -set pkgs="curl,cpio,p7zip,bind-utils,ipcalc,dos2unix,binutils" +set pkgs="curl,cpio,p7zip,bind-utils,ipcalc,dos2unix,binutils,jq" set tags=%tmp%\cygwin-installed-!pkgs! if not exist !tags! ( rem win10 arm 支持运行 x86 软件 diff --git a/reinstall.sh b/reinstall.sh index 2d03099..ef075f3 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -27,6 +27,7 @@ usage_and_exit() { fi cat <>/os/etc/yum.conf fi @@ -2132,18 +2155,37 @@ install_qcow_by_copy() { # 为 centos 7 ci 安装 NetworkManager # 1. 能够自动配置 onlink 网关 # 2. 解决 cloud-init 关闭了 ra,因为 nm 无视内核 ra 设置 - if grep 'centos:7' /os/etc/system-release-cpe; then + if grep -E 'centos:7|oracle:linux:7' /os/etc/system-release-cpe; then yum install -y NetworkManager chroot /os/ systemctl enable NetworkManager fi - # fstab 删除 boot 分区 - # alma/rocky 镜像本身有boot分区,但我们不需要 + # fstab 删除多余分区 + # alma/rocky 镜像有 boot 分区 + # oracle 镜像有 swap 分区 sed -i '/[[:space:]]\/boot[[:space:]]/d' /os/etc/fstab + sed -i '/[[:space:]]swap[[:space:]]/d' /os/etc/fstab + + # oracle linux 系统盘从 lvm 改成 uuid 挂载 + sed -i "s,/dev/mapper/vg_main-lv_root,UUID=$os_part_uuid," /os/etc/fstab + if ls /os/boot/loader/entries/*.conf 2>/dev/null; then + sed -i "s,/dev/mapper/vg_main-lv_root,UUID=$os_part_uuid," /os/boot/loader/entries/*.conf + fi + + # oracle linux 移除 lvm cmdline + if ! chroot /os command -v grubby; then + yum install grubby + fi + chroot /os grubby --update-kernel ALL --remove-args "resume rd.lvm.lv" + chroot /os grubby --update-kernel ALL --args UUID=$os_part_uuid + if [ "$releasever" -eq 7 ]; then + # el7 上面那条 grubby 命令不能设置 /etc/default/grub + sed -i 's/ rd.lvm.lv=[^ "]*//g' /os/etc/default/grub + fi # fstab 添加 efi 分区 if is_efi; then - # centos 要创建efi条目 + # centos/oracle 要创建efi条目 if ! grep /boot/efi /os/etc/fstab; then efi_part_uuid=$(lsblk /dev/$xda*1 -no UUID) echo "UUID=$efi_part_uuid /boot/efi vfat $efi_mount_opts 0 0" >>/os/etc/fstab @@ -2153,9 +2195,6 @@ install_qcow_by_copy() { sed -i '/[[:space:]]\/boot\/efi[[:space:]]/d' /os/etc/fstab fi - distro_full=$(awk -F: '{ print $3 }' /os/boot/efi/EFI/$distro_full/grub.cfg + cat </os/boot/efi/EFI/$distro_efi/grub.cfg search --no-floppy --fs-uuid --set=dev $os_part_uuid set prefix=(\$dev)/boot/grub2 export \$prefix @@ -2205,7 +2250,7 @@ EOF # 主 grub.cfg if is_efi && [ "$releasever" -le 8 ]; then - chroot /os/ grub2-mkconfig -o /boot/efi/EFI/$distro_full/grub.cfg + chroot /os/ grub2-mkconfig -o /boot/efi/EFI/$distro_efi/grub.cfg else chroot /os/ grub2-mkconfig -o /boot/grub2/grub.cfg fi @@ -2240,6 +2285,8 @@ EOF # minimal 20.04/22.04 kvm # 后台 vnc 无显示 # minimal 24.04 virtual + # debian cloud 内核不支持 ahci,ubuntu virtual 支持 + # 标记旧内核包 # 注意排除 linux-base pkgs=$(chroot $os_dir apt-mark showmanual linux-* | grep -E 'generic|virtual|kvm' | grep -v $flavor) @@ -2303,7 +2350,7 @@ EOF case "$distro" in ubuntu) modify_ubuntu ;; - *) modify_el ;; + *) modify_el_ol ;; esac # 删除installer分区,重启后cloud init会自动扩容 @@ -3161,7 +3208,7 @@ if is_use_cloud_image; then create_part download_qcow case "$distro" in - centos | alma | rocky) + centos | alma | rocky | oracle) # 这几个系统云镜像系统盘是8~9g xfs,而我们的目标是能在5g硬盘上运行,因此改成复制系统文件 install_qcow_by_copy ;;