使用 preseed 安装 Ubuntu

原理大同小异,需要 dhcp,tftp,可以通过一个轻量级的 dnsmasq 来解决:

$ sudo yum  install dnsmasq
$ cat /etc/dnsmasq.conf
bogus-priv
interface=eth1
dhcp-range=192.168.1.1,192.168.1.20,255.255.255.0,100h
dhcp-option=3,192.168.1.254
dhcp-boot=pxelinux.0
enable-tftp
tftp-root=/var/ftpd
log-queries
log-dhcp

如果不想使用 dnsmasq,可以将 dhcp 以及 tftp 分开来使用:

$ sudo yum install -y dhcp
$ cat /etc/dhcpd.conf
ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

subnet 192.168.1. netmask 255.255.255.0 {
   option routers             192.168.1.254;
   option domain-name-servers 8.8.4.4;
   option subnet-mask         255.255.255.0;
   range dynamic-bootp        192.168.1.1 192.168.1.20;
   filename                   "/pxelinux.0";
   default-lease-time         21600;
   max-lease-time             43200;
   next-server                192.168.1.254
}

$ sudo yum install -y xinetd tftp-server
$ cat /etc/xinetd.d/tftp
service tftp
{
   socket_type = dgram
       protocol = udp
       wait = yes
       user = root
       server = /usr/sbin/in.tftpd
       server_args = -u nobody -s /tftpboot -c -p -U 777
       disable = no
       per_source = 11
       cps = 100 2
       flags = IPv4
}

$ sudo /etc/init.d/xinetd start

在一台机子上测试 tftp 是否正常:

$ tftp 192.168.1.254
>get test

$ sudo yum  install httpd
$ sudo mount -o loop ubuntu-10.04.3-server-amd64.iso /mnt
$ sudo cp -r /mnt/* /var/www/ubuntu
$ sudo cp -r /var/www/ubuntu/install/netboot/* /var/ftpd/
$ cat /var/ftpd/ubuntu-installer/amd64/pxelinux.cfg/default
prompt 1
timeout 0
default 0
display boot.msg

LABEL 0

localboot 0

label 1

kernel ubuntu-installer/amd64/linux
append initrd=ubuntu-installer/amd64/initrd.gz locale=en_US.UTF-8 console-setup/layoutcode=en_US debian-installer/keymap=us netcfg/choose_interface=eth1 netcfg/get_hostname=unode netcfg/get_domain=example.com console-setup/ask_detect=false preseed/url=http://192.16.1.254/preseed.cfg —

$ cat  /var/ftpd/boot.msg

### START INSTALLING ######

Choose installation type(0/1/2),the DEFAULT is 0:

0 Local Boot (default)
1 Ubuntu-10.04.3-x86_64 server
2 CentOS-5.6-x6_64 server

有关 preseed 的语法规则以及含义,可以点击这里,一篇更详细的教程