码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本之全自动化部署PXE

时间:2017-09-01 10:49:19      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:shell   pxe   

#!/bin/bash

#2017-07-21 by max

#config pxe


#config yum

if [ ! -d ~/yum.bak ];

then

mv /etc/yum.repos.d/* ~/yum.bak

else

mkdir ~/yum.bak

mv /etc/yum.repos.d/* ~/yum.bak

fi

cat >/etc/yum.repos.d/server.repo<< EOF

[base]

name=server

baseurl=file:///mnt

gnabled=1

gpgcheck=0

EOF

mount /dev/cdrom /mnt

yum clean all

yum -y update


#config ftp

yum -y install vsftpd

systemctl restart vsftpd ; systemctl enable vsftpd


#config tftp

yum -y install tftp tftp-server xinetd

sed ‘13s/\/var\/lib/ /‘ /etc/xinetd.d/tftp -i

sed ‘14s/yes/no/‘ /etc/xinetd.d/tftp -i


#config network

cat >/etc/sysconfig/network-scripts/ifcfg-eno16777736<<EOF

TYPE=Ethernet

BOOTPROTO=static

NAME=eno16777736

DEVICE=eno16777736

ONBOOT=yes

NETMASK=255.255.255.0

IPADDR=192.168.25.1

EOF

systemctl restart network


#config dhcp

yum -y install dhcp

if [ -f /etc/dhcp/dhcpd.conf.bak ];

then

rm -rf /etc/dhcp/dhcpd.conf.bak

fi

cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak

rm -rf /etc/dhcp/dhcpd.conf

cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf

cat >>/etc/dhcp/dhcpd.conf<<EOF

subnet 192.168.25.0 netmask 255.255.255.0 {

        range 192.168.25.100 192.168.25.200;

        next-server 192.168.25.1;

        filename "pxelinux.0";

}

EOF

systemctl restart dhcpd ;systemctl enable dhcpd


#config kickstart

if [ ! -d /tftpboot/ ];

then 

mkdir /tftpboot/

else

rm -rf /tftpboot/*

fi

mkdir /tftpboot/pxelinux.cfg -p

yum -y install syslinux

cp /usr/share/syslinux/pxelinux.0 /tftpboot/

cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default

cp /mnt/images/pxeboot/initrd.img /tftpboot/

cp /mnt/images/pxeboot/vmlinuz /tftpboot/

chmod 644 /tftpboot/pxelinux.cfg/default


#config boot ‘default‘

sed ‘1s/.*/default linux/‘ /tftpboot/pxelinux.cfg/default -i

sed ‘64s/.*/append initrd=initrd.img ks=ftp:\/\/192.168.25.1\/ks.cfg/‘ /tftpboot/pxelinux.cfg/default -i

sed ‘68d‘ /tftpboot/pxelinux.cfg/default -i

sed ‘63 imenu default‘ /tftpboot/pxelinux.cfg/default -i


cat >/var/ftp/ks.cfg<<EOF

#platform=x86, AMD64, 或 Intel EM64T

#version=DEVEL

# Install OS instead of upgrade

install

# Keyboard layouts

keyboard ‘us‘

# Root password

rootpw --iscrypted $1$syci/OCt$KHzs273jZFiTzcp92eGxJ0

# System timezone

timezone Africa/Abidjan

# Use network installation

url --url="ftp://192.168.25.1/pub"

# System language

lang en_US

# Firewall configuration

firewall --disabled

# System authorization information

auth  --useshadow  --passalgo=sha512

# Use graphical install

graphical

firstboot --disable

# SELinux configuration

selinux --enforcing


# Network information

network  --bootproto=dhcp --device=eno16777736 --onboot=yes

# Reboot after installation

reboot

# System bootloader configuration

bootloader --location=mbr --md5pass="$1$wLuI.AZb$sO8s4dCMYHZ7rRDIhRC95."

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information

part / --fstype="xfs" --size=20480

part swap --fstype="swap" --size=2048


%packages

@base

@core

@desktop-debugging

@dial-up

@fonts

@gnome-desktop

@guest-agents

@guest-desktop-agents

@input-methods

@internet-browser

@multimedia

@print-client

@x11


%end

EOF


#config srouce and server

umount /dev/cdrom

mount /dev/cdrom /var/ftp/pub

iptables -F

setenforce 0

systemctl stop firewalld

systemctl restart dhcpd

systemctl restart vsftpd

systemctl restart xinetd


shell脚本之全自动化部署PXE

标签:shell   pxe   

原文地址:http://zhaom0109.blog.51cto.com/11675013/1961603

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!