CentOS无人值守U盘安装(丢掉你的键盘鼠标)

CentOS默认镜像安装时使用界面模式,但有些情况下确实缺少鼠标键盘设备无法方便的进行安装,现放出kickstart工具的完整ks.cfg以及isolinux.cfg文件,请各位随时取用!针对EFI模式补充EFI配置文件支持BIOS以及EFI两种模式。

#ks.cfg
#
# Kickstart file automatically generated by anaconda

# Install, not upgrade
install

cdrom

# enable graphical
#graphical
text

firstboot --disable

ignoredisk --only-use=sda

network --bootproto=static --ip=192.168.0.2 --netmask=255.255.255.0 --gateway=192.168.0.1 --device=enp2s0
network  --hostname=localhost

selinux --disabled
firewall --enable

# Language and keyboard setup
lang en_US.UTF-8
keyboard --vckeymap=us --xlayouts='us'
timezone Asia/Shanghai

# Authentication
rootpw --iscrypted "$6$ABpaQUbGYJ/HrXhi$NkyGvseLANvE4A2mzgmnuMkycU6Kl9BFxL5NetzUyoYwVT8i.0CLJVokllm.ktDag4ZVpFMBcLAO5wHPAdaQX/"

# Setting partitions
zerombr
clearpart --all --initlabel --drives=sda
#autopart --type=lvm

part /boot --fstype xfs --size=1024
part pv.01 --size=1 --grow
volgroup localhost pv.01
logvol / --vgname=localhost --size=102400 --name=root 
logvol /home --vgname=localhost --size=51200 --name=home
logvol swap --vgname=localhost --size=4096  --name=swap
logvol /var --fstype ext4 --vgname=localhost --size=1 --grow --name=var

#part /boot    --onpart=/dev/sda1
#part /    --onpart=/dev/sda3
#part /home    --onpart=/dev/sda4
#part /var    --onpart=/dev/sda5
#part swap    --onpart=/dev/sda6

bootloader --timeout=5 --append="console=tty0 console=ttyS0,9600" --append=" crashkernel=auto" --location=mbr --boot-drive=sda

# Shutdown when the kickstart is done
#reboot --eject
poweroff

# 指定要安装的软件包
# 默认
%packages 
@core

%end
 
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end

%pre
#dd if=/dev/zero of=/dev/sda bs=512 count=1
#parted -s /dev/sda mklabel msdos
#TOTAL=`parted -s /dev/sda unit mb print free | grep Free | awk '{print $3}' | cut -d "M" -f1`

#let SWAP_START=$TOTAL-2048
#let ROOT_START=$SWAP_START-102400
#let HOME_START=$ROOT_START-51200

#parted -s /dev/sda mkpart primary xfs 0 2048
#parted -s /dev/sda mkpart extended 2048 $TOTAL
#parted -s /dev/sda mkpart logical xfs 2048 $HOME_START
#parted -s /dev/sda mkpart logical xfs $HOME_START $ROOT_START
#parted -s /dev/sda mkpart logical xfs $ROOT_START $SWAP_START
#parted -s /dev/sda mkpart logical $SWAP_START $TOTAL

%end

