服务端:centos5u4 x64 (IP:192.168.242.253/24)
所需环境:dhcp (dhcp / dhcp-devel)
httpd
tftp (tftp / tftp-server)
xinetd
syslinux
本文只针对如何通过net全自动安装ubuntu10.4-server,关于安装redhat不在本篇讨论,只是通过centos服务端的pxe引导与tftp等一系列
所需iso镜像为:ubuntu10.4-server-amd64.iso
挂载镜像:
先挂载挂载ubuntu的镜像
#mount /dev/cdrom /mnt
#mkdir /var/www/html/ubuntu64
#cp –ar /mnt/* /var/www/html/ubuntu64
#umount /mnt
再服务端版本的centos镜像
#mount /dev/cdrom /mnt
|
1.修改必要的文件
(为了安装ubuntu时省去繁琐的工作,自动安装):
#cd /var/www/html/
# cp ubuntu64/install/netboot/ubuntu-installer/amd64/initrd.gz ./
#gunzip initrd.gz
#mv initrd initrd.img
#mkdir initrd
#cd initrd
#cpio -i < ../initrd.img
解压到当前目录
制作gpg key(防止安装时出现bad mirrors 错误),需要安装rng-utils
#gpg --gen-key 安装提示一步步下去,如果出现如下错误:
Not enough random bytes available,说明系统中的熵值不足,没有足够的随机数给GPG来产生密钥。打开另一终端
可以通过这个命令查看有多少剩余的熵
# cat /proc/sys/kernel/random/entropy_avail
如果不足的话,可以用rngd来产生
# rngd -r /dev/urandom -o /dev/random -f -t 1
|
#gpg --list-key可以看到刚创建的key
#cd usr/share/keyrings
#gpg --import
**************************
客户端使用时遇到的问题:
#apt-get update 时出错,应该下载不到镜像
Some index files failed to download, they have been ignored......
解决:
#mv /etc/apt/sources.list /etc/apt/sources.list.bk
#vi /etc/apt/sources.list 添加如下:
#gpg --list-key得到三个key的pub值
#gpg --export 437D05B5 FBB75451 92B92869 > ubuntu-archive-keyring.gpg
制作自动安装的cfg文件
#cd /var/www/html/initrd就上面的那个initrd目录
#vi preseed.cfg (貌似名字要固定),写入如下:
# Locale sets language and country.
d-i debian-installer/locale string en_HK
# Keyboard selection.
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us
# Network configuration.
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string ubuntu
d-i netcfg/get_domain string ubuntu
#d-i netcfg/get_nameservers string 202.96.209.5
#d-i netcfg/get_ipaddress string 192.168.242.250
#d-i netcfg/get_netmask string 255.255.255.0
#d-i netcfg/get_gateway string 192.168.242.1
#d-i netcfg/confirm_static boolean true
# Mirror settings
d-i mirror/country string manual
d-i mirror/http/hostname string 192.168.242.253
d-i mirror/http/directory string /ubuntu64
d-i mirror/http/proxy string
# Clock and time zone setup
d-i clock-setup/utc boolean false
d-i time/zone string Asia/Shanghai
# Partitioning
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
# Base system installation
d-i base-installer/kernel/p_w_picpath string linux-generic
# Account setup
d-i passwd/root-login boolean true
d-i passwd/root-password password 123qwe
d-i passwd/root-password-again password 123qwe
d-i passwd/make-user boolean false
d-i user-setup/encrypt-home boolean false
# Apt setup
d-i apt-setup/use_mirror boolean false
d-i apt-setup/services-select multiselect security
d-i apt-setup/security_host string 192.168.242.253
d-i apt-setup/security_path string /ubuntu64
d-i debian-installer/allow_unauthenticated string true
# Package selection
tasksel tasksel/first multiselect standard
d-i pkgsel/include string openssh-server vim
d-i pkgsel/upgrade select none
d-i pkgsel/language-packs multiselect en, zh
d-i pkgsel/update-policy select none
# Boot loader installation
d-i grub-installer/only_debian boolean true
# Finishing up the installation
d-i finish-install/reboot_in_progress note
|
其中红色部分为主机名与root密码,网络注释掉,因为不会起作用
现在initrd目录中应该为如下:
initrd]# ls
bin etc
initrd lib64 mnt proc sys usr
dev init lib
media preseed.cfg sbin tmp var
现在可以把initrd打包了
#find . | cpio -o -H newc |gzip -9 >../initrd.gz
#cd ..
#mv initrd.gz initrd.img
#cp initrd.img /tftpboot/initrd-ubuntu.img
2.复制必要的文件(此时centos还挂载在/mnt下)
# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/
# mkdir /tftpboot/pxelinux.cfg
# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
# cp /var/www/html/ubuntu64/install/vmlinuz /tftpboot/vmlinuz-ubuntu
# mkdir /tftpboot/pxelinux.cfg
# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
# cp /var/www/html/ubuntu64/install/vmlinuz /tftpboot/vmlinuz-ubuntu
# cp /mnt/isolinux/*.msg /tftpboot/
3、修改/tftpboot/pxelinux.cfg/default文件
修改后默认会安装
ubuntu,如果有其他系统,类似修改相应的label项,然后在boot.msg中写明
default
ubuntu
prompt 1
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label
ubuntu
kernel vmlinuz-ubuntu
append initrd=initrd-ubuntu.img devfs=nomount ramdisk_size=8192
label linux text
kernel vmlinuz
append text initrd=initrd.img devfs=nomount ramdisk_size=8192
label linux expert
kernel vmlinuz
append expert initrd=initrd.img devfs=nomount ramdisk_size=8192
label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img devfs=nomount ramdisk_size=8192
4.配置DHCP及TFTP服务
1. 配置tftp服务器
#vi /etc/xined.d/tftp
service tftp
{
disable = no
(默认为“yes”,一定要改成“no”)
socket_type = dgram
protocol = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
per_source = 11
cps = 100 2
flags = IPv4
}
|
#service xinetd restart
2. 配置DHCP服务器
#cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
cp:是否覆盖“/etc/dhcpd.conf”? y
cp:是否覆盖“/etc/dhcpd.conf”? y
#vi /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates; filename "pxelinux.0"; //PXE得到IP以后的引导文件 next-server 192.168.242.253; //服务器IP地址。
subnet
192.168.242.0 netmask 255.255.255.0 { //所属网段及掩码。
# --- default gateway option routers 192.168.242.1; //路由器IP,可以写网关IP option subnet-mask 255.255.255.0; # option nis-domain "domain.org"; //注销 # option domain-name "domain.org"; //注销 option domain-name-servers 192.168.242.253; //DNS服务器IP option time-offset -18000; # Eastern Standard Time # option netbios-node-type 2; range dynamic-bootp 192.168.242.100 192.168.242.200; //IP地址池范围。 default-lease-time 21600; ......后面省略 //写配置文件的时候注意每句后面的分号(;)不要丢了。 |
#service dhcpd start
#chkconfig --level 35 dhcpd on
现在到客户端开机从网卡启动应该就好了
**************************
客户端使用时遇到的问题:
#apt-get update 时出错,应该下载不到镜像
Some index files failed to download, they have been ignored......
解决:
#mv /etc/apt/sources.list /etc/apt/sources.list.bk
#vi /etc/apt/sources.list 添加如下:
deb http://Ubuntu.cn99.com/ubuntu/ lucid main universe restricted multiverse deb-src http://Ubuntu.cn99.com/ubuntu/ lucid main universe restricted multiverse deb http://Ubuntu.cn99.com/ubuntu/ lucid-security universe main multiverse restricted deb-src http://Ubuntu.cn99.com/ubuntu/ lucid-security universe main multiverse restricted deb http://Ubuntu.cn99.com/ubuntu/ lucid-updates universe main multiverse restricted deb http://Ubuntu.cn99.com/ubuntu/ lucid-proposed universe main multiverse restricted deb-src http://Ubuntu.cn99.com/ubuntu/ lucid-proposed universe main multiverse restricted deb http://Ubuntu.cn99.com/ubuntu/ lucid-backports universe main multiverse restricted deb-src http://Ubuntu.cn99.com/ubuntu/ lucid-backports universe main multiverse restricted deb-src http://Ubuntu.cn99.com/ubuntu/ lucid-updates universe main multiverse restricted
#vi /etc/apt/apt.conf 把第一行注释
#Acquire::http::Proxy "http://192.168.242.254";