如何创建一个完全无人值守安装的Ubuntu Desktop 16.04.1 LTS?

目的

我想要完全无人值守地安装Ubuntu Desktop 16.04.1 LTS。只需将ISO光盘放入并离开即可。

问题

  • 引导参数不正确
  • 仍然需要回答问题和点击鼠标
  • 使用kickstart/preseed的答案复杂
  • 文档示例不按照说明工作,特别是来自partman和ubunutu的部分

我在这个帖子这里中找到了一个接近我所需的解决方案,但并没有完全达到我所需的目标,因为它是针对Ubuntu Server的。该帖子建议使用“非图形化”安装,但我找不到适用于Ubuntu Desktop的非图形化安装,这是合理的。我尝试调整步骤,并使其适用于Ubuntu Desktop 16.04.1 LTS。

使用的文档

我使用了以下所有资源...

显然我不能包含所有的资源,因为askubuntu不允许超过2个链接。这真的不太有帮助 - 所以这里只是一个列表:

  • AskUbuntu
  • Ubuntu install.en.pdf
  • Preseed示例
  • Ubiquity安装程序文档
  • Partman文档和示例
  • 分区配方解释三个数字及其权重
  • 更复杂的Preseed示例

当前解决方案

我目前已经创建了一个无人值守安装,但不确定是否正确 - 这意味着我应该编辑isolinux/isolinux.cfg文件。

我链接的帖子和Ubuntu桌面镜像之间有很多差异。这是我的解决方案:

步骤1

挂载Ubuntu ISO,以便将内容复制到另一个目录,然后编辑相关文件。

mkdir -p /mnt/iso
mount -o loop ubuntu.iso /mnt/iso

第二步
然后,我将ISO文件复制到另一个目录进行编辑。
mkdir -p /opt/ubuntuiso
cp -rT /mnt/iso /opt/ubuntuiso

第三步
我编辑了`isolinux/isolinux.cfg`文件,并用以下内容替换了其中的所有内容:
default live-install
label live-install
  menu label ^Install Ubuntu
  kernel /casper/vmlinuz.efi
  append  file=/cdrom/ks.preseed auto=true priority=critical debian-installer/locale=en_US keyboard-configuration/layoutcode=us ubiquity/reboot=true languagechooser/language-name=English countrychooser/shortlist=US localechooser/supported-locales=en_US.UTF-8 boot=casper automatic-ubiquity initrd=/casper/initrd.lz quiet splash noprompt noshell ---

附加行非常长,为了方便阅读,这里列出了我使用的所有选项:
file=/cdrom/ks.preseed 
auto=true 
priority=critical 
debian-installer/locale=en_US 
keyboard-configuration/layoutcode=us 
ubiquity/reboot=true 
languagechooser/language-name=English 
countrychooser/shortlist=US 
localechooser/supported-locales=en_US.UTF-8 
boot=casper 
automatic-ubiquity 
initrd=/casper/initrd.lz 
quiet 
splash 
noprompt 
noshell

我发现所有这些引导参数都是为了实现完全无人值守安装所必需的。对于Ubuntu服务器,可能会有所不同。
第4步
我尝试使用和创建许多预配置文件,但我发现越复杂,出错的机会就越大。目前这是与上述isolinux.cfg文件配合使用的简单预配置文件。
### Partitioning
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-auto/choose_recipe select atomic

# This makes partman automatically partition without confirmation
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

# Locale
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us

# Network
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
d-i netcfg/choose_interface select auto

# Clock
d-i clock-setup/utc-auto boolean true
d-i clock-setup/utc boolean true
d-i time/zone string US/Pacific
d-i clock-setup/ntp boolean true

# Packages, Mirrors, Image
d-i base-installer/kernel/override-image string linux-server
d-i base-installer/kernel/override-image string linux-image-amd64
d-i mirror/country string US
d-i mirror/http/proxy string
d-i apt-setup/restricted boolean true
d-i apt-setup/universe boolean true
d-i pkgsel/install-language-support boolean false
tasksel tasksel/first multiselect ubuntu-desktop

