点击上方"walkingcloud"关注
Debian10.7 自动化安装镜像制作一、debian的自动化安装方式介绍第一种、FAI方式自动电脑化安装FAI是用于Linux的无人值守大规模部署的工具
具体方法可以参考https://fai-project.org/其官方站点
(图片可放大查看)
其在线打包的功能相当方便
https://fai-project.org/FAIme/
(图片可放大查看)
第二种、preseed预置文件方式完成自动化安装Debian 安装程序支持使用预先配置的文件(preseed)进行自动安装。preseed预置文件可以从网络或移动介质上加载,并自动回答安装过程中的问题
具体步骤:从原始的ISO映像中提取initrd,将预置文件preseed添加到initrd,最后再封装创建一个新可引导的自动化安装的ISO映像
电脑(图片可放大查看)
(图片可放大查看)
Simple-CDD方式还有一种是Simple-CDD方式 The All-In-One Solution
(图片可放大查看)
我采用的是第二种 在preseed.cfg脚本编写上踩坑无数,经过20多次的debian自动化安装镜像打包和安装验证测试, debian10.7自动化安装终于搞定了
二、Debian10.7 preseed自动化安装镜像制作步骤具体的操作步骤如下
1、debian官网下载debian10.7的完整版镜像文件https://cdimage.debian.org/debian-cd/current/amd64/bt-dvd/
1)种子文件的方式下载更快 2)只用下载第一张:DVD1电脑2、安装debian虚拟机用于制作镜像 我这边安装成了图形化界面模式,当然安装命令行模式也是一样 安装过程就不详细描述了,参考之前的文章图解Debian10Linux系统的安装步骤
3、配置apt源,并安装镜像制作相关的软件包工具Debian10.7的apt源配置参考之前的文章几种常用Linux系统的软件镜像源配置
安装镜像制作相关的软件包工具
apt install vim lrzsz apt install debconf-utils apt install whois #[whois工具包用于mkpasswd生成root密码的密文] apt install bsdtar apt install genisoimage
4、preseed.cfg脚本
脚本主要说明
1、网卡默认静态地址192.168.100.100/24 2、主机名debian,域walkingcloud.cn 3、时区Asia/Shanghai 4、分区为LVM方案 *# /boot 500M ext4 *# /home 20G ext4 LVM *# / 20G+ ext4 LVM 5、自动安装htop net-tools vim wget iftop iotop这些常用工具包6、preseed/late_command安装后执行命令实现root用户可以直接SSH登录 7、mkpasswd -m sha-512设置root用户密码当然你可以根据自身需要进行定制,修改脚本
vi preseed.cfg添加如下内容 # US locale/kbd mapd-i debian-installer/locale string en_USd-i keyboard-configuration/xkb-keymap select us# automatically select network interfaced-i netcfg/choose_interface select autod-i netcfg/disable_dhcp boolean trued-i netcfg/disable_autoconfig boolean trued-i netcfg/get_ipaddress string 192.168.100.100d-i netcfg/get_nameservers string 223.5.5.5d-i netcfg/get_netmask string 255.255.255.0d-i netcfg/get_gateway string 192.168.100.254d-i netcfg/confirm_static boolean true# set host and domaind-i netcfg/get_hostname string debiand-i netcfg/get_domain string walkingcloud.cn# disable WEP dialogued-i netcfg/wireless_wep string# use http.us.debian.org as mirror with no proxyd-i mirror/country string manuald-i mirror/http/hostname string mirrors.cloud.tencent.comd-i mirror/http/directory string /debiand-i mirror/http/proxy string # don't make a regular user / set root passwordd-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 trued-i clock-setup/utc boolean trued-i time/zone string Asia/Shanghaid-i clock-setup/ntp boolean falsed-i clock-setup/ntp-server string cn.pool.ntp.org### Partitioningd-i preseed/early_command string anna-install fdisk-udeb # use lvm partitioningd-i partman-auto/method string lvmd-i partman-lvm/device_remove_lvm boolean trued-i partman-lvm/confirm boolean trued-i partman-lvm/confirm_nooverwrite boolean true# make lvm the max sized-i partman-auto-lvm/guided_size string maxd-i partman-auto-lvm/new_vg_name string debian# use the following partition scheme on /dev/sda#d-i partman-auto/disk string /dev/sdad-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+ ext4d-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 partitioningd-i partman-md/device_remove_md boolean true# don't confirm anythingd-i partman-basicfilesystems/no_mount_point boolean falsed-i partman-partitioning/confirm_write_new_label boolean trued-i partman/choose_partition select finishd-i partman-auto/purge_lvm_from_device boolean trued-i partman-lvm/device_remove_lvm boolean trued-i partman/confirm boolean trued-i partman/confirm_nooverwrite boolean true# disable swap warningd-i partman-basicfilesystems/no_swap boolean false# install standard system with ssh-servertasksel tasksel/first multiselect standard, ssh-server# also install other packaged-i pkgsel/include string htop net-tools vim wget iftop iotop # upgrade all packagesd-i pkgsel/upgrade select full-upgrade# disable popularity contestpopularity-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 falsed-i apt-setup/no_mirror boolean trued-i apt-setup/use_mirror boolean falsed-i apt-setup/contrib boolean falsed-i apt-setup/non-free boolean falsed-i apt-setup/cdrom/set-next boolean falsed-i apt-setup/services-select multiselect# force grub install to /dev/sdad-i grub-installer/only_debian boolean trued-i grub-installer/with_other_os boolean true#d-i grub-installer/bootdev string /dev/sdad-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 finishedd-i finish-install/reboot_in_progress noted-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密码密文
(图片可放大查看)
5、iso制作脚本make_iso.sh/opt/preseed_debian_iso_make目录下创建 make_iso.sh
(图片可放大查看)
脚本来源自github
#!/bin/bashtemp_dir="isofiles"if [ $# -ne 2 ]; then echo usage $0 ISO preseed.cfg exit 1fisource_iso=$1source_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/initrdfised -i 's/^timeout.*/timeout 1/' "$temp_dir"/isolinux/isolinux.cfgcat >"$temp_dir"/isolinux/menu.cfg <<EOFmenu hshift 4menu width 70menu title Debian GNU/Linux installer menu (BIOS mode)include stdmenu.cfginclude txt.cfgEOFcat >"$temp_dir"/isolinux/txt.cfg <<EOFlabel 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 --- quietdefault installEOF\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.txtgenisoimage -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安装这些工具包以及执行该系统优化脚本
7、制作镜像sh -x make_iso.sh /root/debian-10.7.0-amd64-DVD-1.iso preseed.cfg
sh -x可以看到脚本执行过程
(图片可放大查看)
(图片可放大查看)
8、下载ISO镜像文件并创建虚拟机测试镜像这里用SFTP方式下载打好的镜像包 preseed-debian-10.7.0-amd64-DVD-1.iso
(图片可放大查看)
创建虚拟机测试
(图片可放大查看)
9、全程自动化安装从光盘启动,无需手工干预
安装过程截图
(图片可放大查看)
10、安装完成后登录验证1)分区与网络ip addr 可以看到分区与IP与定制的preseed.cfg文件中一致
(图片可放大查看)
2)htop工具(图片可放大查看)
3)home目录也有额外的工具包或者系统优化脚本cd /home
dpkg --install lrzsz_0.12.21-10_amd64.deb ncdu_1.13-1+b1_amd64.deb nmon_16i+debian-2_amd64.deb
(图片可放大查看)
(图片可放大查看)
4)Env4Buster.sh 系统优化脚本(图片可放大查看)
(图片可放大查看)
本文完成过程参考如下文档1、https://salsa.debian.org/installer-team/debian-installer/tree/master/doc/devel 2、https://salsa.debian.org/installer-team/debian-installer/-/raw/master/doc/devel/partman-auto-recipe.txt 3、preseed预置例子文件 https://www.debian.org/releases/buster/example-preseed.txt 4、debian安装手册之使用预置自动进行安装 https://www.debian.org/releases/stable/amd64/ch04s06.zh-cn.html https://www.debian.org/releases/stable/amd64/apb.zh-cn.html https://www.debian.org/releases/stable/amd64/apbs04.zh-cn.html5、debian管理员手册及Preseed的wiki参考文档 https://wiki.debian.org/DebianInstaller/Preseed https://www.debian.org/doc/manuals/debian-handbook/sect.automated-installation.zh-cn.html https://wiki.debian.org/DebianInstaller/Preseed/EditIso6、使用 build-simple-cdd 快速定制 Debian 安装盘 https://my.oschina.net/anglix/blog/506702 制作Debian的Preseed自动安装U盘版 https://my.oschina.net/anglix/blog/5012357、https://github.com/Mazhive/fs-uae-autoboot-debian108、打包测试中遇到问题时搜索到的相关问题链接https://askubuntu.com/questions/935565/install-openssh-server-package-from-preseed-file https://community.theforeman.org/t/no-root-file-system-is-defined-error-using-preseed-atomic-partitioning-scheme/5969/8电脑