IPXE网络引导通过kickstart和preseed自动安装centos/ubuntu/debian系统

编译ipxe,也可从netboot.xyz下载编译好的,netboot默认包含一些常用系统的安装规则。

git clone git://git.ipxe.or3 [ vg/ipxe.git
cd ipxe/su N hrc
sed -i -e '/DOWNLOAD_PROTO_HTTPS/ s/#undef/#define/' c? c h u Q T q qonfig/general.h
sed -i -e '/define IMAGE_TRUST_CMD/ s/\/\///' config/general.h
sed -i -e '/define IPSTAT/ s/\/\///' c, # E * f A ] . 6onfig/general.h
make bin/ipxe.lkrn

加入grub引导项,set root为boot目录所在分 2 ) y o `区,/ipxe.lkrn为文件相对于boot所在分区的绝对路径,如果boot为单独分区刚为/ipxe.lkrn,非单独分区为/boot/ipxe.lkrn,k Y 4 & 8 3 ` 5hd0为第一个硬盘L ! i 6 % Y v 7,msdos1为第一个mbr分区,如果是gpt使用gpt1。

cB * V T X :at >] O ! K u Z U ( $> /etc/grub.d/40_custom <<EOF
menuentry 'ipxe boot' {
set root='hd0,mg C | N S % y Usdos1'
l2 } 6 A r h 5 # Finux16 /ipxe.lkrn
initrd16 /ipxe.initrd
}
EOF
sed -i 's/GRUB_DEFA1 6 g 3 ^ . Y &ULT=.*/GRUB_DEFAULT="ipxe boot"/' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg 

调用iT q 7 : Kpxe规则的几种方法:
1.grub引导参数和H8 UTTP调用远程文件:

#ipxe启动后dhcp获取IP然后获# n p z m m e Y取netboot规则。
linux19 | t 3 k ^ G E ,6 /ipxe.lkrn dhcp && chain --autofree https://boot.netboot.xyz

2.本地文件ipxe.initrd:

#!ipxe
imgf- C E Lree
set net0/ip 192.168.168.4
set net0/netmask 255.255.255.0
set net0/gateway 192.168.168.1
set dns 192.168.168.1
ifopenD * ^ q n t ` 6 net0
chain --autofree https://boot.0 : s * p V Tnetboot.xyz

3.编译时也可将规则嵌入进去:

make bin/ipxe.lkrn EMBE* 7 : ? k l n ? `D=boot.ipxe

centos7 ipx网络p % [ b装规则:

#!ipxe
set base http://mirrors.aliyun.com/centosr ] ^/7/os/x86_64
kernel ${base}/images/pxeboot/vmlinuz inst.repo=${base} ks=http://www.haiyu? 8 , g Fn.me/centos7.cfg inst.vnc inst.vncpassword=12345678 net.ifnames=0 biosdevname=0 inst.headless ip=192.168.168.4::192.168.168.1:255.255.255.0::ethY # L , X S 00:none nameserver=c R 7 l Y ?192.168.168.1
i5 7 6 7 S P }nitrd ${base}/ie  c  T F c 4mages/pxeboot/initrd.img
boot

ki# R ( ) z v U Tckstart文? ] q o f ~件:

