服務端: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 <ubuntu-archive-keyring.gpg匯入當前key
#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
# 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
#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”;