PXE远程网络安装linux系统
刚进公司,新人学习各种方式装linux系统。U盘安装已经安装了,现在该网络安装系统了。
首先把实验的环境。如图:

首先把环境搭建起来,
1、搭建DHCPF服务器
各种方法找到dhcpd-* .rpm,最好在系统ios里那个。

[root@localhost Desktop]#rpm -ivh dhcpd-* .rpm
[root@localhost Desktop]#rpm -ql dhcpd //查看我们装了那些dhcpd相关的

[root@localhost isolinux]# vi /etc/dhcpd.conf 
内容:

ddns-update-style interim;
ignore client-updates;

subnet 192.168.3.0 netmask 255.255.0.0 {

# --- default gateway
        option routers                  192.168.0.1;
        option subnet-mask              255.255.255.0;

        server-name "192.168.3.12";
        option nis-domain               "domain.org";
        option domain-name              "domain.org";
        option domain-name-servers      192.168.0.1;

        option time-offset              -18000; # Eastern Standard Time
#       option ntp-servers              192.168.1.1;
#       option netbios-name-servers     192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
#       option netbios-node-type 2;

        range dynamic-bootp 192.168.3.1 192.168.3.254;
        default-lease-time 21600;
        max-lease-time 43200;
}
         group pxe{
        filename "/pxelinux.0";   //方便找到pxe
        # we want the nameserver to appear at a fixed address
        host test{
                next-server 192.168.3.12;   //nfs服务器
                hardware ethernet E0:CB:4E:CE:6A:17;
                fixed-address 192.168.3.5;   //待安装主机

        }

}

[root@localhost Desktop]#service dhcpd start

2、配置tftp服务器
安装就不写了。修改配置;

[root@localhost isolinux]# vi /etc/xinetd.d/tftp 


# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -u nobody -s /tftpboot
        disable                 = no             //默认是yes修改为no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
[root@localhost Desktop]#chkconfig xinetd on
[root@localhost Desktop]#chkconfig  --list | grep tftp

[root@localhost Desktop]#service xinetd start


3、安装nfs

[root@localhost tftpboot]#mkdir /instsvr

[root@localhost tftpboot]# ll /instsvr/     //放安装文件
total 3041648
-rwxr-xr-x 1 root root 3111600128 Apr 19 16:05 rhel-server-5.5-i386-dvd.iso

[root@localhost tftpboot]# vi /etc/exports 


/instsvr   *(ro,no_root_squash,sync)

启动服务

检测目录/instsrv是否已被正确共享
[root@localhost tftpboot]# showmount -e localhost
Export list for localhost:
/instsvr *
[root@localhost tftpboot]# service nfs restart

4、引导文件
挂载ios文件
[root@localhost Desktop]# mount -o loop,ro rhel-server-5.5-i386-dvd.iso /media/ios/

[root@localhost isolinux]# cp initrd.img vmlinuz /tftpboot

从系统盘的拷贝initrd.img vmlinuz这两个文件。

[root@localhost ~]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot

[root@localhost tftpboot]# cp /media/ios/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default

[root@localhost ~]# cd /tftpboot/
[root@localhost tftpboot]# ll
total 9548
-rw-r--r-- 1 root root 7838075 Jun  5 16:33 initrd.img
drwxr-xr-x 3 root root    4096 Jun  5 12:30 linux-install
-rw-r--r-- 1 root root   13148 Jun  5 13:00 pxelinux.0
drwxr-xr-x 2 root root    4096 Jun  5 14:36 pxelinux.cfg
-r--r--r-- 1 root root 1875796 Jun  5 10:59 vmlinuz
[root@localhost tftpboot]# 

[root@localhost tftpboot]# cp /media/ios/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default

[root@localhost tftpboot]# ll pxelinux.cfg/
total 8
-rwxr-xr-x 1 root root 366 Jun  5 14:40 default
[root@localhost tftpboot]# 
[root@localhost tftpboot]# vi pxelinux.cfg/default 

default linux
prompt 1
timeout 600
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
  kernel vmlinuz
  append initrd=initrd.img