# Users
d-i passwd/user-fullname string Liason
d-i passwd/username string liason
d-i passwd/user-password-crypted password [crpyt 3]
d-i passwd/root-login boolean true
d-i passwd/root-password-crypted password [crypt 3]
d-i user-setup/allow-password-weak boolean true

# Grub
d-i grub-installer/grub2_instead_of_grub_legacy boolean true
d-i grub-installer/only_debian boolean true
d-i finish-install/reboot_in_progress note

# Custom Commands

我没有包含我的加密密码,所以如果你尝试使用这个预置文件,请将它们更改为加密密码。这里有三种方法来创建密码。
第五步
我从/opt/ubuntuiso/目录创建了新的ISO文件。
mkisofs -D -r -V ATTENDLESS_UBUNTU -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o /opt/autoinstall.iso /opt/ubuntuiso

第6步
我最终在Virtualbox上进行了测试,它创建了一个完全无人值守的安装。
问题
我是否需要编辑`isolinux/isolinux.cfg`文件?
在另一篇帖子中,他们似乎能够编辑`isolinux/txt.cfg`文件并使其工作。我尝试了大约一个小时使用`isolinux/txt.cfg`,但它没有起作用。
有没有人有一个更复杂的partman配方,可以直接指定分区?或者一个可行的LVM设置? 我尝试使用一个简单的LVM设置,但是重新启动后它无法启动,只会停留在黑屏上。此外,我列在文档中的任何一个预设示例都没有起作用。
感谢任何帮助。
7个回答

回答

我在最初提问后给了一些时间,看是否有其他解决方案,但看起来在等待期间我想到的解决方案是目前唯一可行的解决方案。

误解

由于这引起了很多困惑,我将尝试澄清。似乎有些答案尝试使用 Ubuntu 16 Server 镜像,而我特别想创建一个无人值守的 Ubuntu 16 桌面镜像安装。问题出现在 d-i (debian installer) 和 ubiquity 的实现差异上。由于服务器镜像会注意并使用预置文件中的所有 d-i 命令,所以我提出的大部分问题对服务器镜像来说都不相关。然而,由于桌面镜像使用 ubiquity 作为安装程序,许多 d-i 命令被忽略,你的选择非常有限,而且缺少很多文档。

找到的文档链接

  • 这里是Ubiquity忽略preseed/late_command的链接(我相信它也会忽略preseed/early_command)。
  • 这里是Ubiquity文档,它讨论了在Ubiquity中不会使用的安装程序组件,但是你会注意到即使在这个文档中,它也提到了preseed/early_command。但是我建议你进行全面测试以验证,因为在我的情况下似乎没有起作用(我承认我没有严格测试early_command,所以可能是我错了)。

成功的过程

这是我成功创建一个无人参与的Ubuntu Desktop 16.04 LTS iso的过程。

挂载Ubuntu ISO

您需要挂载ISO文件以便编辑相关文件。

mkdir -p /mnt/iso
mount -o loop ~/Downloads/ubuntu-16.04.1-desktop-amd64.iso /mnt/iso

复制ISO文件

我们需要将挂载的ISO文件复制到其他目录,以便我们可以对其进行编辑。随意选择任何你喜欢的目录,我选择了/opt目录是因为另一个操作指南,但是/tmp同样可以轻松使用。

mkdir -p /opt/ubuntuiso
cp -rT /mnt/iso /opt/ubuntuiso

编辑txt.cfg文件

在这里,我们将编辑/opt/ubuntuiso/isolinux/txt.cfg文件,并自定义我们的引导参数,以实现完全无人值守安装,其中包括一个预配置文件。使用您喜欢的任何编辑器:

#default live
#label live
#  menu label ^Try Ubuntu without installing
#  kernel /casper/vmlinuz.efi
#  append  file=/cdrom/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash ---
#label live-install
#  menu label ^Install Ubuntu
#  kernel /casper/vmlinuz.efi
#  append  file=/cdrom/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash ---
#label check
#  menu label ^Check disc for defects
#  kernel /casper/vmlinuz.efi
#  append  boot=casper integrity-check initrd=/casper/initrd.lz quiet splash ---
#label memtest
#  menu label Test ^memory
#  kernel /install/mt86plus
#label hd 
#  menu label ^Boot from first hard disk
#  localboot 0x80

