通过 网络安装 linux

必备服务:
1.DHCP服务
2.tftp服务
3.NFS服务或FTP或HTTP均可
(要求待安装电脑必需支持PXE启动)

配置步骤:
1.DHCP服务器的配置
[root@disk iso]# rpm -qa dhcp* #确定dhcp是否安装
dhcp-3.0pl1-23

[root@disk iso]# vi /etc/dhcpd.conf #我的dhcp配置(可通过rpm -ql dhcp找到范本)
#ddns-update-style interim;
ddns-update-style none; #不更新DDNS
ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 {

# — default gateway
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;

# option nis-domain "domain.org";
# option domain-name "domain.org";
option domain-name-servers 202.106.46.151,202.106.196.115,202.106.0.20;

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.1.240 192.168.1.254;
default-lease-time 21600;
max-lease-time 43200;

# we want the nameserver to appear at a fixed address
group pxe {
filename "pxelinux.0";
host ns {
# next-server marvin.redhat.com;
next-server 192.168.1.51;
hardware ethernet 00:0c:29:96:93:05; #待安装电脑的MAC与IP的绑定
fixed-address 192.168.1.240;
}
}}

[root@disk iso]# vi /usr/share/doc/dhcp-3.0pl1/dhcpd.conf.sample
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
# — default gateway
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;

option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 192.168.1.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.0.128 192.168.0.255;
default-lease-time 21600;
max-lease-time 43200;

# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}

#如果有多个网卡
[root@disk iso]# cat /etc/sysconfig/dhcpd
# Command line options here
DHCPDARGS=“eth0”

#启动dhcp
[root@disk iso]# /etc/init.d/dhcpd start

#确定dhcp是否开机自动运行
[root@disk iso]# chkconfig –list |grep dhcp
dhcpd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭

2.tftp服务配置
[root@disk iso]# rpm -qa |grep tftp
tftp-0.32-4
tftp-server-0.32-4

安装
rpm -ivh tftp-server-0.32-4
rpm -ivh tftp-0.32-4

[root@disk iso]# cat /etc/xinetd.d/tftp
service tftp
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot -c
}
修改项server_args= -s <path> -c,其中<path>处可以改为你的tftp-server的根目录,参数-s指定chroot,-c指定了可以创建文件

3.NFS服务器配置
[root@disk /]# cat /etc/exports
/home/iso 192.168.1.0/24(rw,no_root_squash)
参数包括
rw:可读写
ro:只读
sync:同步写入
async:先暂存于内存中
no_root_squash:如果是root,则以root的权限访问
root_squash:如果是root,则压缩成匿名用户
all_squash:将所有登陆用户压缩成匿名用户
anonuid:将匿名者变为指定的uid
anongid:匿名者指定gid

#启动RPC与NFS(最好先关闭防火墙做测试)
/etc/init.d/portmap start
/etc/init.d/nfs start
确认是否正常
[root@disk /]# /etc/init.d/portmap status
portmap (pid 2024) 正在运行…
[root@disk /]# /etc/init.d/nfs status
rpc.mountd (pid 2425) 正在运行…
nfsd (pid 2417 2416 2415 2414 2413 2412 2411 2410) 正在运行…
rpc.rquotad (pid 2405) 正在运行…
#联机观察
[root@disk /]# showmount -a localhost
All mount points on localhost:
redhat.kumouse.com:/home/iso
[root@disk /]# showmount -e localhost
Export list for localhost:
/home/iso (everyone)
参数
-a 显示联机共享状态
-e 显示某主机的/etc/exports所共享的目录

设置NFS服务器的防火墙
[root@disk /]# cat /etc/sysconfig/nfs
MOUNTD_PORT="815"
#STATD_PORT=""
LOCKD_TCPPORT="2049"
LOCKD_UDPPORT="2049"
在/etc/sysconfig/iptables加入
-A RH-Firewall-1-INPUT -p tcp -s 192.168.1.0/24 -m multiport –dport 111,815,2049 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -s 192.168.1.0/24 -m multiport –dport 111,815,2049 -j ACCEPT
[root@disk /]#/etc/init.d/iptables restart

在别外一台linux主机上加载试试
[root@redhat mydisk]#mkdir /mydisk
[root@redhat mydisk]# mount -t nfs 192.168.1.200:/home/iso /mydisk
如果不输出信息,说明成功了,可以进去看看,看看是不是和/home/iso中的内容一样

关于NFS更详细的说明见:http://www.kumouse.com/article.asp?id=113

