Debian网络PXE批量安装

Debian PXE 批量安装

Debian PXE 网络批量安装

传统配置:/etc/network/interfaces

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# The loopback network interface
auto lo
iface lo inet loopback

#allow-hotplug ens32
#iface ens32 inet dhcp

# The primary network interface
auto ens32
iface ens32 inet static
    address 192.168.99.30
    netmask 255.255.255.0
    gateway 192.168.99.1
    dns-nameservers 223.5.5.5 114.114.114.114

若是 DNS 配置 /etc/resolv.conf 未生效,需要手动配置或安装 resolvconf 包: 手动配置 /etc/resolv.conf

1
2
domain localdomain
nameserver 192.168.99.2

在 Debian 系统中,/etc/network/interfaces 里的 dns-* 配置项,默认是由 resolvconf 这个服务负责翻译并写入 /etc/resolv.conf 的。 安装 resolvconf

1
2
3
4
5
apt-get install -y resolvconf
# 启用 resolvconf 服务并开机自启
systemctl enable --now resolvconf
# 重启 resolvconf 服务
systemctl restart resolvconf

重启网络服务

1
systemctl restart networking

安装 DHCP 服务 isc-dhcp-server

1
2
3
apt-get install -y isc-dhcp-server

systemctl enable --now isc-dhcp-server

启动报错指定网卡名称

1
2
3
# 编辑 /etc/default/isc-dhcp-server 文件,指定网卡名称
INTERFACESv4="ens32"
INTERFACESv6=""

查看 DHCP 启动日志

1
2
3
4
5
6
7
8
# 查看 isc-dhcp-server 服务的所有日志
journalctl -u isc-dhcp-server
# 实时滚动查看最新日志(类似 tail -f)
journalctl -u isc-dhcp-server -f
# 查看最后 50 行日志
journalctl -u isc-dhcp-server -n 50
# 配置文件语法检查
dhcpd -t

编辑 DHCP 配置文件 /etc/dhcp/dhcpd.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
log-facility local7;

option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;

subnet 192.168.99.0 netmask 255.255.255.0 {
    range 192.168.99.100 192.168.99.200;
    option subnet-mask 255.255.255.0;
    option routers 192.168.99.2;
    option domain-name-servers 223.5.5.5;

    # TFTP 服务器地址
    next-server 192.168.99.30;
    # 根据架构类型分发启动文件
    if option architecture-type = 00:07 {
        # EFI x86-64
        filename "debian-installer/amd64/bootnetx64.efi";
    } elsif option architecture-type = 00:09 {
        # EFI x86-64 (备用标识)
        filename "debian-installer/amd64/bootnetx64.efi";
    } else {
        # Legacy BIOS
        filename "bios/pxelinux.0";
    }
    # TFTP服务器IP
    #next-server 192.168.99.30;
    # PXE启动文件
    #filename "pxelinux.0";
}

重启 DHCP 服务

1
systemctl restart isc-dhcp-server
1
apt-get install -y nginx squashfs-tools
1
mkdir -p /srv/www/{preseed,debian12,debian13}

debian12.13.0 网络安装 ISO 下载链接

debian13.2.0 网络安装 ISO 下载链接

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
cat > /etc/nginx/conf.d/debian-pxe.conf << EOF
server {
    listen 8080 default_server;
    listen [::]:8080 default_server;
    
    server_name _;
    
    # Preseed配置文件
    location /preseed {
        alias /srv/www/preseed;
        autoindex on;
    }
    
    # Debian 12 (bookworm)
    location /debian12/ {
        alias /srv/www/debian12/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }

    # Debian 13 (trixie)
    location /debian13/ {
        alias /srv/www/debian13/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }
    
    # 健康检查
    location /health {
        return 200 'OK';
        add_header Content-Type text/plain;
    }
}
EOF

安装 TFTP 服务 tftpd-hpa

1
2
3
4
5
apt-get install -y tftpd-hpa
systemctl enable tftpd-hpa
systemctl restart tftpd-hpa

journalctl -u tftpd-hpa -f