default live-install
label live-install
  menu label ^Install Ubuntu
  kernel /casper/vmlinuz.efi
  append  file=/cdrom/ks.preseed auto=true priority=critical debian-installer/locale=en_US keyboard-configuration/layoutcode=us ubiquity/reboot=true languagechooser/language-name=English countrychooser/shortlist=US localechooser/supported-locales=en_US.UTF-8 boot=casper automatic-ubiquity initrd=/casper/initrd.lz quiet splash noprompt noshell ---

请注意以下几点:
  • 我已经将文件中的所有原始文本注释掉了。
  • 我在底部添加了包括"default live-install"在内的所有文本。
  • 我将预置文件命名为"ks.preseed",它将位于ISO的顶级目录下(/opt/ubuntuiso)。

使用或创建预置文件

谨慎使用已存在的预置文件!我没有找到任何一个可以直接使用的。这并不是说它们不存在,只是我在搜索中没有找到合适的。有很多方法可以配置预置文件,但我发现许多选项都被忽略了,这些选项在我上面提供的Ubiquity文档和preseed/late_command vs ubiquity/success_command链接中有详细说明。我在这里包含了一个简单有效的预置文件,可以与上述txt.cfg文件配合使用。

对于netcfg/get_hostname stringnetcfg/get_domain string,您可以根据需要设置任何值。我使用了unassigned-hostname和unassigned-domain,因为我之后会通过脚本进行更改。

对于安装后要运行的任何自定义命令,您需要使用:

ubiquity ubiquity/success_command string

跟着你想运行的任何命令。注意用";\"继续字符串,并使用"/target"来更改与新系统安装相关的任何内容。
# Partitioning
# Old style using d-i command
#d-i partman-auto/disk string /dev/sda
#d-i partman-auto/method string regular
#d-i partman-lvm/device_remove_lvm boolean true
#d-i partman-md/device_remove_md boolean true
#d-i partman-auto/choose_recipe select atomic

# Newer ubiquity command
ubiquity partman-auto/disk string /dev/sda
ubiquity partman-auto/method string regular
ubiquity partman-lvm/device_remove_lvm boolean true
ubiquity partman-md/device_remove_md boolean true
ubiquity partman-auto/choose_recipe select atomic

# This makes partman automatically partition without confirmation
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

# Locale
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us

# Network
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
d-i netcfg/choose_interface select auto

# Clock
d-i clock-setup/utc-auto boolean true
d-i clock-setup/utc boolean true
d-i time/zone string US/Pacific
d-i clock-setup/ntp boolean true

# Packages, Mirrors, Image
d-i mirror/country string US
d-i apt-setup/multiverse boolean true
d-i apt-setup/restricted boolean true
d-i apt-setup/universe boolean true

# Users
d-i passwd/user-fullname string User
d-i passwd/username string user
d-i passwd/user-password-crypted password yourEncryptedPasswd
d-i passwd/user-default-groups string adm audio cdrom dip lpadmin sudo plugdev sambashare video
d-i passwd/root-login boolean true
d-i passwd/root-password-crypted password rootEncryptedPasswd
d-i user-setup/allow-password-weak boolean true

# Grub
d-i grub-installer/grub2_instead_of_grub_legacy boolean true
d-i grub-installer/only_debian boolean true
d-i finish-install/reboot_in_progress note

# Custom Commands
ubiquity ubiquity/success_command string \
  sed -i -e 's/dns=dnsmasq/#dns=dnsmasq/' /target/etc/NetworkManager/NetworkManager.conf ;\
  cp -a /cdrom/scripts/ /target/root/ ;\
  cp -a /cdrom/salt/ /target/root/

请注意,我在这里保留了一些内容以作说明,但在您的预设命令中可能会有所不同。
- 用户/根密码需要您添加。这里是一个链接,展示了三种不同的方法来生成加密3密码。 - 您可能希望更改用户所分配的组。 - 您肯定会想要更改成功命令。我将其保留以展示如何格式化以及如何使用目标环境。
创建新的ISO
创建ISO文件,以便您可以测试您的预设文件。如果您使用现有的ISO文件或自己制作一个,您需要进行测试,因为这很可能是您的过程失败的地方。我编写了一个用于快速测试的脚本,但您也可以将预设文件指向托管在http://上的预设文件,并通过这种方式进行快速测试。
mkisofs -D -r -V "UNATTENDED_UBUNTU" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o /tmp/ubuntu16-desktop-unattended-install.iso /opt/ubuntuiso

