pxe/service-install.sh

raw link view readme
1 yum install firewalld -y
2 systemctl start firewalld
3 systemctl enable firewalld
4 firewall-cmd --permanent --add-interface=eth0 --zone=public
5 firewall-cmd --permanent --add-interface=eth1 --zone=internal
6 firewall-cmd --permanent --add-service=ftp --zone=internal
7 firewall-cmd --permanent --add-service=dhcp --zone=internal
8 firewall-cmd --permanent --add-service=tftp --zone=internal
9 firewall-cmd --reload
10
11 yum install dhcp -y
12
13 export PUBLIC_IP=$(ip addr show eth1 | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
14
15 cat > /etc/dhcp/dhcpd.conf << EOF
16 default-lease-time 86400;
17 max-lease-time 86400;
18 ddns-update-style none;
19 authoritative;
20 log-facility local4;
21 subnet 10.18.0.0 netmask 255.255.0.0 {
22 range 10.18.0.50 10.18.0.200;
23 next-server $PUBLIC_IP;
24 filename "pxelinux.0";
25 }
26 EOF
27
28 systemctl start dhcpd
29 systemctl enable dhcpd
30
31 yum install dhcp tftp tftp-server syslinux -y
32
33 cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
34 cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot
35
36 mkdir /var/lib/tftpboot/pxelinux.cfg
37 cat > /var/lib/tftpboot/pxelinux.cfg/default <
38 default menu.c32
39 prompt 0
40 timeout 1000
41 ontimeout local
42 menu title Install Boot Menu
43
44 label local
45 menu label Boot from local disk
46 localboot 0
47
48 label install
49 menu label Install CentOS 7.2 (Manual)
50 kernel vmlinuz
51 append initrd=initrd.img ip=dhcp repo=ftp://$PUBLIC_IP/pub/centos72
52
53 label install
54 menu label Install CentOS 7.2 (Automated)
55 kernel vmlinuz
56 append initrd=initrd.img ip=dhcp ks=ftp://$PUBLIC_IP/pub/centos72/install.ks
57 EOF
58
59 yum install vsftpd -y
60
61 systemctl start vsftpd
62 systemctl enable vsftpd
63
64 mkdir -p /mnt/cdrom
65 mount /dev/sr0 /mnt/cdrom
66 cp /mnt/cdrom/isolinux/vmlinuz /var/lib/tftpboot
67 cp /mnt/cdrom/isolinux/initrd.img /var/lib/tftpboot
68 mkdir /var/ftp/pub/centos72
69 cp -R /mnt/cdrom/* /var/ftp/pub/centos72
70 umount /dev/sr0
71
72 chmod -R 755 /var/ftp/pub
73
74 systemctl start tftp.socket
75 systemctl enable tftp.socket
76
77 cat > /var/ftp/pub/centos72/install.ks << EOF
78 auth --enableshadow --passalgo=sha512
79
80 install
81 url --url="ftp://$PUBLIC_IP/pub/centos72"
82
83 text
84 firstboot --disable
85 ignoredisk --only-use=sda
86
87 keyboard --vckeymap=us --xlayouts='us'
88 lang en_US.UTF-8
89
90 network --bootproto=dhcp --device=eth0 --onboot=off --ipv6=auto
91 network --hostname=beta.example.com
92
93 #password is taco
94 rootpw --iscrypted $6$E5x7fvTe$QwzinizmEoejxnChGh2ue5euXWfDfNIjHTN5MYBYjxa3eh0nOkMaHjJClb.jjTvSwlEFySit6vw/DXAl5gcLl.
95
96 services --disabled="chronyd"
97
98 timezone America/Chicago --isUtc --nontp
99
100 user --groups=wheel --name=dbetz --password=$6$E5x7fvTe$QwzinizmEoejxnChGh2ue5euXWfDfNIjHTN5MYBYjxa3eh0nOkMaHjJClb.jjTvSwlEFySit6vw/DXAl5gcLl. --iscrypted --gecos="David Betz"
101
102 bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
103
104 clearpart --all --initlabel --drives=sda
105
106 part /boot --fstype="xfs" --ondisk=sda --size=500
107 part pv.1 --fstype="lvmpv" --ondisk=sda --size=1000 --grow
108
109 volgroup vg01 --pesize=4096 pv.1
110
111 logvol / --fstype="xfs" --size=30000 --name=root --vgname=vg01
112 logvol /home --fstype="xfs" --size=1000 --name=home --vgname=vg01 --grow
113 logvol swap --fstype="swap" --size=4096 --name=swap --vgname=vg01
114 logvol /var/log --fstype="xfs" --size=8192 --name=log --vgname=vg01
115
116 repo --name=alpha --baseurl="ftp://$PUBLIC_IP/pub/centos72"
117
118 %packages
119 @^minimal
120 @core
121 kexec-tools
122
123 %end
124
125 %addon com_redhat_kdump --enable --reserve-mb='auto'
126
127 %end
128 EOF
129
130 chmod 644 /var/ftp/pub/centos72/install.ks
131