Debian10.7 自动化安装镜像制作
FAI是用于Linux的无人值守大规模部署的工具
具体方法可以参考https://fai-project.org/其官方站点
(图片可放大查看)
其在线打包的功能相当方便
https://fai-project.org/FAIme/
(图片可放大查看)
Debian 安装程序支持使用预先配置的文件(preseed)进行自动安装。preseed预置文件可以从网络或移动介质上加载,并自动回答安装过程中的问题
具体步骤:从原始的ISO映像中提取initrd,将预置文件preseed添加到initrd,最后再封装创建一个新可引导的自动化安装的ISO映像
(图片可放大查看)
(图片可放大查看)
还有一种是Simple-CDD方式 The All-In-One Solution
(图片可放大查看)
我采用的是第二种 在preseed.cfg脚本编写上踩坑无数,经过20多次的debian自动化安装镜像打包和安装验证测试, debian10.7自动化安装终于搞定了
具体的操作步骤如下
https://cdimage.debian.org/debian-cd/current/amd64/bt-dvd/
用于制作镜像 我这边安装成了图形化界面模式,当然安装命令行模式也是一样 安装过程就不详细描述了,参考之前的文章图解Debian10Linux系统的安装步骤
Debian10.7的apt源配置参考之前的文章几种常用Linux系统的软件镜像源配置
安装镜像制作相关的软件包工具
apt install vim lrzsz
apt install debconf-utils
apt install whois
#[whois工具包用于mkpasswd生成root密码的密文]
apt install bsdtar
apt install genisoimage
脚本主要说明
当然你可以根据自身需要进行定制,修改脚本
vi preseed.cfg
添加如下内容
# US locale/kbd map
d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
# automatically select network interface
d-i netcfg/choose_interface select auto
d-i netcfg/disable_dhcp boolean true
d-i netcfg/disable_autoconfig boolean true
d-i netcfg/get_ipaddress string 192.168.100.100
d-i netcfg/get_nameservers string 223.5.5.5
d-i netcfg/get_netmask string 255.255.255.0
d-i netcfg/get_gateway string 192.168.100.254
d-i netcfg/confirm_static boolean true
# set host and domain
d-i netcfg/get_hostname string debian
d-i netcfg/get_domain string walkingcloud.cn
# disable WEP dialogue
d-i netcfg/wireless_wep string
# use http.us.debian.org as mirror with no proxy
d-i mirror/country string manual
d-i mirror/http/hostname string mirrors.cloud.tencent.com
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
# don't make a regular user / set root password
d-i passwd/make-user boolean false
# mkpasswd -m sha-512 <pwd>
d-i passwd/root-password-crypted password $6$zRyZgBe.MEy$fDGbMeV/4DHSuVrCepJC6Md4adDkV9jKjAXaaEHBhx8xs/AmTcoBo80AsYC3gyuoJX/ww2zNGdi1oYQkkd9KN/
d-i passwd/root-login boolean true
d-i clock-setup/utc boolean true
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp boolean false
d-i clock-setup/ntp-server string cn.pool.ntp.org
### Partitioning
d-i preseed/early_command string anna-install fdisk-udeb
# use lvm partitioning
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
# make lvm the max size
d-i partman-auto-lvm/guided_size string max
d-i partman-auto-lvm/new_vg_name string debian
# use the following partition scheme on /dev/sda
#d-i partman-auto/disk string /dev/sda
d-i partman/early_command string debconf-set partman-auto/disk "$(list-devices disk | head -n1)"
d-i partman-auto/choose_recipe select boot-lvm
# /boot 500M ext4
# /home 20G ext4
# / 20G+ ext4
d-i partman-auto/expert_recipe string \
boot-lvm :: \
500 500 500 ext4 \
$primary{ } $bootable{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ /boot } \
. \
20480 20480 20480 ext4 \
$lvmok{ } \
lv_name{ lv_home } in_vg { debian } \
$primary{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ /home } \
. \
20480 20480 -1 ext4 \
$lvmok{ } \
lv_name{ lv_root } in_vg { debian } \
$primary{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ / } \
.
# remove any RAID partitioning
d-i partman-md/device_remove_md boolean true
# don't confirm anything
d-i partman-basicfilesystems/no_mount_point boolean false
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
# disable swap warning
d-i partman-basicfilesystems/no_swap boolean false
# install standard system with ssh-server
tasksel tasksel/first multiselect standard, ssh-server
# also install other package
d-i pkgsel/include string htop net-tools vim wget iftop iotop
# upgrade all packages
d-i pkgsel/upgrade select full-upgrade
# disable popularity contest
popularity-contest popularity-contest/participate boolean false
# Uncomment this if you don't want to use a network mirror.
#d-i apt-setup/use_mirror boolean false
d-i apt-setup/no_mirror boolean true
d-i apt-setup/use_mirror boolean false
d-i apt-setup/contrib boolean false
d-i apt-setup/non-free boolean false
d-i apt-setup/cdrom/set-next boolean false
d-i apt-setup/services-select multiselect
# force grub install to /dev/sda
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 grub-installer/bootdev string default
#d-i grub-installer/early_command string debconf-set grub-installer/bootdev "$(list-devices disk | head -n1)"
# don't wait for confirm, just reboot when finished
d-i finish-install/reboot_in_progress note
d-i preseed/late_command string \
cp -vrf /cdrom/tools/* /target/home/ ; \
sed -i "s/^#PermitRootLogin.*\$/PermitRootLogin yes/g" /target/etc/ssh/sshd_config ;
其中mkpasswd -m sha-512 <pwd>用于获取root密码密文
(图片可放大查看)
/opt/preseed_debian_iso_make目录下创建 make_iso.sh
(图片可放大查看)
脚本来源自github
#!/bin/bash
temp_dir="isofiles"
if [ $# -ne 2 ]; then
echo usage $0 ISO preseed.cfg
exit 1
fi
source_iso=$1
source_iso_name=$(basename $source_iso)
preseed=$2
[ -f "$source_iso" ] || (echo source_iso does not exist && exit 1)
[ -f "$preseed" ] || (echo preseed does not exist && exit 1)
if [ ! -d "$temp_dir" ]; then
mkdir -p "$temp_dir"
bsdtar -C "$temp_dir" -xf "$source_iso"
gunzip "$temp_dir"/install.amd/initrd.gz
echo "$preseed" | cpio -H newc -o -A -F "$temp_dir"/install.amd/initrd
gzip "$temp_dir"/install.amd/initrd
fi
sed -i 's/^timeout.*/timeout 1/' "$temp_dir"/isolinux/isolinux.cfg
cat >"$temp_dir"/isolinux/menu.cfg <<EOF
menu hshift 4
menu width 70
menu title Debian GNU/Linux installer menu (BIOS mode)
include stdmenu.cfg
include txt.cfg
EOF
cat >"$temp_dir"/isolinux/txt.cfg <<EOF
label install
menu label ^AutoInstall Debian10.7 DIY-OS v1(cdrom)
menu default
kernel /install.amd/vmlinuz
append vga=788 auto=true priority=critical file=/preseed.cfg initrd=/install.amd/initrd.gz --- quiet
default install
EOF
\cp -vrf packages_add/*.deb $temp_dir/tools/
\cp -vrf packages_add/*.sh $temp_dir/tools/
md5sum `find $temp_dir -follow -type f` > "$temp_dir"/md5sum.txt
genisoimage -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o "preseed-$source_iso_name" "$temp_dir"/
#rm -r "$temp_dir"
其中packages_add目录为额外的工具包或者系统优化脚本
用于自动化安装完成后,若有需要,可以手动dpkg安装这些工具包以及执行该系统优化脚本
sh -x make_iso.sh /root/debian-10.7.0-amd64-DVD-1.iso preseed.cfg
sh -x可以看到脚本执行过程
(图片可放大查看)
(图片可放大查看)
这里用SFTP方式下载打好的镜像包 preseed-debian-10.7.0-amd64-DVD-1.iso
(图片可放大查看)
创建虚拟机测试
(图片可放大查看)
从光盘启动,无需手工干预
安装过程截图
(图片可放大查看)
ip addr 可以看到分区与IP与定制的preseed.cfg文件中一致
(图片可放大查看)
(图片可放大查看)
cd /home
dpkg --install lrzsz_0.12.21-10_amd64.deb ncdu_1.13-1+b1_amd64.deb nmon_16i+debian-2_amd64.deb
(图片可放大查看)
(图片可放大查看)
(图片可放大查看)
(图片可放大查看)
本文分享自 WalkingCloud 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!