随意更改输出名称和保存目录。

刻录ISO

我建议在虚拟机或类似软件上进行测试,一旦成功运行,再将其刻录到DVD上。现在,您应该拥有一个可用的无人值守Ubuntu Desktop 16.04 LTS安装DVD。

反馈、修正、错误

我一口气写了这些内容,可能会有错误、错别字或混乱的地方。如果有人尝试了这个过程,请告诉我是否遇到了错误。请记住,如果您创建自己的preseed文件,由于ubiquity喜欢忽略和不执行preseed文件中的某些操作,我可能无法回答为什么您的无人值守安装出现故障并且无法工作。希望对某人有所帮助。


嗨@BrandonAuthier,感谢你在这里分享的信息。我非常仔细地按照你的步骤操作,并最终尝试从/tmp/ubuntu16-desktop-unattended-install.iso镜像制作可启动的USB键。为了做到这一点,我以root身份使用了以下命令(我的USB设备位于/dev/sdc):dd if=/tmp/ubuntu16-desktop-unattended-install.iso of=/dev/sdc bs=4M && sync。不幸的是,这个USB键(只有当它包含这个自定义iso时才会出现问题:原始的iso可以正常工作)在引导选项中没有显示,所以似乎它不是“可启动”的。也许你对发生的情况有什么想法吗? - Hadrien TOMA
1实际上,USB键盘被视为“软盘驱动器”,而不是“USB存储设备”(我可以从中引导)。 - Hadrien TOMA
我还尝试使用UNetbootin将ISO文件烧录到USB闪存驱动器上。结果是,USB闪存驱动器现在成功被识别为"USB存储设备",但似乎无法启动(始终显示黑屏,左上角有一个闪烁的光标)。我现在正在考虑可能是图像错误而不是烧录错误。 - Hadrien TOMA
2我认为创建一个可启动的USB键稍微有些不同,需要将isolinux/和isolinux.cfg重命名为syslinux/和syslinux.cfg。我写这个是为了CD/DVD,并在虚拟机中进行测试,然后通过DVD安装。我没有尝试将其制作成可启动的USB,但使用dd命令可能出现了一些问题。如果您没有更改这些名称,那可能就是其中的一部分原因。如果您没有正确格式化USB并使用fdisk给它设置一个可启动标志,那可能是另一个原因。当我有更多时间时,我可以弄清楚如何操作并发布出来。 - Brandon Authier
3如果您对Linux引导和grub/syslinux加载的低级细节不熟悉,我强烈建议使用mkusb将ISO放入USB中。 - dragon788
1@HadrienTOMA,如果你使用的是Ubuntu机器,dragon788可能是对的,可以使用mkusb,因为它似乎是通过PPA安装的。老实说,查找如何使用fdisk格式化USB,创建正确的文件系统,然后使用dd命令是值得学习的。我唯一担心的是,只使用dd命令可能无法使我的ISO镜像正常工作。一旦我有机会测试一下,我会告诉你的。 - Brandon Authier
好的,非常感谢你们两位。我会尽量在有时间的时候试一试,并告诉你们结果。 - Hadrien TOMA
嘿,我回来告诉大家,我成功地通过使用mkusb将我的USB键盘设置为可启动。谢谢你们两位! - Hadrien TOMA
对于使用UEFI安装,您可以将ISO内容复制到一个FAT32格式的USB闪存驱动器上。然后您可以编辑文件。请参阅:https://askubuntu.com/questions/395879/how-to-create-uefi-only-bootable-usb-live-media/395880#395880 - phiphi
实际上,您不需要在内核选项中放置那么多参数,它们也可以转化为预配置文件。 - Tomofumi

请查看:https://github.com/core-process/linux-unattended-installation

