静看光阴荏苒
不管不顾不问不说也不念

重新打包DebianISO实现无人应答安装(UEFI+BIOS)

之前我写过打包DebianISO的文章,但是那种打包的方法只能用在引导是BIOS的机器上,按照正常的情况,应该是UEFI+BIOS同时支持。

正好前两天给甲骨文重装系统的时候需要重新打包支持UEFI的ISO用作本地测试,所以这里把UEFI的打包过程也记录一下。

Debian的无人应答安装难就难在preseed的配置,因为没有一个完整的文档可以参考,基本上只能自己一个配置一个配置的去试,少一个配置可能就会在安装的界面弹提示框,出了提示框就不能实现无人应答安装了。

不过好在我之前已经折腾出了一个Debian10可以完美用的preseed配置,所以在甲骨文的机器上装,只需要做一下关于UEFI的支持即可。

所以这也就是为啥要在本地测试的原因,先在虚拟机内跑,虚拟机没问题了再放到甲骨文上试。不过即便是这样我也还是翻车了很多次,甲骨文的机器也删了很多台。。这里就不细说了。。

安装打包需要用到的工具:

apt -y update
apt -y install xorriso isolinux syslinux-utils p7zip-full

下载debian的iso并解压:

wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.9.0-amd64-netinst.iso
7z x debian-10.9.0-amd64-netinst.iso -oimlala

把install.amd目录给写权限:

chmod +w -R imlala/install.amd

解压出initrd:

gunzip imlala/install.amd/initrd.gz

bios和uefi引导需要修改的文件不同,这里只记录uefi引导需要修改的位置,bios引导的可以参考我之前的文章。

首先需要把iso内关于uefi引导的grub配置进行修改,编辑如下文件:

nano imlala/boot/grub/grub.cfg

设置一个超时时间,这里我设置为5秒,默认情况下是没有超时的,也就是说当iso挂载上去后,菜单内必须要人工手动去选择,为了实现无人应答安装,必须设置超时,过了超时时间让iso自动进入相应的grub菜单:

set timeout=5

然后把图形化安装菜单和文本安装菜单的位置调换一下,默认是图形化安装在grub菜单的第一位,为啥要调换位置?因为图形化菜单是不支持preseed的:

menuentry --hotkey=i 'Install' {
    set background_color=black
    linux    /install.amd/vmlinuz vga=788 --- quiet
    initrd   /install.amd/initrd.gz
}
menuentry --hotkey=g 'Graphical install' {
    set background_color=black
    linux    /install.amd/vmlinuz vga=788 --- quiet
    initrd   /install.amd/gtk/initrd.gz
}

具体改动的位置:

然后就是老套路了,新建一个preseed配置文件:

nano preseed.cfg

写入你需要的配置,下面这个配置是我经过测试的,目前可以用在debian10.9上:

# 配置语言
d-i debian-installer/locale string en_US

# 配置键盘
d-i keyboard-configuration/xkb-keymap select us

# 使用自动的方式配置网络(DHCP)
d-i netcfg/choose_interface select auto

# 配置hostname和domain
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
d-i netcfg/hostname string imlala

# 配置软件源
d-i mirror/country string manual
d-i mirror/http/hostname string ftp.jp.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

# 开启root登录并设置root密码,关闭普通用户创建
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password password 123456
d-i passwd/root-password-again password 123456

# 设置时区为东八区
d-i clock-setup/utc boolean true
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp boolean false

# 硬盘分区,注意/dev/sda这里的设备名,要改为你自己的设备名,一般虚拟机如VMware/VirtualBox都是这个设备名
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular

# 手动划分分区大小
d-i partman-auto/expert_recipe string         \
  boot-root ::                                \
    1 1 1 free                                \
      $bios_boot{ }                           \
      method{ biosgrub }                      \
    .                                         \
    256 2 256 fat32                           \
      $primary{ }                             \
      $iflabel{ gpt }                         \
      $reusemethod{ }                         \
      method{ efi } format{ }                 \
      mountpoint{ /boot/efi }                 \
    .                                         \
    512 3 512 ext4                            \
      $primary{ }                             \
      $bootable{ }                            \
      method{ format } format{ }              \
      use_filesystem{ } filesystem{ ext4 }    \
      mountpoint{ /boot }                     \
    .                                         \
    1024 5 1024 linux-swap                    \
      $primary{ }                             \
      method{ swap } format{ }                \
    .                                         \
    1 4 -1 ext4                               \
      $primary{ }                             \
      method{ format } format{ }              \
      use_filesystem{ } filesystem{ ext4 }    \
      mountpoint{ / }                         \
    .                                         \

# 因甲骨文的机器是efi引导,所以这里强制使用gpt分区表
d-i partman-efi/non_efi_system boolean true
d-i partman-partitioning/choose_label string gpt
d-i partman-partitioning/default_label string gpt

# 如果硬盘内之前有lvm或是raid的分区,全部删除
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/device_remove_lvm boolean true

# 下面的这些配置可以做到没有交互式的完成硬盘分区
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