经过以上步骤服务器配置基本就完成了
4.将引导程序加入到TFTP的工作目录中(/etc/xinetd.d/tftp中写的server_args = -s /tftpboot -c)
#将光盘中/isolinux目录下的initrd.img与vmlinuz复制到/tftpboot中
[root@disk]#mkdir /mnt/iso
[root@disk]#mount -o loop,ro RHEL5-U2-i386-AS-disc1.iso /mnt/iso
[root@disk]#cp /mnt/iso/isolinux/initrd.img /tftpboot
[root@disk]#cp /mnt/iso/isolinux/vmlinuz /tftpboot
[root@disk]#mv /tftpboot/initrd.img /tftpboot/initrd-rhel5u2-i386.img
[root@disk]#mv /tftpboot/vmlinuz /tftpboot/vmlinuz-rhel5u2-i386
#将启动镜像文件pxelinux.0复制到/tftpboot中
[root@disk]#cp /usr/lib/syslinux/pxelinux.0 /tftpboot/
#编辑pxelinux.0的配置文件,所有的配置文件都放在启动服务器的/tftpboot/pxelinux.cfg/目录下
[root@disk /]# cat /tftpboot/pxelinux.cfg/default
default rhel5u2-i386
prompt 1
display pxelinux.cfg/list

label rhel5u2-i386
kernel vmlinuz-rhel5u2-i386
append initrd=initrd-rhel5u2-i386.img
label rhel5u2-i386-text
kernel vmlinuz-rhel5u2-i386
append initrd=initrd-rhel5u2-i386.img text

#我们将所有备选Red Hat Linux版本列在文件pxelinux.cfg/list中,它的内容会被pxelinux.0显示出来。

[root@disk /]# cat /tftpboot/pxelinux.cfg/list
Choose one of the following Linux distributions for your installation:
Name Distribution Arch. Installation media
————————————————————————-
rhel5u2-i386 RHEL 5 AS U2 i386 192.1

68.1.51:/home/iso/rhel5u2
rhel5u2-i386-text RHEL 5 AS U2 i386 192.168.1.51:/home/iso/rhel5u2

然后复制镜像文件到/home/iso中,就是nfs共享出来的目录,然后把待安装电脑改成网卡启动就可以安装了

选读:无人值守的安装
[root@bootserver ks]# more ks.cfg
# Kickstart file automatically generated by anaconda.
text 文本形式安装
install
nfs –server=192.168.1.51 –dir=/home/iso/rhel5u2 nfs方法安装
lang en_US.UTF-8
langsupport –default=en_US.UTF-8 en_US.UTF-8
keyboard us
#xconfig –card "S3 Savage/IX" –videoram 15168 –hsync 31.5-37.9 –vsync 50-70 –resolution 800×600 –depth 16 –startxonboot —

de
faultdesktop kde
network –device eth0 –bootproto dhcp
rootpw –iscrypted $1$e68iHGpw$/Qe4meNVXULikjCwDH26F1
firewall –disabled
selinux –disabled
authconfig –enableshadow –enablemd5
timezone Asia/Shanghai
bootloader –location=mbr
# 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 –initlabel
#part / –fstype ext2 –size=5000 分区格式可以根据自己的定义。 注释的话手工分区。分区后以下自动安装
#part swap –size=512
#part /data –fstype ext3 –size=1 –grow
%packages
@ admin-tools
@ editors
@ emacs
@ system-tools
@ legacy-network-server
@ dialup
@ ftp-server
@ network-server
@ compat-arch-support
@ legacy-software-development
@ server-cfg
@ development-tools
kernel-devel
e2fsprogs
kernel
pcmcia-cs
grub
%post

所有以"#"号开头的都是注释。

文件中的nfs –server=192.168.1.51 –dir=/home/iso/rhel5u2选项告诉安装程序:到服务器192.168.138.1的NFS共享目录/home/iso/rhel5u2下寻

找安装介质。Red Hat Linux安装程序足够聪明,可以识别该目录下应该被读取的ISO光盘镜像文件名,所有这里你不需要指定ISO文件名。

部署kickstart配置文件

首先我们需要把kickstart配置文件放在安装服务器上。我们把它放到/home/iso/rhel5u2/ks目录下。即该文件的NFS访问路径为:

nfs:192.168.1.51:/home/iso/rhel5u2/ks/ks.cfg

其次,我们需要让安装程序知道我们希望它用kickstart方式安装,并告知它可以从哪里获得kickstart配置文件。这可以通过给内核添加一个参

数"ks=kickstart配置文件路径"来实现。我们只需对启动服务器上的default文件做一些小修改就可以做到这点:

LABEL rhel5u2-i386
KERNEL vmlinuz-rhel5u2-i386
APPEND ks=nfs:192.168.1.51:/home/iso/rhel5u2/ks/ks.cfg initrd=initrd-rhel4u2-i386.img
ramdisk_size=8192

这样在启动安装程序的时候,参数ks=nfs:192.168.1.51:/home/iso/rhel5u2/ks/ks.cfg会被传递给它,告诉它使用这个文件作为kickstart配置文件

来进行kickstart安装。

通过 网络安装 linux》有一个想法

  1. wall decal

    You actually make it seem really easy with your presentation but
    I to find this matter to be actually something which I believe I
    would never understand. It sort of feels too complicated and very huge for me.
    I am having a look ahead in your next post, I’ll try to get the grasp of it!

    回复

回复 wall decal 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注