该项目提供了创建无人值守安装最小化 Linux 的所有所需内容,其中最小化指的是最轻量级的设置 - 包括一个 OpenSSH 服务和 Python,您可以从 Linux 发行版的标准安装程序中派生出来。思路是,一旦完成最小化设置,您将使用 Ansible 或类似工具来进行后续配置和服务部署。


嗯,看起来有点有趣。我肯定会等待18.04 LTS版本,但我可能会试试这个,只是想看看效果如何。我已经通过上面发布的解决方案弄清楚了一切。然而,看看其他人是如何解决问题的总是对于获取不同的想法很有好处。 - Brandon Authier
1刚刚新增了构建磁盘镜像以及ISO镜像的支持。尽情享受吧! - Niklas
用户名是什么?我能够使用这种方法安装,但对于登录细节一无所知。 - Krishnadas PC
@KrishnadasPC,请看我在这里的回复:https://github.com/core-process/linux-unattended-installation/issues/20#issuecomment-565113509 - Niklas

Brandon Authier,你真棒!谢谢你的帖子和指导,对我帮助很大。
不过,我在你的方法中遇到了一个问题:在安装完成后重启电脑时,GRUB卡住了。
所以我在ks.preseed中添加了以下内容:
# Due notably to potential USB sticks, the location of the MBR can not be
# determined safely in general, so this needs to be specified:

d-i grub-installer/bootdev  string /dev/sda

# To install to the first device (assuming it is not a USB stick):
#d-i grub-installer/bootdev  string default

这样做可以防止在不移除USB闪存驱动器的情况下导致grub安装崩溃。 我从https://www.debian.org/releases/stable/example-preseed.txt获取了这个信息。

1所以它卡住是因为USB仍然插着,尝试再次从USB启动?我肯定可以将此添加到上面的预置文件中,但我想确保我知道发生了什么以及这可以防止什么。 - Brandon Authier

首先非常感谢Brandon在这个过程中的努力!网络上有很多预装文件,显示了用户对跳过安装界面的需求。
随着20.04版本的发布,我想从我的测试中添加一些注意事项。我正在使用Kubuntu,但其他Buntus看起来是一样的。
  • 目前正在编辑:如果您使用virt-manager,可以将其安装到原始(ext4)分区并安装到整个磁盘上,跳过分区部分的partman 'recipes'(如果您有能力的话)。 (我为所有Linux操作系统使用单个交换分区,或在另一个分区上使用大型交换文件,以便可以更快地备份整个操作系统分区的副本)。通过网络复制此分区比使用USB在许多机器上安装要快(除非您有一个大型的USB克隆系统)。
  • 我使用AIOBOOT作为引导菜单(包括Refind,Clover等),因此我从来不更改系统的GRUB。而且,在虚拟机中安装会使其无效,但是如果您搞乱了引导顺序,请使用efibootmgr --help命令。
  • 我无法使默认的isolinux.cfg菜单选择项起作用(如下所示)。不需要boot=casper。将default vesamenu.c32更改为default install或者您命名的菜单项,从here..仍然无效。顺便说一句,20.04最初没有直接安装的条目。
  • 我碰巧先尝试Kickstarter,所以它给了我一个ks.cfg(不起作用)和一个ks.preseed(只有一行)。由于ISO中已经存在一个kubuntu.preseed,我将那些行复制到ks.preseed(下面是内容),然后添加了Brandon的preseed魔法,更改了自定义命令。它还将我的通用初始密码加密为$1$D2dImaFN$AEBMU.qOh2qer0v/alzeH0,即123。您可以像我下面所做的那样输入它。但是,不要忘记更改它;)!
  • 有关Ubuntu自动安装的更多官方信息,请参见here。可能有些过时,因为它声称Kickstarter起作用,尽管“这种方法不如上述预配置文件方法灵活,但需要对安装程序如何工作的了解较少。” Ubuntu提供的一个官方只包含preseed的示例在here
  • 将isolinux/isolinux.cfg中的timeout 30更改为1
  • 在isolinux/txt.cfg中将maybe-ubiquity更改为automatic-ubiquity。这就是安装程序。可能是only-ubiquity,更多信息请参见here
  • 我在ks.preseed中使用了来自here的分区行,因为它们都使用了新的ubiquity命令。只有一行额外不同:partman-lvm/confirm string boolean true。我没有测试Brandon的。