# 禁止在安装的时候弹出CD/DVD扫描提示
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
d-i apt-setup/cdrom/set-first boolean false
d-i apt-setup/cdrom/set-next boolean false   
d-i apt-setup/cdrom/set-failed boolean false

# 软件包选择
tasksel tasksel/first multiselect standard

# 安装额外的软件包,不更新系统
d-i pkgsel/include string openssh-server
d-i pkgsel/upgrade select none

# 禁止在安装的时候弹出popularity
popularity-contest popularity-contest/participate boolean false

# grub安装
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string default

# 安装完成之后不要弹出安装完成的界面,直接重启
d-i finish-install/reboot_in_progress note

# 允许ssh服务使用root用户登录
d-i preseed/late_command string in-target sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config

这里详细说一下关于手动分区的配置,可能很多人不理解分区这块的配置。

分区那里的三个数字,比如说512 3 512,第一个512代表最小分区大小,第二个数字代表优先级,数字越小表示优先级越高,第三个数字代表最大分区大小。如果第三个数字设置为-1就代表剩下的空间全部划分给这个分区。

然后尤其注意这个配置:

d-i partman-efi/non_efi_system boolean true

如果在preseed内配置了这个BIOS引导直接失效,它将强制使用UEFI引导,所以如果你要UEFI+BIOS同时支持,这个配置需要从preseed中删除。

接下来把改好的配置内嵌到initrd:

echo preseed.cfg | cpio -H newc -o -A -F imlala/install.amd/initrd

重新压缩initrd:

gzip imlala/install.amd/initrd

还原install.amd目录之前的权限:

chmod -w -R imlala/install.amd

最后重新打包iso:

xorriso -as mkisofs \
  -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
  -c isolinux/boot.cat \
  -b isolinux/isolinux.bin \
  -no-emul-boot \
  -boot-load-size 4 \
  -boot-info-table \
  -eltorito-alt-boot \
  -e boot/grub/efi.img \
  -no-emul-boot \
  -isohybrid-gpt-basdat \
  -o preseed-debian-10.9.0-amd64-netinst.iso \
  imlala

在虚拟机上启用uefi引导:

测试安装,文本安装选项在第一启动位:

等待5秒超时过后,自动安装开始:

参考文献:

https://wiki.syslinux.org/wiki/index.php?title=Isohybrid
https://wiki.debian.org/DebianInstaller/Preseed/EditIso

赞(7)
未经允许不得转载:荒岛 » 重新打包DebianISO实现无人应答安装(UEFI+BIOS)
分享到: 更多 (0)

评论 10

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    感谢lala的教程,以后要用到的时候可以直接方便的搞定了
    :mrgreen:

    BobMaster3年前 (2021-05-30) Firefox 88.0 Firefox 88.0 GNU/Linux x64 GNU/Linux x64回复
  2. #2

    感谢老哥的教程 美滋滋

    ling ling3年前 (2021-06-01) Google Chrome 90.0.4430.212 Google Chrome 90.0.4430.212 Windows 10 x64 Edition Windows 10 x64 Edition回复
  3. #3

    老哥nb :idea:

    白墨3年前 (2021-06-02) Google Chrome 90.0.4430.210 Google Chrome 90.0.4430.210 Android 10 Android 10回复
  4. #4

    大佬,下个月就出Debian11了,到时候还会出教程么

    david3年前 (2021-06-21) Microsoft Edge 91.0.864.54 Microsoft Edge 91.0.864.54 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 你是说继续出这个打包iso的教程么?这个如果不出意外的话应该可以直接搬到11上用,如果不行的话到时候再看看吧。

      LALA3年前 (2021-06-27) Google Chrome 86.0.4240.198 Google Chrome 86.0.4240.198 Windows 10 x64 Edition Windows 10 x64 Edition回复
  5. #5

    感谢老哥教程,但是我使用时,一直报错no root file system is defind,检查的时候发现没有读取到硬盘信息,但无人装机centos和ubuntu是正常的,老哥有遇到类似的情况么?

    寒桥2年前 (2021-12-01) QQbrowser 10.8.4533.400 QQbrowser 10.8.4533.400 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 没有遇到过,我只能猜测可能是你的preseed配置里面关于硬盘方面的设置有问题,比如说设备名,分区的方式。你可以试下把分区的方式改为自动,参考这篇文章:https://lala.im/7233.html

      LALA2年前 (2021-12-11) Google Chrome 86.0.4240.198 Google Chrome 86.0.4240.198 Windows 10 x64 Edition Windows 10 x64 Edition回复
  6. #6

    大佬,我在vm虚拟机上测试你的debian10的preseed,安装老是弹出[!!] Detect and mount CD-ROM 。能帮忙看一下吗?

    打工人2年前 (2021-12-04) Microsoft Edge 96.0.1054.43 Microsoft Edge 96.0.1054.43 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 在你的preseed配置文件里面加入这个设置试试:d-i cdrom-detect/eject boolean false

      LALA2年前 (2021-12-11) Google Chrome 86.0.4240.198 Google Chrome 86.0.4240.198 Windows 10 x64 Edition Windows 10 x64 Edition回复

分享创造快乐

广告合作资源投稿