%post --nochroot
# 复制安装光盘plus目录下所有内容到系统/mnt目录下
mkdir -p /mnt/sysimage/var/plus
\cp -fr /mnt/install/repo/plus/* /mnt/sysimage/var/plus/
\cp -fr /mnt/install/repo/Packages /mnt/sysimage/var/plus/
\cp -fr /mnt/install/repo/repodata /mnt/sysimage/var/plus/
# 复制安装光盘plus/init.sh文件到系统/root目录下 作为初始化执行脚本
\cp /mnt/install/repo/plus/init.sh /mnt/sysimage/root/
#chmod 777 /mnt/sysimage/etc/rc.d/rc.local
echo 'if [[ ! -e "/etc/.console-end" ]];then' >> /mnt/sysimage/etc/rc.local
echo '    /var/plus/remkgrub.sh &' >> /mnt/sysimage/etc/rc.local
echo 'fi' >> /mnt/sysimage/etc/rc.local
echo 'ldconfig' >> /mnt/sysimage/etc/rc.local
echo '/usr/local/openssh/sbin/sshd' >> /mnt/sysimage/etc/rc.local
chmod 777 /mnt/sysimage/etc/rc.local

tar zxvfp /mnt/sysimage/var/plus/openssh.tar.gz -C /mnt/sysimage/usr/local/
tar zxvfp /mnt/sysimage/var/plus/openssl.tar.gz -C /mnt/sysimage/usr/local/
tar zxvfp /mnt/sysimage/var/plus/zlib.tar.gz -C /mnt/sysimage/usr/local/

mv /mnt/sysimage/etc/ssh/sshd_config /mnt/sysimage/etc/ssh/sshd_config.bak
mv /mnt/sysimage/usr/sbin/sshd /mnt/sysimage/usr/sbin/sshd.bak
mv /mnt/sysimage/usr/bin/ssh /mnt/sysimage/usr/bin/ssh.bak
mv /mnt/sysimage/usr/bin/ssh-keygen /mnt/sysimage/usr/bin/ssh-keygen.bak
mv /mnt/sysimage/usr/bin/scp /mnt/sysimage/usr/bin/scp.bak
mv /mnt/sysimage/usr/bin/sftp /mnt/sysimage/usr/bin/sftp.bak
rm -f /mnt/sysimage/usr/libexec/openssh/*
chmod 600 /mnt/sysimage/etc/ssh/*key
chmod 600 /mnt/sysimage/usr/local/openssh/etc/*key

echo "export PATH=\$PATH:/usr/local/openssh/bin" >> /mnt/sysimage/etc/profile
echo "export PATH=\$PATH:/usr/local/openssh/sbin" >> /mnt/sysimage/etc/profile
echo "export PATH=\$PATH:/usr/local/openssl/bin" >> /mnt/sysimage/etc/profile
echo "export PATH=\$PATH:/usr/local/bin" >> /mnt/sysimage/etc/profile

echo "/usr/local/openssl/lib" >> /mnt/sysimage/etc/ld.so.conf
sed -i 's/enforcing/disabled/g' /mnt/sysimage/etc/selinux/config

%end
#isolinux.cfg
default vesamenu.c32
timeout 6

#display boot.msg

menu clear
menu background splash.png
menu title GoldOS
menu vshift 8
menu rows 18
menu margin 8
menu helpmsgrow 15
menu tabmsgrow 13

# Border Area
menu color border * #00000000 #00000000 none

# Selected item
menu color sel 0 #ffffffff #00000000 none

# Title bar
menu color title 0 #ff7ba3d0 #00000000 none

# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

# Help text
menu color help 0 #ffffffff #00000000 none

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label linux
  menu label ^Install MyOS
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.ks=hd:LABEL=MyOS:/isolinux/ks.cfg  inst.stage2=hd:LABEL=MyOS quiet

#label check
#  menu label Test this ^media & install CentOS 7
#  menu default
#  kernel vmlinuz
#  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet

menu separator # insert an empty line

# utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting

label vesa
  menu indent count 5
  menu label Install CentOS 7 in ^basic graphics mode
  text help
	Try this option out if you're having trouble installing
	CentOS 7.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet

label rescue
  menu indent count 5
  menu label ^Rescue a CentOS system
  text help
	If the system will not boot, this lets you access files
	and edit config files to try to get it booting again.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet

label memtest
  menu label Run a ^memory test
  text help
	If your system is having issues, a problem with your
	system's memory may be the cause. Use this utility to
	see if the memory is working correctly.
  endtext
  kernel memtest

menu separator # insert an empty line

label local
  menu label Boot from ^local drive
  localboot 0xffff

menu separator # insert an empty line
menu separator # insert an empty line

label returntomain
  menu label Return to ^main menu
  menu exit

menu end
#EFI模式的grub.cfg
set default="1"

function load_video {
  insmod efi_gop
  insmod efi_uga
  insmod video_bochs
  insmod video_cirrus
  insmod all_video
}

load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2

set timeout=6
### END /etc/grub.d/00_header ###

search --no-floppy --set=root -l 'MYOS'

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install MYOS' --class fedora --class gnu-linux --class gnu --class os {
	linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=MYOS inst.ks=hd:LABEL=MYOS:/isolinux/ks.cfg quiet
	initrdefi /images/pxeboot/initrd.img
}
#menuentry 'Test this media & install CentOS 7' --class fedora --class gnu-linux --class gnu --class os {
#	linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
#	initrdefi /images/pxeboot/initrd.img
#}
#submenu 'Troubleshooting -->' {
#	menuentry 'Install CentOS 7 in basic graphics mode' --class fedora --class gnu-linux --class gnu --class os {
#		linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet
#		initrdefi /images/pxeboot/initrd.img
#	}
#	menuentry 'Rescue a CentOS system' --class fedora --class gnu-linux --class gnu --class os {
#		linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet
#		initrdefi /images/pxeboot/initrd.img
#	}
#}

Guess you like

Origin blog.csdn.net/afk_02/article/details/118157380