debian+pxe+preseed.cfg安裝配置
debian+pxe 最主要的是preseed 文件的的配置,其他的基本沒有什麼難度。具體如下:
apt-get install apt-cacher-ng apache2
vim /etc/apt-cacher-ng/backends_debian
http://mirrors.163.com/debian/
cat /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"
vi /etc/dhcp/dhcpd.conf
subnet 192.88.50.0 netmask 255.255.255.0 {
range 192.88.50.200 192.88.50.253;
option domain-name-servers 192.88.50.42;
option routers 192.88.50.1;
default-lease-time 600;
max-lease-time 7200;
next-server 192.88.50.46;
filename "pxelinux.0";
}
mkdir /var/lib/tftpboot
cd /var/lib/tftpboot
wget http://ftp.fr.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/netboot/debian-installer/amd64/pxelinux.0
mkdir -p /var/lib/tftpboot/debian/wheezy/amd64
cd /var/lib/tftpboot/debian/wheezy/amd64
wget http://ftp.fr.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/netboot/debian-installer/amd64/linux
wget http://ftp.fr.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz
mkdir -p /var/lib/tftpboot/debian/wheezy/amd64/boot-screens
cd /var/lib/tftpboot/debian/wheezy/amd64/boot-screens
lftp http://ftp.fr.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/netboot/debian-installer/amd64/boot-screens/
下載所需文件:
get syslinux.cfg menu.cfg vesamenu.c32
mkdir -p /var/lib/tftpboot/pxelinux.cfg/
cd /var/lib/tftpboot/pxelinux.cfg/
wget http://ftp.fr.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/netboot/debian-installer/amd64/pxelinux.cfg/default
cd /var/lib/tftpboot/debian/wheezy/amd64
wget http://people.debian.org/~dannf/add-firmware-to/add-firmware-to
sed -i 's/lenny/wheezy/' add-firmware-to
chmod +x add-firmware-to
./add-firmware-to initrd.gz initrd.nonfree.gz wheezy
mv initrd.gz initrd.free.gz
ln -s initrd.nonfree.gz initrd.gz
vim /var/lib/tftpboot/pxelinux.cfg/default
# D-I config version 2.0
include debian/wheezy/amd64/boot-screens/menu.cfg
default debian/wheezy/amd64/boot-screens/vesamenu.c32
prompt 1
timeout 3
DEFAULT wheezy_amd64
LABEL wheezy_amd64
kernel debian/wheezy/amd64/linux
append vga=normal initrd=debian/wheezy/amd64/initrd.gz auto=true interface=auto netcfg/dhcp_timeout=60 netcfg/choose_interface=auto priority=critical url=http://192.88.50.46/pxe/preseed.cfg DEBCONF_DEBUG=5
IPAPPEND 2
mkdir /var/www/pxe
vim /var/www/pxe/preseed.cfg
d-i debian-installer/locale string zh_CN
d-i console-keymaps-at/keymap select us
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/xkb-keymap select us
d-i keyboard-configuration/layoutcode string us
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string noconfigured
d-i netcfg/get_domain string test.com
d-i netcfg/no_default_route boolean true
d-i mirror/country string manual
d-i mirror/protocol string http
d-i mirror/http/hostname string 192.88.50.46:3142
d-i mirror/http/directory string /debian/
d-i mirror/http/proxy string
d-i mirror/suite string wheezy
### 設置時區
d-i time/zone string Asia/Shanghai
d-i clock-setup/utc boolean true
d-i clock-setup/ntp boolean true
### 設置分區 分別為swap 8G /home 2G / 10G /tmp 1G /use 40G /var 10G 剩余的全部分給 /www
d-i partman-auto/disk string /dev/vda ###需要分區的磁盤文件,默認為/dev/sda
d-i partman-auto/method string lvm
d-i partman-auto/choose_recipe select fsm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-auto-lvm/no_boot boolean true
d-i partman-auto-lvm/new_vg_name string vg0
d-i partman-auto/expert_recipe string \
fsm :: \
1024 100% 8192 linux-swap method{ swap } \
format{ } $lvmok{ } lv_name{ swap } \
. \
2048 2048 2048 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /home } lv_name{ home } \
format{ } use_filesystem{ } filesystem{ ext4 } \
. \
10240 10240 10240 ext4 method{ lvm } \
$lvmok{ } mountpoint{ / } lv_name{ root } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
. \
768 1024 1024 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /tmp } lv_name{ tmp } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
. \
10240 40960 40960 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /usr } lv_name{ usr } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
. \
7680 10240 10240 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /var } lv_name{ var } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
. \
1 2048 1000000000 ext4 method{ lvm } \
$lvmok{ } mountpoint{ /www } lv_name{ www } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/relatime{ relatime } \
.
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/confirm boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm boolean true
### 保存磁盤分區信息
d-i partman/choose_partition \
select Finish partitioning and write changes to disk
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
### 設置root 用戶密碼
d-i passwd/root-password password 111111
d-i passwd/root-password-again password 111111
d-i user-setup/allow-password-weak boolean true
#d-i apt-setup/restricted boolean true
### 安裝的軟件包
tasksel tasksel/first multiselect standard
d-i pkgsel/include string ruby openssh-server sysstat xinetd build-essential curl tcpdump chkconfig lrzsz atop htop iotop dstat ethtool vim screen curl dmi
decode lsb-release ntp ipmitool
###
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
popularity-contest popularity-contest/participate boolean false
d-i finish-install/reboot_in_progress note
# Once the installation is done we'll set the system up for some firstboot
# magic. 安裝完成後需要執行的其他命令
d-i preseed/late_command string chroot /target sh -c "/usr/bin/curl -o /tmp/postinstall http://192.88.50.46/pxe/postinstall && /bin/sh -x /tmp/postinstall"
vim /var/www/pxe/postinstall
#!/bin/bash
# grab our firstboot script
/usr/bin/curl -o /root/firstboot http://192.88.50.46/pxe/firstboot
chmod +x /root/firstboot
# create a service that will run our firstboot script
cat > /etc/init.d/firstboot << EOF
### BEGIN INIT INFO
# Provides: firstboot
# Required-Start: $networking
# Required-Stop: $networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: A script that runs once
# Description: A script that runs once
### END INIT INFO
cd /root ; /usr/bin/nohup sh -x /root/firstboot &
EOF
# install the firstboot service
chmod +x /etc/init.d/firstboot
update-rc.d firstboot defaults
echo "finished postinst"
vim /var/www/pxe/firstboot
#!/bin/sh
PXESERVER=192.88.50.46
# This script will run the first time the system boots. Even
# though we've told it to run after networking is enabled,
#
# Introducing a brief sleep makes things work right all the
# time. The time for DHCP to catch up.
sleep 120
# install our new sources
cat << EOF >/etc/apt/sources.list
deb http://mirrors.163.com/debian/ wheezy main
deb-src http://mirrors.163.com/debian/ wheezy main
deb http://security.debian.org/ wheezy/updates main contrib
deb-src http://security.debian.org/ wheezy/updates main contrib
# wheezy-updates, previously known as 'volatile'
deb http://mirrors.163.com/debian/ wheezy-updates main contrib
deb-src http://mirrors.163.com/debian/ wheezy-updates main contrib
EOF
update-rc.d firstboot remove
rm /etc/init.d/firstboot /root/firstboot
chkconfig rmnologin off
chkconfig nfs-common off
chkconfig rpcbind off
chkconfig rsync off
chkconfig ipmievd off
chkconfig exim4 off
chkconfig ntp off
chkconfig salt-master off
sed -i 's/false/true/g' /etc/default/sysstat
cat << EOF >> /etc/hostnmae
debian
EOF
cat << EOF >> /root/.bashrc
export LS_OPTIONS='--color=auto'
eval "``dircolors``"
alias ls='ls $LS_OPTIONS'
alias l='ls $LS_OPTIONS -lA'
EOF
/sbin/reboot
然後pxe引導後自己安裝,無需手工干預。完成後記得修改機器名與Ip地址即可。