label text
  kernel vmlinuz
  append initrd=initrd.img text
label ks
  kernel vmlinuz
  append ks initrd=initrd.img
label local
  localboot 1
label memtest86
  kernel memtest
  append -


把服务器的服务启动。安装选择网络启动就可以了。
 四 、少交互无人职守
[root@localhost ~]# vi /root/anaconda-ks.cfg
# Kickstart file automatically generated by anaconda.

install
nfs --server=192.168.3.5 --dir=/instsvr
key --skip
lang zh_CN.UTF-8
keyboard us
xconfig --startxonboot
network --device eth0 --bootproto dhcp
rootpw --iscrypted $1$R3wtqu1.$ego8qNo6O6bXtzv  --改成123456
firewall --enabled --port=22:tcp
authconfig --enableshadow --enablemd5
selinux --enforcing
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --drives=sda
part /boot --fstype ext3 --size=100 --grow --maxsize=1024
part swap --size=100 --grow --maxsize=2048
part /usr/local --fstype ext3 --size=100 --grow --maxsize=8000
part /usr --fstype ext3 --size=100 --grow --maxsize=4096
part /opt --fstype ext3 --size=100 --grow --maxsize=8459
part /tmp --fstype ext3 --size=100 --grow --maxsize=4096
part /home --fstype ext3 --size=100 --grow --maxsize=2048
part / --fstype ext3 --size=100 --grow --maxsize=50000

%packages
@admin-tools
@base
@chinese-support
@core
@development-libs
@development-tools
@dialup
@editors
@gnome-desktop
@gnome-software-development
@graphical-internet
@graphics
@java
@java-development
@legacy-software-development
@legacy-software-support
@network-server
@office
@printing
@sound-and-video
@text-internet
@web-server
@x-software-development
@base-x
kexec-tools
fipscheck
device-mapper-multipath
sgpio
python-dmidecode
imake
emacs
libsane-hpaio
qt4
vnc-server
dnsmasq
dhcp
krb5-server
mesa-libGLU-devel
xorg-x11-utils
xorg-x11-server-Xnest
xorg-x11-server-Xvfb

[root@localhost ~]# cp /root/anaconda-ks.cfg  /instsvr/ks/ks.cfg

[root@localhost ~]# vi /tftpboot/pxelinucx.cfg/default
[root@localhost tftpboot]# vi pxelinux.cfg/default 

default linux
prompt 1
timeout 600
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
  kernel vmlinuz
  append ks=nfs:192.168.3.5:/instsvr/ks/ks.cfg initrd=initrd.img
label text
  kernel vmlinuz
  append initrd=initrd.img text
label ks
  kernel vmlinuz
  append ks initrd=initrd.img
label local
  localboot 1
label memtest86
  kernel memtest
  append -

把服务开启,把防火墙关闭!
ok!



附:
当时我会碰到安装端的网卡引导里并不能认到,怎么办呢?
思路:就是initrd.img有关了。于是上网google去initrd.img
就是把网卡驱动编译好的加进去。

[root@localhost Desktop]# lspci
01:00.0 Ethernet controller: Atheros Communications Atheros AR8121/AR8113/AR8114 PCI-E Ethernet Controller (rev b0)

这个是我们已经装好的驱动。都是AR8121/AR8113/AR8114 PCI-E Ethernet Controller

这个值:
[root@localhost Desktop]# vi /lib/modules/2.6.18-194.el5/modules.alias
alias pci:v00001969d00001026sv*sd*bc*sc*i* atl1e
 
[root@localhost Desktop]# ll /lib/modules/2.6.18-194.el5/kernel/drivers/net/atl1e/
total 800
-rw-r--r-- 1 root root 810366 Jun  1 11:28 atl1e.ko

找到已编译好的网卡atl1e

把atl1e.ko拷贝出来暂时随便放到一个你可以记的的目录地下就可以了。我放到/根目录下
[root@localhost Desktop]# cp /lib/modules/2.6.18-194.el5/kernel/drivers/net/atl1e/atl1e.ko /                                                                               


未完!!