编辑 TFTP 配置文件 /etc/default/tftpd-hpa

1
2
3
4
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure -l"

TFTP 目录结构

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
/srv/tftp/
├── efi/
│   ├── bootx64.efi           # UEFI启动文件
│   ├── grubx64.efi           # GRUB EFI
│   ├── grub.cfg              # GRUB配置
│   └── grub/                 # GRUB模块
│       ├── efi_gop.mod
│       ├── efi_uga.mod
│       └── ...
├── bios/
│   ├── pxelinux.0            # Legacy BIOS启动文件
│   ├── vesamenu.c32
│   ├── ldlinux.c32
│   ├── libutil.c32
│   ├── vmlinuz               # 内核
│   ├── initrd.gz             # 初始化镜像
│   └── pxelinux.cfg/
│       └── default           # Legacy BIOS菜单
├── debian/
│   ├── ...                   # netboot.iso
│   ├── initrd.gz             # 初始化镜像

创建 TFTP 目录结构

1
2
mkdir -p /srv/tftp/{bios,efi,debian}
chown -R tftp:tftp /srv/tftp

启动加载器关系

1
2
3
BIOS PXE   → pxelinux.0
UEFI PXE   → bootnetx64.efi
SecureBoot → shimx64.efi

下载 debian 网络 PXE 安装内核

1
2
3
4
5
6
7
8
9
cd /srv/tftp/debian
wget http://mirrors.ustc.edu.cn/debian/dists/stable/main/installer-amd64/current/images/netboot/netboot.tar.gz
tar -xzf netboot.tar.gz

# debian 12 - bookworm
wget https://mirrors.ustc.edu.cn/debian/dists/bookworm/main/installer-amd64/current/images/netboot/netboot.tar.gz

# debian 13 - trixie
wget https://mirrors.ustc.edu.cn/debian/dists/trixie/main/installer-amd64/current/images/netboot/netboot.tar.gz

bios 目录下放置 Legacy BIOS 启动文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# pxelinux.0 → ldlinux.c32 → pxelinux.cfg → kernel
cp /srv/tftp/debian/{pxelinux.0,ldlinux.c32,splash.png} /srv/tftp/bios/
cp /srv/tftp/debian/debian-installer/amd64/boot-screens/{vesamenu.c32,libcom32.c32,libutil.c32} /srv/tftp/bios/

mkdir -p /srv/tftp/bios/debian13
# default -> debian12
cp /srv/tftp/debian/debian-installer/amd64/{linux,initrd.gz} /srv/tftp/bios/

mkdir -p /srv/tftp/bios/pxelinux.cfg
touch /srv/tftp/bios/pxelinux.cfg/default

bios/pxelinux.cfg/default 文件内容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# /srv/tftp/bios/pxelinux.cfg/default
PROMPT 0
TIMEOUT 50
default vesamenu.c32

MENU TITLE PXE Boot Menu
MENU BACKGROUND splash.png

LABEL debian12
    MENU default
    MENU LABEL ^Automated Debian 12 Install
    KERNEL linux
    APPEND initrd=initrd.gz url=http://192.168.99.30/preseed/preseed-debian12-bios.cfg interface=auto auto=true priority=critical DEBCONF_DEBUG=5
LABEL debian13
    MENU LABEL ^Automated Debian 13 Install
    KERNEL linux
    APPEND initrd=initrd.gz url=http://192.168.99.30/preseed/preseed-debian13-bios.cfg interface=auto auto=true priority=critical DEBCONF_DEBUG=5
LABEL local
    menu label ^Boot from Local Disk
    localboot 0
    timeout 50
1
cp -a /srv/tftp/debian/debian-installer/ /srv/tftp/

grub.cfg GRUB 配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# vim /srv/tftp/debian-installer/amd64/grub/grub.cfg
set default=0
set timeout=5

menuentry "Automated Debian 12 Install" {
  linux /debian-installer/amd64/linux auto=true priority=critical url=http://10.10.10.30:8080/preseed/preseed-debian12-efi.cfg
  initrd /debian-installer/amd64/initrd.gz
}

