Ventoy 自动安装Ubuntu22.04和Rockylinux9.6操作系统配置说明

Ventoy是一个制作可启动U盘的开源工具 官方: https://www.ventoy.net/

本次使用的功能

1 使用单个u盘能安装多个操作系统,不需要使用rufus单个烧录 大道至简(本次15GU盘)
2 使用主题插件 自定义(装X用)
3 使用 自定义菜单插件 显示清晰明了
4 使用 菜单别名插件   显示清晰明了
4 使用 自动安装插件   无人值守
5 使用 启动配置替换插件 网卡命名为eht0

u盘制作步骤

1 下载ventoy-1.1.07-windows.zip 解压到自定义目录
2 插入u盘,打开Ventoy2Disk.exe 选择对应的u盘,启动烧录
3 制作完成后U盘显示为空(有用的部分隐藏了无需多问)
4 创建目录,目录结构如下
    /iso  存放镜像 和 启动配置替换文件
        1 下载Ubuntu22.04.5-server.iso 和rockylinux9.6-mini.iso到 /iso目录
        2 重命名为 u220405.iso和r96-mini.iso
        3 从r96-mini.iso镜像中提取文件/boot/grub/grub.cfg重名为:r96-mini-new-isolinux.cfg
            添加 net.ifnames=0 biosdevname=0
            例如: linux	/casper/vmlinuz net.ifnames=0 biosdevname=0 ---
        4 从u220405.iso镜像中提取文件/isolinux/isoliunx.cfg重命名为:u220405-new-grub.cfg
            添加 net.ifnames=0 biosdevname=0
            例如: append initrd=initrd.img inst.stage2=hd:LABEL=Rocky-9-6-x86_64-dvd net.ifnames=0 biosdevname=0 quiet
    /theme/Cyber-Security  主题文件
        自行下载 无需修改 https://www.gnome-look.org/p/1276072
    /ventoy/  存放主配置文件 和 自动应答文件:ks user-data
        1 meta-data        ubuntu22.04应答文件
        2 user-data        ubuntu22.04应答文件
        3 ks-r96-mini.cfg  rockylinux 应答ks文件
        4 ventoy.json      ventoy主配制文件
    

ubuntu 应答文件

1 meta-data

instance-id: kcadmin-ubuntu
local-hostname: kcadmin

2 user-data

#cloud-config
autoinstall:
  version: 1
  source:
    id: ubuntu-server
    search_drivers: false
  locale: en_US.UTF-8
  keyboard:
    layout: us
  timezone: Asia/Shanghai
  kernel:
    package: linux-generic
  apt:
    fallback: offline-install
    mirror-selection:
      primary:
      - arches: [amd64]
        uri: http://mirrors.aliyun.com/ubuntu/
      - arches: [arm64]
        uri: http://mirrors.aliyun.com/ubuntu-ports
    preserve_sources_list: false
  network:
    version: 2
    ethernets:
      eth0:
        match:
          name: "en*"
        set-name: eth0
        dhcp4: false
        dhcp6: false
        addresses:
          - 192.168.168.168/24
        routes:
        - to: default
          via: 192.168.168.254
        nameservers:
          addresses: [8.8.8.8, 114.114.114.114]
  identity:
    username: kcadmin
    hostname: u240403-node01
    password: $6$BPMly4e2Ib2FzkO9$o0jpeycyeUILqk.i4dNigLNCuW/vq1QOIAMzsl6YkBZQXO0KOI.eDrqk7l9YTw/eq2Jf2gzI3u5LcpjfNj.O21
  ssh:
    allow-pw: true
    install-server: true
  storage:
    layout:
      name: direct
  updates: security
  codecs:
    install: false
  drivers:
    install: false
  late-commands:
    - echo "Autoinstall completed on $(date)" >> /target/root/install.log
    - curtin in-target --target=/target -- systemctl disable ufw
    - curtin in-target --target=/target -- systemctl stop ufw
    - curtin in-target --target=/target -- bash -c "echo 'root:Kc@123456' | chpasswd"
    - curtin in-target --target=/target -- sed -i 's/^#\?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
    - curtin in-target --target=/target -- sed -i 's/^#\?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
    - curtin in-target --target=/target -- systemctl restart ssh
    - curtin in-target --target=/target -- bash -c "ulimit -n 655360"
    - curtin in-target --target=/target -- bash -c "printf '%s\n' '* hard nproc 655360' '* hard nofile 655360' 'root soft nproc 655360' 'root hard nofile 655360' >> /etc/security/limits.conf"
    - curtin in-target --target=/target -- bash -c "printf '%s\n' 'fs.file-max = 655350' 'net.core.somaxconn = 2048' 'net.core.rmem_max = 819200000' 'vm.overcommit_memory = 1' 'vm.swappiness = 0' 'vm.zone_reclaim_mode = 0' >> /etc/sysctl.conf"
    - curtin in-target --target=/target -- sysctl -p

