KVM环境下使用Kickstart无法自动化安装Rocky9 Linux
KVM环境下使用Kickstart无法自动化安装Rocky9 Linux
哥们,我之前在KVM上装Rocky9的时候也踩过几乎一模一样的坑!你这情况大概率是Kickstart脚本缺了关键配置,或者启动VM时没正确传递KS文件的参数,咱一步步捋:
先揪Kickstart脚本里的致命问题
你的
clearpart命令没写完!
脚本最后是clearpart --all --initlabel...,这明显是语法不完整,必须补全成clearpart --all --initlabel --drives=vda,不然分区清理的逻辑会报错,直接把安装流程卡去手动界面。缺了
rootpw和timezone配置!
这俩是自动化安装的核心必填项,Rocky9的安装程序会强制要求设置root密码和时区,没写的话直接跳出手动交互:- 加root密码:测试环境可以用明文(别生产用!)
rootpw --plaintext yourTestPass123;生产环境先跑grub2-mkpasswd-pbkdf2生成加密串,再写rootpw --iscrypted $6$xxxxxx... - 加时区:比如国内用
timezone Asia/Shanghai --isUtc,把时区钉死就不会弹选择框了。
- 加root密码:测试环境可以用明文(别生产用!)
给你补个修正后能跑的完整KS脚本参考:
# Generated by Anaconda 34.25.4.9 # Generated by pykickstart v3.32 #version=RHEL9 # Use text mode install text repo --name="minimal" --baseurl=file:///run/install/sources/mount-0000-cdrom/minimal %addon com_redhat_kdump --enable --reserve-mb='auto' %end # System language lang en_US.UTF-8 # Use CDROM installation media cdrom # 配置root密码(测试用明文,生产请替换为加密串) rootpw --plaintext yourTestPass123 # 强制设置时区(根据自己地区改) timezone Asia/Shanghai --isUtc %packages @^minimal-environment %end # Run the Setup Agent on first boot firstboot --enable # Do not configure the X Window System skipx # Generated using Blivet version 3.6.0 ignoredisk --only-use=vda # System bootloader configuration bootloader --append="crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M" --location=mbr --boot-drive=vda autopart # 补全分区清理命令 clearpart --all --initlabel --drives=vda # 可选:根据需求设置SELinux和防火墙 selinux --enforcing firewall --enabled --service=ssh
再检查KVM启动时的参数
你启动VM的virt-install命令里,有没有明确指定Kickstart文件的位置?比如:
- 如果你的KS文件是放在宿主机本地,比如
/root/rocky9.ks,那要把它挂载成VM的额外磁盘,或者用--extra-args传递路径。举个能用的virt-install例子:
virt-install \ --name rocky9-auto \ --ram 2048 \ --vcpus 2 \ --disk path=/var/lib/libvirt/images/rocky9-auto.qcow2,size=20,bus=virtio \ --cdrom /var/lib/libvirt/images/Rocky-9.2-x86_64-minimal.iso \ --extra-args "inst.ks=file:///root/rocky9.ks" \ --network bridge=virbr0,model=virtio \ --graphics none \ --console pty,target_type=serial
这里要注意inst.ks的路径必须是VM内部能访问到的位置——如果是把KS文件塞进了自定义ISO里,路径要改成对应ISO里的位置;如果是用HTTP服务托管KS,就写inst.ks=http://[宿主机IP]/rocky9.ks。
最后总结最可能的坑
- KS脚本缺
rootpw、timezone,或者clearpart语法错误 - 启动VM时没加
--extra-args传递KS文件路径,导致VM根本没加载到自动化配置 - 没确认Rocky9的ISO镜像正确挂载到了VM的CDROM设备
先把这几点改了,应该就能自动跑完安装,不用再进控制台点来点去了!
备注:内容来源于stack exchange,提问作者user2233706
相关产品推荐
相关产品推荐