default install
...all the original entries...
label install
  menu label ^Install kUbuntu auto
  kernel /casper/vmlinuz
  append  file=/cdrom/ks.preseed auto=true priority=critical debian-installer/locale=en_US keyboard-configuration/layoutcode=us ubiquity/reboot=true languagechooser/language-name=English countrychooser/shortlist=US localechooser/supported-locales=en_US.UTF-8 automatic-ubiquity initrd=/casper/initrd --

# Enable extras.ubuntu.com.
d-i apt-setup/extras    boolean true
# Install the Kubuntu desktop.
tasksel tasksel/first   multiselect kubuntu-desktop
#tasksel tasksel/first   multiselect ubuntu-desktop
# Install KDE translation packages.
d-i pkgsel/language-pack-patterns   string language-pack-kde-$LL kde-i18n-$LL
# Install the KDE oem-config frontend (if in OEM mode).
d-i oem-config-udeb/frontend    string kde
# On live DVDs, don't spend huge amounts of time removing substantial
# application packages pulled in by language packs. Given that we clearly
# have the space to include them on the DVD, they're useful and we might as
# well keep them installed.
ubiquity    ubiquity/keep-installed string icedtea6-plugin openoffice.org

# Partitioning
# Not needed if only one disk
#ubiquity   partman-auto/disk string /dev/sda

ubiquity    partman-auto/method string regular
ubiquity    partman-lvm/device_remove_lvm string boolean true
ubiquity    partman-md/device_remove_md string boolean true
ubiquity    partman-lvm/confirm string boolean true
ubiquity    partman-auto/choose_recipe select atomic

ubiquity    partman/confirm_write_new_label string boolean true
ubiquity    partman/choose_partition select finish
ubiquity    partman/confirm string boolean true
ubiquity    partman/confirm_nooverwrite string boolean true

# Locale
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us

# Network
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
d-i netcfg/choose_interface select auto

# Clock
d-i clock-setup/utc-auto boolean true
d-i clock-setup/utc boolean true
d-i time/zone string US/Pacific
d-i clock-setup/ntp boolean true

# Packages, Mirrors, Image
d-i mirror/country string US
d-i apt-setup/multiverse boolean true
d-i apt-setup/restricted boolean true
d-i apt-setup/universe boolean true

# Users
d-i passwd/user-fullname string User
d-i passwd/username string user
d-i passwd/user-password-crypted password $1$D2dImaFN$AEBMU.qOh2qer0v/alzeH0
d-i passwd/user-default-groups string adm audio cdrom dip lpadmin sudo plugdev sambashare video
d-i passwd/root-login boolean true
d-i passwd/root-password-crypted password $1$D2dImaFN$AEBMU.qOh2qer0v/alzeH0
d-i user-setup/allow-password-weak boolean true

# Grub
d-i grub-installer/grub2_instead_of_grub_legacy boolean true
d-i grub-installer/only_debian boolean true
d-i finish-install/reboot_in_progress note

# Custom Commands
ubiquity ubiquity/success_command string \
  echo 'command1' ;\
  read -p "Press enter to continue" ;


关于通过虚拟机安装到原始分区的更多信息...目前,gparted无法识别该分区,但我可以在virt-manager中创建一个新的虚拟机并启动它。要在virt-manager中安装,请选择ISO安装,将分区/dev/sda#(或更安全地:/dev/disk/by-id/...)输入到自定义存储字段中。在安装之前点击自定义按钮,您可以添加更多硬件(底部的按钮)作为IDE或SATA设备进行存储。我不得不在引导选项中更改直接内核引导,以添加指向正确UUID的路径和参数BOOT_IMAGE=/boot/vmlinuz-4.18.0-14-generic root=UUID=...,但这是在我转换VirtualBOX VDI之后,这次它只是正常启动而没有这些字段。我需要测试一下它是否能从硬盘通过我的引导管理器启动。另外,我听说Vagrant是一种较新的虚拟机管理器。还有,在virt-manager中将网络设置为NAT。

