ubuntu、debian是用的debian-installer程序进行无人值的,通常是preseed.cfg文件
ubuntu16官方文档:
挂载镜像
本地先手动安装镜像ubuntu-16.04-server-amd64.iso,测试该镜像对于当前的硬件环境是否正常兼容
将该镜像挂载到Linux系统中,通过对镜像内容编辑,用linux命令mkisofs生成修改后的镜像
mkdir /mnt/iso#创建挂载点mount /dev/sr0 /mnt/iso#挂载mkdir -p /work#创建/work目录, 用于存放iso目录cp /mnt/iso /work/ubuntuchmod a+w -R /work/ubuntu#复制用于编辑cp /work/ubuntu /work/ubuntu_bak#备份
修改文件
修改isolinux/isolinux.cfg
# pathinclude menu.cfgdefault vesamenu.c32prompt 0timeout 0#ui gfxboot bootlogo
isolinux.cfg会加载menu.cfg文件,该文件又会加载txt.cfg。我们需要修改txt.cfg文件
:::info ubuntu无需设置卷标,直接/cdrom/路径开头就可以用软件刻录用u盘安装系统。读取根目录的preseed.cfg文件 :::
default installlabel installmenu label ^Auto install Serverkernel /install/vmlinuzappend file=/cdrom/preseed.cfg vga=788 auto=true initrd=/install/initrd.gz quiet ---
在/目录创建preseed.cfg文件,简单的preseed.cfg文件
该文件最好写英文注释,去掉中文,避免mkisofs生成出现问题,导致找不到该文件
d-i debian-installer/locale string en_USd-i console-setup/ask_detect boolean falsed-i console-setup/layoutcode string usd-i console-setup/variantcode stringd-i keyboard-configuration/layoutcode string usd-i passwd/root-login boolean trued-i passwd/root-password-crypted password $1$hZzTN1$dFKO/okBaidPvfVGTDha51d-i user-setup/allow-password-weak boolean trued-i passwd/user-fullname string ubuntud-i passwd/username string ubuntud-i passwd/user-password-crypted password $1$hZzTN1$dFKO/okBaidPvfVGTDha51d-i user-setup/encrypt-home boolean falsed-i netcfg/enable boolean falsed-i netcfg/get_hostname string ubuntud-i netcfg/get_domain string ubuntud-i apt-setup/use_mirror boolean falsed-i apt-setup/cdrom/set-first boolean falsed-i apt-setup/cdrom/set-next boolean falsed-i apt-setup/cdrom/set-failed boolean falsed-i clock-setup/utc boolean falsed-i time/zone string Asia/Shanghaid-i clock-setup/ntp boolean falsetasksel tasksel/first multiselect standardd-i pkgsel/include string vim openssh-serverd-i pkgsel/upgrade select noned-i pkgsel/update-policy select noned-i pkgsel/install-language-support boolean trued-i grub-installer/skip boolean falsed-i lilo-installer/skip boolean falsed-i grub-installer/only_debian boolean trued-i grub-installer/timeout string 2d-i grub-installer/with_other_os boolean trued-i grub-installer/password-crypted password $1$hZzTN1$dFKO/okBaidPvfVGTDha51d-i debian-installer/quiet boolean falsed-i debian-installer/splash boolean falsed-i finish-install/keep-consoles boolean falsed-i finish-install/reboot_in_progress noted-i cdrom-detect/eject boolean trued-i debian-installer/exit/halt boolean falsed-i debian-installer/exit/poweroff boolean false
preseed详解
语言
# 英文语言d-i debian-installer/locale string en_US
键盘
# 英文键盘d-i console-setup/ask_detect boolean falsed-i console-setup/layoutcode string usd-i console-setup/variantcode stringd-i keyboard-configuration/layoutcode string us
时钟设置
d-i clock-setup/utc boolean falsed-i time/zone string Asia/Shanghaid-i clock-setup/ntp boolean false
用户
# 允许root登录:允许d-i passwd/root-login boolean true# root密码,使用grub-md5-crypt命令生成密文d-i passwd/root-password-crypted password $1$hZzTN1$dFKO/okBaidPvfVGTDha51#d-i user-setup/allow-password-weak boolean true#用户全名d-i passwd/user-fullname string ubuntu#用户d-i passwd/username string ubuntu#用户密码d-i passwd/user-password-crypted password $1$hZzTN1$dFKO/okBaidPvfVGTDha51#加密用户家目录:不加密d-i user-setup/encrypt-home boolean false
网络
# 网络# 跳过网络设置,不使用dhcp也不使用配置静态,也不会出现界面让你选择,这个步骤直接跳过了# 如果你不想跳过,想直接手动通过界面修改,那么注释该语句d-i netcfg/enable boolean false# 主机名d-i netcfg/get_hostname string ubuntu# 域名d-i netcfg/get_domain string ubuntu
apt源
# 以下语句关闭apt源,这样不会因为网络原因去检测apt源是否可用,因为这个会卡在无人值页面,由用户去设置,所以一定要屏蔽掉# 但是这样安装完的apt源/etc/apt/source.list有问题的,如果你需要可用的源# 可以下载阿里源、镜像源,也可以改回之前正常的源d-i apt-setup/use_mirror boolean falsed-i apt-setup/cdrom/set-first boolean falsed-i apt-setup/cdrom/set-next boolean falsed-i apt-setup/cdrom/set-failed boolean false
安装软件
tasksel tasksel/first multiselect standardd-i pkgsel/include string vim openssh-serverd-i pkgsel/upgrade select noned-i pkgsel/update-policy select noned-i pkgsel/install-language-support boolean true
GRUB引导
d-i grub-installer/skip boolean falsed-i lilo-installer/skip boolean falsed-i grub-installer/only_debian boolean trued-i grub-installer/timeout string 2d-i grub-installer/with_other_os boolean trued-i grub-installer/password-crypted password $1$hZzTN1$dFKO/okBaidPvfVGTDha51d-i debian-installer/quiet boolean falsed-i debian-installer/splash boolean false
安装完设置
d-i finish-install/keep-consoles boolean falsed-i finish-install/reboot_in_progress noted-i cdrom-detect/eject boolean trued-i debian-installer/exit/halt boolean falsed-i debian-installer/exit/poweroff boolean false
## 预配置预配置是在安装系统前可以使用基础的命令,如fdisk命令,可以用于实现判断磁盘大小## 后配置预配置是在安装系后的操作## 精简软件包脚本的作用是 进入deb目录,如果系统有这个软件保留,没有这个软件则删除find语句我发现没有用,这个是删除关于d大小为0的文件,所以我注释了把rm语句注释,如果发现查找的文件没有问题,再开启,避免误删文件因为是在原有的基础上,减少软件包无需生成release```bash#!/bin/bashfor j in *docd $jfor k in *docd $kfor l in *.debdoif [ $l != "*.deb" ]thenn=$(dpkg -l $(echo $l | cut -f1 -d"_") 2> /dev/null| grep "^ii")if [ -z "$n" ]then# rm $lecho $lfifidonecd ..donecd ..done#find -depth -type d -empty -exec rmdir {} \;
改回正常的源 http://security.ubuntu.com/ubuntu
我这边修改的是阿里源,本地source.list文件
apt install debconf-utils
debconf-get-selections —installer > file
磁盘小于2T用MBR,大于2T必须用gpt格式
生成ISO镜像
生成md5
find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt
生成镜像
apt -y install genisoimagemkisofs -r -V "linux" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o /root/test-4.iso /cola1/
不配置网络
sed -i 's@PermitRootLogin prohibit-password@PermitRootLogin yes@' /etc/ssh/sshd_config