menuentry "Automated Debian 13 Install" {
  linux /debian-installer/amd64/linux auto=true priority=critical url=http://10.10.10.30:8080/preseed/preseed-debian13-efi.cfg
  initrd /debian-installer/amd64/initrd.gz
}

/srv/www/preseed/preseed-debian12-bios.cfg 配置文件编辑

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# vim /srv/www/preseed/preseed-debian12-bios.cfg
# 设置非交互模式和关键优先级
d-i debconf debconf/priority select critical
d-i debconf debconf/frontend select noninteractive

# ==================== 禁用CD-ROM检测 ====================
d-i cdrom-detect/cdrom_mounted boolean true
d-i cdrom-detect/try-hd boolean true
d-i cdrom-detect/hd-mount boolean true
d-i apt-setup/cdrom/set-first boolean false
d-i apt-setup/cdrom/set-double boolean false
d-i apt-setup/cdrom/set-failed boolean false

# ==================== 本地化设置 ====================
d-i debian-installer/language string en
d-i debian-installer/country string CN
d-i debian-installer/locale string en_US.UTF-8
d-i localechooser/supported-locales multiselect en_US.UTF-8, zh_CN.UTF-8

# 键盘布局
d-i keyboard-configuration/xkb-keymap select us
d-i keyboard-configuration/variant select us

# ==================== 网络设置 ====================
d-i netcfg/choose_interface select auto
d-i netcfg/dhcp_timeout string 60
d-i netcfg/get_hostname string debian
d-i netcfg/get_domain string localdomain
d-i netcfg/wireless_show_essids select manual

# ==================== 镜像源设置 ====================
#d-i mirror/protocol string http
#d-i mirror/country string manual
#d-i mirror/http/hostname string 10.10.10.30:8080
#d-i mirror/http/directory string /debian12/
#d-i mirror/http/proxy string
# -> http://10.10.10.30:8080/debian12/dists/stable/Release

# 跳过镜像选择对话框
d-i mirror/skip-question boolean true

d-i mirror/country string manual
d-i mirror/http/hostname string deb.debian.org
#d-i mirror/http/hostname string mirrors.ustc.edu.cn
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

# 指定 Debian 版本为 13 (trixie) / 12 (bookworm)
d-i mirror/suite string bookworm
#d-i mirror/suite string trixie

# ==================== 时区和时钟 ====================
d-i clock-setup/utc boolean true
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string ntp.aliyun.com

# 分区
d-i partman-auto/method string lvm
# 选择要分区的磁盘
d-i partman-auto/disk string /dev/sda
# 使用整个磁盘
d-i partman-auto-lvm/guided_size string max
# 使用 XFS 文件系统(默认)
d-i partman/default_filesystem string xfs
# 使用 MSDOS 分区表格式(MBR)
d-i partman-partitioning/choose_label string msdos

# 自定义服务器分区
# 分区方案名称 :: \
#     最小大小 优先大小 最大大小 文件系统类型 \
#         标志{ } \
#         方法{ 方法 } 格式化{ } \
#         使用文件系统{ } 文件系统{ 文件系统类型 } \
#         挂载点{ 挂载点 } \
#     . \
# 自定义分区方案:boot 500MB, swap 2GB, / 剩余全部
d-i partman-auto/expert_recipe string \
    lvm :: \
        500 500 500 ext4 \
            $primary{ } $bootable{ } \
            method{ format } format{ } \
            use_filesystem{ } filesystem{ ext4 } \
            mountpoint{ /boot } \
        . \
        2048 2048 2048 linux-swap \
            $lvmok{ } \
            method{ swap } format{ } \
        . \
        100% 100% 100% xfs \
            $lvmok{ } \
            method{ format } format{ } \
            use_filesystem{ } filesystem{ xfs } \
            mountpoint{ / } \
        .

# 删除现有分区和 LVM
d-i partman-lvm/device_remove_lvm boolean true
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/choose_partition select finish
d-i partman/confirm boolean true