很抱歉听到我的以前的方法没有起作用。幸运的是,我在GitHub上找到了由Rinck Sonnenberg(netson)设计的脚本,可以创建无人值守的Ubuntu Server的AMD64 ISO镜像,并且我进行了分叉。然后,我通过添加创建I386 ISO镜像的功能来改进了脚本。我还将操作系统从Ubuntu Server更改为Ubuntu Desktop。您不需要访问GitHub存储库,只需按照以下说明操作。
运行以下命令:
$ wget https://raw.githubusercontent.com/iPlus-TechNet/ubuntu-unattended/master/create-unattended-iso.sh
$ chmod +x create-unattended-iso.sh
$ sudo ./create-unattended-iso.sh

有时候 wget 不可用。如果是这种情况,可以使用 curl:
$ curl -O https://raw.githubusercontent.com/iPlus-TechNet/ubuntu-unattended/master/create-unattended-iso.sh

如果这些方法都不起作用,就下载它并将其移动到您的主文件夹中。
然后,您将被要求选择要安装的Ubuntu版本,然后是如果您进行手动安装时Ubuntu会问的问题。脚本将随后下载Ubuntu ISO,并对其进行所请求的更改。现在,您已经拥有了一个准备好进行无人值守安装的ISO!
这应该能回答您的问题,因为对我来说它完全正常运行。而且,这种方法比我之前的回答要简单得多。希望它对您也同样有效。

1我很感谢你的回答,阅读了你的脚本后,我发现你正在使用Ubuntu Server,而我已经明确多次表示我不想使用它。我已经知道Ubuntu Server使用d-i,并且实际上利用了传统的preseed参数。然而,我的问题清楚地说明了我想要Ubuntu Desktop。我不想安装服务器,然后再安装桌面版。 - Brandon Authier
好的。我会更换为Ubuntu桌面版。 - iplustech.net
我修好了。希望现在能对你有用。 - iplustech.net
这个功能失败了,没有达到预期的效果。它甚至无法通过欢迎界面。 - Brandon Authier
Pic - Brandon Authier
我不知道该说什么。这些方法应该是有效的。你的系统可能有一些奇怪的地方。 - iplustech.net
1这应该很简单 - 你的脚本只下载服务器图片 - 这不是我要求的,这就是为什么你的脚本解决方案失败的原因。它与我的系统有关,这并不奇怪,因为我在问题中明确指出了它是桌面版本。谢谢你的努力,但服务器图片无法解决这个问题。 - Brandon Authier
2https://github.com/iPlus-TechNet不再存在吗?我遇到了404错误。 - Hadrien TOMA

非常感谢!这是我迄今为止找到的对这个问题最好的答案。自动安装部分都很顺利。只想补充一下关于创建新的ISO文件的部分。使用你回答中的命令创建的ISO镜像在我的测试中完美适用于虚拟机安装,但不适用于USB启动驱动器。我尝试下面的方法可以很好地创建USB安装介质并以UEFI模式启动。
OLD_IMAGE=/path/to/iso
MBR_FILE=/tmp/ubuntu_isohybrid_mbr.img
dd if="$OLD_IMAGE" bs=1 count=446 of="$MBR_FILE"

IMAGE=custom.iso
BUILD=/mnt/iso

xorriso -as mkisofs -r -V "Custom Ubuntu Install CD" \
            -cache-inodes -J -l \
            -isohybrid-mbr "$MBR_FILE" \
            -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 "$IMAGE" \
            "$BUILD"

rm "$MBR_FILE"

要让自动化在UEFI模式下工作,您还需要以与上述答案中提到的isolinux.cfg几乎相同的方式编辑镜像中的boot/grub/grub.cfg。我的文件看起来是这样的:
if loadfont /boot/grub/font.pf2 ; then
    set gfxmode=auto
    insmod efi_gop
    insmod efi_uga
    insmod gfxterm
    terminal_output gfxterm
fi

set menu_color_normal=white/black
set menu_color_highlight=black/light-gray

