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地址即可。

转载于:https://my.oschina.net/u/142602/blog/171328

<think>嗯,用户想通过PXEPreseed实现Ubuntu的批量自动化安装。我得先回忆一下PXEPreseed的基本概念。PXE是预启动执行环境,可以让客户端通过网络启动,而PreseedDebian系系统自动化安装配置文件。用户可能需要从零开始搭建环境,所以需要分步骤讲解。 首先,PXE需要DHCP、TFTP和HTTP服务器。DHCP分配IP并告知客户端TFTP的位置,TFTP提供引导文件,HTTP则存放安装镜像和Preseed文件。记得Syslinux的pxelinux.0文件是关键,客户端启动时会下载这个文件[^1]。然后需要准备Ubuntu的ISO镜像,解压到HTTP目录,设置引导配置,比如pxelinux.cfg/default文件,指定内核和initrd的位置,同时加入Preseed配置参数。 Preseed文件需要正确配置分区、语言、时区、用户账户等自动化选项。用户可能需要参考Ubuntu的官方文档来确保语法正确[^2]。测试的时候可以用虚拟机启动,确认是否自动安装。如果遇到问题,可能需要检查TFTP的路径是否正确,或者Preseed文件是否有语法错误。 用户可能还会关心如何优化流程,比如使用Kickstart对比Preseed的区别,或者如何处理不同硬件的兼容性问题。此外,日志记录和错误处理也是实际部署中需要注意的点,比如在Preseed中加入d-i preseed/late_command来执行自定义脚本[^3]。可能还需要考虑网络带宽,同时大量客户端启动时会不会有性能问题,这时候分布式TFTP或者HTTP服务器可能有用。 最后,要确保提供的步骤清晰,命令准确,避免用户操作时出错。同时,相关问题要覆盖用户可能进一步的需求,比如调试方法、高级配置或与其他工具的整合。</think>### PXEPreseed实现Ubuntu批量自动化安装步骤 #### 一、基础环境搭建 1. **网络服务配置** - **DHCP服务器**:为客户端分配IP地址并指向TFTP服务器 ```bash subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.100 192.168.1.200; filename "pxelinux.0"; # 指定PXE引导文件 } ``` - **TFTP服务器**:存储PXE启动文件(需安装`tftpd-hpa`) ```bash sudo apt install tftpd-hpa ``` - **HTTP/NFS服务器**:存放Ubuntu镜像和Preseed文件(推荐使用`nginx`或`apache2`) 2. **引导文件准备** - 复制Syslinux组件到TFTP根目录: ```bash cp /usr/lib/syslinux/modules/bios/* /var/lib/tftpboot/ cp /usr/lib/PXELINUX/pxelinux.0 /var/lib/tftpboot/ ``` #### 二、Ubuntu安装镜像处理 1. **下载ISO镜像** ```bash wget https://releases.ubuntu.com/20.04/ubuntu-20.04.6-live-server-amd64.iso ``` 2. **挂载并提取文件** ```bash mount -o loop ubuntu-20.04.6-live-server-amd64.iso /mnt cp -r /mnt/* /var/www/html/ubuntu/ umount /mnt ``` #### 三、Preseed配置 1. **生成配置文件** 创建`/var/www/html/preseed/ubuntu.seed`,核心参数示例: ```plaintext d-i partman-auto/disk string /dev/sda d-i passwd/user-fullname string Ubuntu User d-i passwd/user-password password insecure d-i preseed/late_command string in-target apt-get update ``` 2. **集成到PXE菜单** 编辑`/var/lib/tftpboot/pxelinux.cfg/default`: ```plaintext label autoinstall kernel ubuntu/vmlinuz append initrd=ubuntu/initrd.gz auto=true url=http://192.168.1.10/preseed/ubuntu.seed ``` #### 四、验证与部署 1. **客户端测试** 使用虚拟机(VirtualBox/VMware)设置网络启动,观察自动安装过程。若出现`d-i console-setup/ask_detect boolean false`配置错误,需检查Preseed语法。 2. **批量扩展方案** - 通过MAC地址绑定实现差异化安装 - 使用Ansible批量配置DHCP保留地址
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值