# ==================== 用户账户 ====================
# Root用户
d-i passwd/root-login boolean true
d-i passwd/root-password password luck
d-i passwd/root-password-again password luck

# 普通用户(可选)
d-i passwd/user-fullname string luck
d-i passwd/username string luck
d-i passwd/user-password password luck
d-i passwd/user-password-again password luck
d-i passwd/user-uid string 1000

# ==================== 软件包安装 ====================
# 禁用流行度调查
popularity-contest popularity-contest/participate boolean false
d-i apt-setup/services-select multiselect security, updates
d-i apt-setup/security_host string security.debian.org

# 软件包选择
tasksel tasksel/first multiselect standard, ssh-server
d-i pkgsel/include string openssh-server vim curl wget sudo net-tools
d-i pkgsel/upgrade select full-upgrade
d-i pkgsel/update-policy select none
d-i pkgsel/updatedb boolean true

# ==================== GRUB引导器 ====================
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string /dev/sda

# ==================== 完成安装 ====================
d-i finish-install/reboot_in_progress note
d-i cdrom-detect/eject boolean true

/srv/www/preseed/preseed-debian13-bios.cfg 配置文件编辑

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# vim /srv/www/preseed/preseed-debian13-bios.cfg
# 设置非交互模式和关键优先级
d-i debconf debconf/priority select critical
d-i debconf debconf/frontend select noninteractive

# ==================== 禁用CD-ROM检测 ====================
d-i cdrom-detect/cdrom_mounted boolean true
d-i cdrom-detect/try-hd boolean true
d-i cdrom-detect/hd-mount boolean true
d-i apt-setup/cdrom/set-first boolean false
d-i apt-setup/cdrom/set-double boolean false
d-i apt-setup/cdrom/set-failed boolean false

# ==================== 本地化设置 ====================
d-i debian-installer/language string en
d-i debian-installer/country string CN
d-i debian-installer/locale string en_US.UTF-8
d-i localechooser/supported-locales multiselect en_US.UTF-8, zh_CN.UTF-8

# 键盘布局
d-i keyboard-configuration/xkb-keymap select us
d-i keyboard-configuration/variant select us

# ==================== 网络设置 ====================
d-i netcfg/choose_interface select auto
d-i netcfg/dhcp_timeout string 60
d-i netcfg/get_hostname string debian
d-i netcfg/get_domain string localdomain
d-i netcfg/wireless_show_essids select manual

# ==================== 镜像源设置 ====================
#d-i mirror/protocol string http
#d-i mirror/country string manual
#d-i mirror/http/hostname string 10.10.10.30:8080
#d-i mirror/http/directory string /debian12/
#d-i mirror/http/proxy string
# -> http://10.10.10.30:8080/debian12/dists/stable/Release

# 跳过镜像选择对话框
d-i mirror/skip-question boolean true

d-i mirror/country string manual
d-i mirror/http/hostname string deb.debian.org
#d-i mirror/http/hostname string mirrors.ustc.edu.cn
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

# 指定 Debian 版本为 13 (trixie) / 12 (bookworm)
#d-i mirror/suite string bookworm
d-i mirror/suite string trixie

# ==================== 时区和时钟 ====================
d-i clock-setup/utc boolean true
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string ntp.aliyun.com

# 分区
d-i partman-auto/method string lvm
# 选择要分区的磁盘
d-i partman-auto/disk string /dev/sda
# 使用整个磁盘
d-i partman-auto-lvm/guided_size string max
# 使用 XFS 文件系统(默认)
d-i partman/default_filesystem string xfs
# 使用 MSDOS 分区表格式(MBR)
d-i partman-partitioning/choose_label string msdos