menuentry "Customized Automatic Install" {
    set gfxpayload=keep
    linux   /casper/vmlinuz  file=/cdrom/preseed/custom.seed boot=casper automatic-ubiquity initrd=/casper/initrd quiet splash noprompt noshell ---
    initrd  /casper/initrd
}

在这里,custom.seed 是我正在使用的预配置文件,我将一些区域设置放入了预配置文件中,而不是留在这行代码中。


请不要尝试这种方法。不起作用(除非你只是想消磨时间):
我在各个地方都看到了答案。我会告诉你最常见的解决方案。我自己以前从未尝试过,所以可能已经过时了。我真的不明白它的意义,因为仅仅进行手动安装本身会更容易,但无论如何...
以root用户登录或运行$ sudo su - 下载并挂载ISO文件。不要从Ubuntu网站手动操作。
# mkdir -p /mnt/iso
# mount -o loop ubuntu.iso /mnt/iso

备份并移动相关文件。
# mkdir -p /opt/ubuntuiso
# cp -rT /mnt/iso /opt/ubuntuiso

屏蔽GUI界面中的语言部分显示
# cd /opt/ubuntuiso
# echo en >isolinux/lang

添加一个“Kickstart”文件。
# apt install system-config-kickstart
# system-config-kickstart

[可选] 为您的安装添加软件包
# vim /path/to/ks.cfg #[OPTIONAL]

或者直接在您的文件中搜索并进行编辑。添加%packages部分,并将您的软件包放在其中。

%packages
# Add your packages below. Example:
@ ubuntu-server
apache2
mysql-server
php7.0
php-pear
libapache2-mod-php7.0 
php7.0-mysql
php7.0-curl
php7.0-json
php7.0-cgi

正如我所说,我从未亲自尝试过这样做,所以如果你有像上面那样的配置,它实际上可能不会安装LAMP堆栈,你之后可能需要手动安装。

使用"preseed"文件来抑制问题。

# echo 'd-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition \
select Finish partitioning and write changes to disk
d-i partman/confirm boolean true' > ks.preseed

激活文件:

# vi isolinux/txt.cfg

然后搜索:
label install
  menu label ^Install Ubuntu Server
  kernel /install/vmlinuz
  append  file=/cdrom/preseed/ubuntu-server.seed vga=788 initrd=/install/initrd.gz quiet --

你需要添加ks=cdrom:/ks.cfgpreseed/file=/cdrom/ks.preseed。删除quietvga=788这两个词,使其看起来像这样:
append file=/cdrom/preseed/ubuntu-server.seed initrd=/install/initrd.gz ks=cdrom:/ks.cfg preseed/file=/cdrom/ks.preseed --

现在你可以创建新的答案:
# mkisofs -D -r -V "ATTENDLESS_UBUNTU" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o /opt/autoinstall.iso /opt/ubuntuiso

而你就是这样!

既然我四处看了看,发现在这里Elazar Leibovich提供的链接中有完全相同的公式,我猜我关于它是最常见的观点是正确的。 - iplustech.net
1嗯,我不确定我的先前关于这篇文章的评论发生了什么事...... 上述方法不起作用。如果您正在阅读此内容以寻找答案,请不要尝试此方法,这是浪费您时间的行为。我在原始问题中明确地链接了这个确切的过程,清楚地概述了这种方法的缺陷: ks太过有限 由于普及性,Ubuntu 16.01的ps文件忽略了很多功能 txt.cfg对于Ubuntu Desktop 16.04无效,如此或其他帖子所示 您必须传递相当多的启动参数才能绕过并甚至达到ubiquity的ps-ding - Brandon Authier
3这个海报显然没有读过我的帖子。他写道:“我自己以前从未尝试过,所以可能已经过时了。我真的不明白它的意义,因为仅仅进行手动安装本身会更容易,但无论如何...”。甚至都没试过就把它当作一个解决方案???其次,我解释了我想要一个无人值守安装,可以让我离开。不是手动的。想象一下安装100个盒子,你愿意手动做吗?不会。 - Brandon Authier
哦。对不起。我可以考虑其他方法来完成这个任务。 - iplustech.net
我猜iplustech.net在第一条评论中关于这个公式有效的说法是错误的,因为它是最常见的。 - alchemy