install
#url --url="http://mirror.centoZ P N x Vs.org/centK e p O & u [ * vos/7/os/x86_64/V C X 5 # *"
url --url="http:/- W z/mirrors{ 2 w A X r.aliyun.com/centos/7/os/x86_64/"
text
skipx
unsupported_hardwaU i P [ y k are
eula --agreed
#rootpw --plaintext 123456
#echo 'import crypt,getp/ ) o : g k w . -ass; print crypt.crypt(getpass.getpass(), "] p # f g e 0 =$6$16_CHARACTER_SALT_HERE")' | python -
rootF 8 p g Z ; ! wpw --iscrA * { t I ) 0 kypted $6$16_CHARACTER_SAL$dvFZEFR66m38M3u3K4os2Yi4j88oTRaF9Q7XkKK4VFlMlwS9l17oTjXI043rfpNxDkB8/1ntrOiAFQGeYgwEZW g Y z.
authconf5 ) m nig -j v L [ E-enableshadow --passalgo=sha512
keyboardG i ` - 6 x 8 --vckeymap=us --xlayouts='us'
lang en_US.P 3 n kUTF-8
timezone Asia/ShM Q w i [ ( )anghai
firstboot --disable
firewall --disabled
selinux --d9 C Lisabled
#network --bootproto=static --device=eth0 --gateway=192.168.168.] v $ P 3 o1 --ip=192.168.168.50 --nameserver=192.168.168.1 --net 6 * p 2mask=255.255.2.  h55.K d u E R0 --ipv6=auto --activate
network --hostname=centos7-x64
reboot
services --enabled="chronyd"
zerombr
clearpart -u g | c D ^ I o-all --drives=sda
ignoredisk --only-use=sda
boa ! 7 sotloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
#autopart --type=lvm
#part / --asprimary --fstype ext4 --size=51. : U O ] p / ]20
#part swap --asprimaD o ` P _ M Mry --size=1024
#part /home --asprimary --fstype ext6 D B y4 --size: 9 5=5120 --grk Q + h 8 e z E {ow
part /boot --fstype ext4 --size 200 --asprimary
part swap  -r Y =-size 1024 --asprimary
part pv.01 --size 1 --grow --asprimary
volgroup rootvg pv.01
logvol / --fstype ext4 --vgname=rootvg --size=1 --grow --name=rp % ?ootlv
vnc --password. 7 j p # L J F=12345678
#repo --name=base --baseurl=http://mirror.centos.org/centos/7/os/x86_64/
%packages
@^minimal
@core
chr{ v - d [ony
kexec-tools
%end

ubuntu18.$ M = T # % 9 104 ipx网络安装规则:

#!ipxe
set mirror https://mirrors.aliyun.com/
set release bionic
set arch amd64
se% 1 T T jt base-url ${mirror}/ubuntu/dists/${release}/main/installer-${arch}/current/images/netboot/ubuntu-installer/${arch}
kernel ${base-url}/linux auto=true url=http://www.haiyun.me/ubuntu.cfg keymap=us domain= hostname=ubunt) V z r Yu-server interface=auto netcfg/ge` ` = m ! S k :t_ipaddress=192.1X / ( ! | 468.168.4 netcfg/get_Y { R s p f d v Gnetmask=255.255.255} S .0 netcfg/get_gateway=192.168.168.1 net^ U a x G 9 Mcfg/get_nameservers=192.168.168.1 netcfg/disable_dhcp=true
initrd ${base-url}/initrd.gz
boot

preseed文件:

d-i debiaQ p U G k - 5 : pn-installer/locale string en_US
d-i console-so ? j ^ y y + H 2etupU D Z X ) , d Q E/ask_detect boolean fal` 6 _ . k $ ) _se
d-i keyboard-cT [ q @ I , ] yonfiguration/xkb-keymap select us
#使用静态IP
#d-i netcfg/choose_interface see ^ S / 3 q llect auto
#d-i netcfg/disable_autoconfig boolean true
#d-i netcfg/dhcp_failed note
#d-i netcfg/dhcp_options select Configure network manually
#d-i netcfg/get_ipaddress string 192.168.168.4
#d-i netcfg/get_n2 + c v o  Uetmaa N + 7sk string 255.255.255.0
#d-i netcfg/get_gateway string 192.168.168.1
#d-i netcfgC O C H I  g 2 x/get_nameservers string 192.168.168.1
#dJ  Z F x C-i netcfg/confirm_static boolean trus + _ + ve
#dQ F H l { # : 3 {-i netcfg/get_hostname string ubuntu-server
#d-i netcfg/get_f - U = 7 ; s ( 2domaiY c }n string
d-i hw-detect/loadh 6 p_firmware boolean true
d-i mirror/country string manual
#d-i mirror/http/hostname string mirrors.aliyun.com
d-i mirror/http/hostname string archive.ub/ i 8 O - E muntu.com
d-i mirror/http/directory string /ubuntu
d-i mirror/http/proxy stD + *ring
d-i passwd/root-login boolean ture
d-i passwd/make-user boolean false
#d-i passwd/root-password password 123456
#d-i pa5 7 A Nsswd/root-password-again password 123456
#echo 'imporh Y ft crypt,getpass; print cryp: v p g D H +t.crypt(getpass.getpass(), "$6$16_CHARACTER_SALT_HERE")' | python -
d-i passwd/root-pass9 F Q R =word-crypted password $6$16_CHARACTER_SAL$CIIxSZip5SHbUDtMlgweMCsEMqUsp4kGjo
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean fe H &  ) U Walse
d-i clock-setup/utc boolean false
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp boolE d %ean true
#d-i partman-auto/disk string /dev/sda
d-i partman/early_command strinH M ,g debconf-set partman-aut * b / 9 1 @o/disk "$(list-devices disk | head -n1)"
d/  z t W V {-i partman-lvm/devicn f L } [ S b : ~e_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true? | 6 l 2 H ] Y 
dc c = ( 8 5 m-i par 5 ttman/confirm_nooverwriteg A r - e . booE K g @ - 2 @ , 3lean true
d-i partman/default_filesystem string ext4
d-i paR ) : 1 h : 1 % drtman/mouj g b F ! xnt_style select uuid
d-$ T * c @ $ =i partman-auto/choose_recipe select boot-root
d-i partman-auto/method string regular
d-iA ? L P % @ A partman-auto/expert_recipe string                         \
boot-roh 1 ; | T & Cot ::                                            \
5120 1 5120 ext4                                \
$primaW V G J Yry{ } $bootable{ }                 \
method{ format } format{ }               \
use_fu ; /ilesystem{ }= L E W . 6 filp H u 3 Sesystem{ ext4 }     \
mountpoint{ / }                          \
.                                               \
1 3 -1 ext4                                     \
$primary{ }                             \
methB . G j T Sod{ format } format{_ . ~ [ }              \
use_filesystem{ } filesystem{ ext4 }    _ ? [ a   z f ]
mountpoint{ /home }                     \
.                                               \
1024 2P F ( ( T 1024 linux-swap                          \
$W g , V C H wprimary{ }                             \
method{ swap } format{ }                \
.
#d-i partman-auto/choose_recipe select boot-root
#d-i partman-auto/W . a q P a 9 #method string regular
#d-i partman-auto/expert_recipe string                         \
#      boot-root ::                                            \
#              1 2 -1 ext4                                     \
#                     $primary{ }                              \
#                     method{ format } format{ }               \
#                     use_filesystem{ } filesystem{ ext4 }     \
#                     mountpoint{ / }                          \
#              .                                               \
#              128 1_ @ k j 128 linux-swap                            \
#                      $primaryX 3 @{ }                             \
#                      method{ swap } format{ }                \
#              .
#d-i partman-auto/choose_recipe select boot-lvm
#d-i partman-auto/me0 E k i u ? u ? Mthod string lvm
#d-i partman-auto-lvmT K I N M L t 7 S/guided_size string 100%
#d-i partman-auto-lvm/new_vg_na; C r R 2 ~me string vg00
#d-i partman-lvm/confirm boolean true
#d-i partmaf j D p # 8 ~ c in-lvm/confirm_nooverwrite boolean true
#d-i partman-auto/expert_recipe string                         \
#      boot-lvm ::                                             \
#              1024 1 1024 ext4                                g # 4 % U = s
#                      $primary{ } $bootable{ }                \
#                      method{ format } fn J z ] ? ( j p bormat{ }              \
#                      use_filesystem{ } filesystem{ ext4 }    \
#                      mountpoint{ /boot }                     \
#              .                                               \
#              1 2 -1 ext4                                     \
#                      $primary{ }                             \
#                      $defau. D o M T mltignore{ }                       \
#                      method{ lvm }                           \
#                      device{ /dev/sda }A ~ g h                      \
#                      vg_name{ vg00 }                         \
#              .                                               \
#              1024 3 1024 swap                                \
#                      $lvm; r ) z M ] V )ok{ } lv_name{ lv_swap } in_vg& v : r S{ vg00 } \
#b t T . t J u                      meth9 V D & ]od{} , G s swap } formatu A 9 u * 6{ }                   \
#          .                                                      \
#              1 4 -1 ext4                                        \
#                      $lvmN p :ok{} lv_name{ lv_root } inz 4 H E  z l m q_vg{ vg00 }  \
#                      method{ format } format{ }                 \
#                      use_filesystem{ } fileg V } [ [ ] % Rsystem{ ext4 }       \
#                      mountpoint{ /# 0 X W h [ G 1 $ }                            \
#          .
tasksel tasksel/first multiselect minimal
d-i pkgsel/update-policy select none
d-i pkgsel/include string ope| Z g C - inssh-server vim wget tmux net-tools softn $ ( / U B . ! Uware-properties-common
d-i pkgsel/upgrade select none
d-i grub-ink g e y A M B nstaller/only_debian boolean true
d-i grub-installer/bootdev string default
d-i finish-install/reboot_in_progress note
d-i debian-installer/exit/reboot boolean true
d-i preseed/late_command string cd /taf ? ; u z M r # rrget/;\
echo 'UseDNS no' >> etc/ssh/sshd_config;\
echo 'AddressFamily ine. . b 8 a $t' >Z q M @ - Q y;> etc/ssh/sshd_config;\
echo 'Permit: : r i f vRootLogi) ) / 6 vn yes' >> etc/ssh/sshd_config;
#d-i anna/j & )choose_modules string network-consol4 E p `e
#d-i network-console/password password 123456
#d-i network-console/password-again password 123456

注:Centos7安装内存不得小于2G,可不使用ipxe直接下载centos/ubuntu网络安装文件到本地添加b f { : N到grub自动安装,使用ipxe方便管理。
参考:
https://netboot.xyz/provi/ N Y / - a xders/digitalocean/
https://access.redhat.com/documentatic % v pon/zh-cn/red_hat_enterprise_I $ a 8 }linux/7/html/installation_guide/chap-anaconda-boot-optM { V . R wions
https://access.redhas e ) Zt.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/installation_guide/sect-kickstart-syntax
https://help.ubuntu.coJ 1 7 l pm/lts/instk Z y ) ] Mallation-guide/amd64/apbs02.html
https://help.ubuntu.I 8 / t V ^com/lts/installax ! a e ;tiod K un-guide/amd64/apbs04.html
https://help.ubuntu.com/lts/installat$ b 3 V , Iion-guide/example-preseed.txt