pxe/service-install.sh

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