# 自定义服务器分区
# 分区方案名称 :: \
#     最小大小 优先大小 最大大小 文件系统类型 \
#         标志{ } \
#         方法{ 方法 } 格式化{ } \
#         使用文件系统{ } 文件系统{ 文件系统类型 } \
#         挂载点{ 挂载点 } \
#     . \
# 自定义分区方案:boot 500MB, swap 2GB, / 剩余全部
d-i partman-auto/expert_recipe string \
    lvm :: \
        500 500 500 ext4 \
            $primary{ } $bootable{ } \
            method{ format } format{ } \
            use_filesystem{ } filesystem{ ext4 } \
            mountpoint{ /boot } \
        . \
        2048 2048 2048 linux-swap \
            $lvmok{ } \
            method{ swap } format{ } \
        . \
        100% 100% 100% xfs \
            $lvmok{ } \
            method{ format } format{ } \
            use_filesystem{ } filesystem{ xfs } \
            mountpoint{ / } \
        .

# 删除现有分区和 LVM
d-i partman-lvm/device_remove_lvm boolean true
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/choose_partition select finish
d-i partman/confirm boolean true

# ==================== 用户账户 ====================
# Root用户
d-i passwd/root-login boolean true
d-i passwd/root-password password luck
d-i passwd/root-password-again password luck

# 普通用户(可选)
d-i passwd/user-fullname string luck
d-i passwd/username string luck
d-i passwd/user-password password luck
d-i passwd/user-password-again password luck
d-i passwd/user-uid string 1000

# ==================== 软件包安装 ====================
# 禁用流行度调查
popularity-contest popularity-contest/participate boolean false
d-i apt-setup/services-select multiselect security, updates
d-i apt-setup/security_host string security.debian.org

# 软件包选择
tasksel tasksel/first multiselect standard, ssh-server
d-i pkgsel/include string openssh-server vim curl wget sudo net-tools
d-i pkgsel/upgrade select full-upgrade
d-i pkgsel/update-policy select none
d-i pkgsel/updatedb boolean true

# ==================== GRUB引导器 ====================
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string /dev/sda

# ==================== 完成安装 ====================
d-i finish-install/reboot_in_progress note
d-i cdrom-detect/eject boolean true
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# vim /srv/www/preseed/preseed-debian12-efi.cfg
# 设置非交互模式和关键优先级
d-i debconf debconf/priority select critical
d-i debconf debconf/frontend select noninteractive

# ==================== 禁用CD-ROM检测 ====================
d-i cdrom-detect/cdrom_mounted boolean true
d-i cdrom-detect/try-hd boolean true
d-i cdrom-detect/hd-mount boolean true
d-i apt-setup/cdrom/set-first boolean false
d-i apt-setup/cdrom/set-double boolean false
d-i apt-setup/cdrom/set-failed boolean false

# ==================== 本地化设置 ====================
d-i debian-installer/language string en
d-i debian-installer/country string CN
d-i debian-installer/locale string en_US.UTF-8
d-i localechooser/supported-locales multiselect en_US.UTF-8, zh_CN.UTF-8

# 键盘布局
d-i keyboard-configuration/xkb-keymap select us
d-i keyboard-configuration/variant select us

# ==================== 网络设置 ====================
d-i netcfg/choose_interface select auto
d-i netcfg/dhcp_timeout string 60
d-i netcfg/get_hostname string debian
d-i netcfg/get_domain string localdomain
d-i netcfg/wireless_show_essids select manual

# ==================== 镜像源设置 ====================
#d-i mirror/protocol string http
#d-i mirror/country string manual
#d-i mirror/http/hostname string 10.10.10.30:8080
#d-i mirror/http/directory string /debian12/
#d-i mirror/http/proxy string
# -> http://10.10.10.30:8080/debian12/dists/stable/Release

# 跳过镜像选择对话框
d-i mirror/skip-question boolean true

d-i mirror/country string manual
#d-i mirror/http/hostname string deb.debian.org
d-i mirror/http/hostname string mirrors.ustc.edu.cn
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

# 指定 Debian 版本为 13 (trixie) / 12 (bookworm)
d-i mirror/suite string bookworm
#d-i mirror/suite string trixie

# ==================== 时区和时钟 ====================
d-i clock-setup/utc boolean true
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string ntp.aliyun.com