Rockylinux 应答文件 ks.cfg

3 ks-r96-mini.cfg

#version=RHEL9
url --url=file:///run/install/repo
firstboot --disable
text
lang en_US.UTF-8
keyboard --vckeymap=us --xlayouts='us'
network --bootproto=static --device=eth0 --ip=192.168.168.168 --gateway=192.168.168.254 --nameserver=8.8.8.8 --netmask=255.255.255.0 --noipv6 --activate
timezone Asia/Shanghai --utc

%pre
DISK=$(lsblk -ndo NAME,TYPE | awk '$2=="disk"{print $1}' | head -n1)
echo "Detected disk: $DISK" > /tmp/disk.log
echo "ignoredisk --only-use=$DISK" > /tmp/part-include
echo "bootloader --location=mbr --boot-drive=$DISK" >> /tmp/part-include
echo "zerombr" >> /tmp/part-include
echo "clearpart --all --initlabel" >> /tmp/part-include
echo "part /boot --fstype=xfs --ondisk=$DISK --size=1024" >> /tmp/part-include
echo "part swap --fstype=swap --ondisk=$DISK --size=2048" >> /tmp/part-include
echo "part / --fstype=xfs --ondisk=$DISK --size=17000 --grow" >> /tmp/part-include
%end
%include /tmp/part-include

eula --agreed
rootpw --plaintext "Kc@123456"
firewall --disabled
selinux  --disabled
reboot
%packages
@^minimal-environment
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end

%post --interpreter /bin/bash
sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/#PermitEmptyPasswords.*/PermitEmptyPasswords no/' /etc/ssh/sshd_config
systemctl restart sshd
cat >/etc/security/limits.d/99-custom-limits.conf <<EOF
* soft nofile 65536
* hard nofile 131072
* soft nproc 65536
* hard nproc 131072
EOF
cat >/etc/sysctl.d/99-custom-sysctl.conf <<EOF
fs.file-max = 2097152
vm.swappiness = 10
net.core.somaxconn = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_forward = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
EOF
sysctl --system
%end

4 ventoy.json

{
    "control":[
        { "VTOY_DEFAULT_MENU_MODE": "1" },
        { "VTOY_MENU_LANGUAGE": "zh_CN" },
        { "VTOY_DEFAULT_SEARCH_ROOT": "/iso" }
    ],
    "theme":{
        "file": "/theme/Cyber-Security/theme.txt",
        "fonts":[
            "/theme/Cyber-Security/dejavu_12.pf2"
        ]
    },
    "menu_alias":[
        {
            "image": "/iso/u220405.iso",
            "alias": "Ubuntu 22.04.5 Server"
        },
        {
            "image": "/iso/r96-mini.iso",
            "alias": "Rockylinux 9.6 mini"
        }
    ],
    "auto_install":[
        {
            "image": "/iso/u220405.iso",
            "template":[
                "/ventoy/user-data"
            ]
        },
        {
            "image": "/iso/r96-mini.iso",
            "template":[
                "/ventoy/ks-r96-mini.cfg"
            ]
        }
    ],
    "conf_replace":[
        {
            "iso": "/iso/r96-mini.iso",
            "org": "/isolinux/isolinux.cfg",
            "new": "/iso/r96-mini-new-isolinux.cfg"
        },
        {
            "iso": "/iso/u220405.iso",
            "org": "/boot/grub/grub.cfg",
            "new": "/iso/u220405-new-grub.cfg"
        }
    ]
}

注意事项

1 登录系统  root / Kc@123456
2 测试机单块磁盘容量大于U盘容量 如20G > 15G u盘
3 测试机磁盘如果是raid 或 多块磁盘 请自行测试解决
4 配置了默认静态IP 192.168.168.168
5 应答文件中做了简单系统优化

posted on 2025-09-02 13:27  luokeli  阅读(152)  评论(0)    收藏  举报

导航