# 分区
d-i partman-auto/method string lvm
# 选择要分区的磁盘
d-i partman-auto/disk string /dev/sda
# 使用整个磁盘
d-i partman-auto-lvm/guided_size string max
# 使用 XFS 文件系统(默认)
d-i partman/default_filesystem string xfs
# msdos - 使用 MSDOS 分区表格式(MBR)
# gpt - GUID Partition Table(现代分区表,支持 EFI/UEFI 和大于 2TB 磁盘)
d-i partman-partitioning/choose_label string gpt

# 自定义服务器分区
# 分区方案名称 :: \
#     最小大小 优先大小 最大大小 文件系统类型 \
#         标志{ } \
#         方法{ 方法 } 格式化{ } \
#         使用文件系统{ } 文件系统{ 文件系统类型 } \
#         挂载点{ 挂载点 } \
#     . \
# $lvmok{ } 不是文件系统类型,也不是大小,它只是告诉 installer:“这个分区可以加入卷组 (VG) 并创建逻辑卷 (LV)”。
# 自定义分区方案:boot 500MB, swap 2GB, / 剩余全部
d-i partman-auto/expert_recipe string \
    lvm :: \
       512 512 512 fat32 \
            $primary{ } $bootable{ } \
            method{ efi } format{ } \
            mountpoint{ /boot/efi } label{ efi } \
        . \
        512 512 512 ext4 \
            $primary{ } \
            method{ format } format{ } \
            use_filesystem{ } filesystem{ ext4 } \
            mountpoint{ /boot } \
        . \
        2048 2048 2048 linux-swap \
            method{ swap } format{ } \
        . \
        100% 100% -1 xfs \
            $lvmok{ } \
            method{ format } format{ } \
            use_filesystem{ } filesystem{ xfs } \
            mountpoint{ / } \
        .

# 删除现有分区和 LVM
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/confirm boolean true

# 清空磁盘分区表
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true

# ==================== 用户账户 ====================
# Root用户
d-i passwd/root-login boolean true
d-i passwd/root-password password luck
d-i passwd/root-password-again password luck

# 普通用户(可选)
d-i passwd/user-fullname string luck
d-i passwd/username string luck
d-i passwd/user-password password luck
d-i passwd/user-password-again password luck
d-i passwd/user-uid string 1000

# ==================== 软件包安装 ====================
# 禁用流行度调查
popularity-contest popularity-contest/participate boolean false
d-i apt-setup/services-select multiselect security, updates
d-i apt-setup/security_host string security.debian.org

# 软件包选择
tasksel tasksel/first multiselect standard, ssh-server
d-i pkgsel/include string openssh-server vim curl wget sudo net-tools
d-i pkgsel/upgrade select full-upgrade
d-i pkgsel/update-policy select none
d-i pkgsel/updatedb boolean true

# ==================== GRUB引导器 ====================
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string /dev/sda

# ==================== 完成安装 ====================
d-i finish-install/reboot_in_progress note
d-i cdrom-detect/eject boolean true
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# vim /srv/www/preseed/preseed-debian12-efi.cfg
# 设置非交互模式和关键优先级
d-i debconf debconf/priority select critical
d-i debconf debconf/frontend select noninteractive

# ==================== 禁用CD-ROM检测 ====================
d-i cdrom-detect/cdrom_mounted boolean true
d-i cdrom-detect/try-hd boolean true
d-i cdrom-detect/hd-mount boolean true
d-i apt-setup/cdrom/set-first boolean false
d-i apt-setup/cdrom/set-double boolean false
d-i apt-setup/cdrom/set-failed boolean false

# ==================== 本地化设置 ====================
d-i debian-installer/language string en
d-i debian-installer/country string CN
d-i debian-installer/locale string en_US.UTF-8
d-i localechooser/supported-locales multiselect en_US.UTF-8, zh_CN.UTF-8

# 键盘布局
d-i keyboard-configuration/xkb-keymap select us
d-i keyboard-configuration/variant select us

# ==================== 网络设置 ====================
d-i netcfg/choose_interface select auto
d-i netcfg/dhcp_timeout string 60
d-i netcfg/get_hostname string debian
d-i netcfg/get_domain string localdomain
d-i netcfg/wireless_show_essids select manual

# ==================== 镜像源设置 ====================
#d-i mirror/protocol string http
#d-i mirror/country string manual
#d-i mirror/http/hostname string 10.10.10.30:8080
#d-i mirror/http/directory string /debian12/
#d-i mirror/http/proxy string
# -> http://10.10.10.30:8080/debian12/dists/stable/Release

# 跳过镜像选择对话框
d-i mirror/skip-question boolean true

d-i mirror/country string manual
#d-i mirror/http/hostname string deb.debian.org
d-i mirror/http/hostname string mirrors.ustc.edu.cn
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

# 指定 Debian 版本为 13 (trixie) / 12 (bookworm)
#d-i mirror/suite string bookworm
d-i mirror/suite string trixie

# ==================== 时区和时钟 ====================
d-i clock-setup/utc boolean true
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string ntp.aliyun.com

# 分区
d-i partman-auto/method string lvm
# 选择要分区的磁盘
d-i partman-auto/disk string /dev/sda
# 使用整个磁盘
d-i partman-auto-lvm/guided_size string max
# 使用 XFS 文件系统(默认)
d-i partman/default_filesystem string xfs
# msdos - 使用 MSDOS 分区表格式(MBR)
# gpt - GUID Partition Table(现代分区表,支持 EFI/UEFI 和大于 2TB 磁盘)
d-i partman-partitioning/choose_label string gpt

# 自定义服务器分区
# 分区方案名称 :: \
#     最小大小 优先大小 最大大小 文件系统类型 \
#         标志{ } \
#         方法{ 方法 } 格式化{ } \
#         使用文件系统{ } 文件系统{ 文件系统类型 } \
#         挂载点{ 挂载点 } \
#     . \
# $lvmok{ } 不是文件系统类型,也不是大小,它只是告诉 installer:“这个分区可以加入卷组 (VG) 并创建逻辑卷 (LV)”。
# 自定义分区方案:boot 500MB, swap 2GB, / 剩余全部
d-i partman-auto/expert_recipe string \
    lvm :: \
       512 512 512 fat32 \
            $primary{ } $bootable{ } \
            method{ efi } format{ } \
            mountpoint{ /boot/efi } label{ efi } \
        . \
        512 512 512 ext4 \
            $primary{ } \
            method{ format } format{ } \
            use_filesystem{ } filesystem{ ext4 } \
            mountpoint{ /boot } \
        . \
        2048 2048 2048 linux-swap \
            method{ swap } format{ } \
        . \
        100% 100% -1 xfs \
            $lvmok{ } \
            method{ format } format{ } \
            use_filesystem{ } filesystem{ xfs } \
            mountpoint{ / } \
        .

# 删除现有分区和 LVM
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/confirm boolean true

# 清空磁盘分区表
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true

# ==================== 用户账户 ====================
# Root用户
d-i passwd/root-login boolean true
d-i passwd/root-password password luck
d-i passwd/root-password-again password luck

# 普通用户(可选)
d-i passwd/user-fullname string luck
d-i passwd/username string luck
d-i passwd/user-password password luck
d-i passwd/user-password-again password luck
d-i passwd/user-uid string 1000

# ==================== 软件包安装 ====================
# 禁用流行度调查
popularity-contest popularity-contest/participate boolean false
d-i apt-setup/services-select multiselect security, updates
d-i apt-setup/security_host string security.debian.org

# 软件包选择
tasksel tasksel/first multiselect standard, ssh-server
d-i pkgsel/include string openssh-server vim curl wget sudo net-tools
d-i pkgsel/upgrade select full-upgrade
d-i pkgsel/update-policy select none
d-i pkgsel/updatedb boolean true

# ==================== GRUB引导器 ====================
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string /dev/sda

# ==================== 完成安装 ====================
d-i finish-install/reboot_in_progress note
d-i cdrom-detect/eject boolean true

相关内容