Xubuntu 20.04 最小安装

Xubuntu 20.04 最小安装

在多个 Ubuntu 早期版本中使用过 netboot (mini.iso) 映像中的 Xubuntu 最小安装后,我注意到 netboot 安装程序不再受支持。我想知道现在在虚拟机中获取 Xubuntu 20.04 最小安装的“官方”方法是什么(因为 Xubuntu 是唯一一个在安装程序中没有“最小安装”选项的官方版本)。我知道以下选项及其各自的缺点:

  • Xubuntu 网站上的 Xubuntu Core 描述仍指 mini.iso,该版本未正式支持 18.04 以上版本。20.04 版有一个 mini.iso,详见这个帖子,尽管不再受官方支持。它可能随时消失,或者在未来版本 >20.04 中完全停用。目前,此映像允许我安装最低版本的 Xubuntu。

  • Xubuntu 核心映像无法安装,因为安装程序崩溃了(自发布以来,我尝试过多次,使用过不同版本的 VirtualBox): 安装程序崩溃

  • 通过 Ubuntu live server安装该xubuntu-core软件包apt(被列为 mini.iso 的推荐替代品)会占用 4 GB 以上的磁盘空间,因此似乎与 20.04 mini.iso 和 18.04 mini.iso 执行的最小安装有很大不同。

  • Ubuntu Core 对我来说不是一个选择,因为它需要创建并将其链接到用户帐户。由于这个限制,我到目前为止还没有尝试过。我只想在虚拟机中安装 Xubuntu 并离线使用它。

  • Ubuntu Base 太小,需要很多准备步骤。我只想安装 Xubuntu。

有了这些选项,我是否遗漏了什么,以便以官方支持的方式获得 Xubuntu 20.04 最小安装,并且可能在未来版本中得到支持?

答案1

使用 Ubuntu Base 和 Live 自动安装程序 (subiquity) 来获得最小的 Ubuntu/Xubuntu 系统

下面是一个自动安装模板文件,你可以使用它来自动安装Ubuntu 基础版 20.10(及更新版本)并从中获取相对最小的 Xubuntu 安装。作为一项要求,您需要已设置其余的 PXE 安装环境(请参阅下面的链接以获取分步指南)。PXE 环境由以下部分组成:DHCP 服务、TFTP 服务器、HTTP(S) 服务器和可选的 NFS 服务器。这些服务器组合在一起时,可为网络中的设备提供 PXE 启动功能。设备本身也需要支持从网络启动(传统 BIOS 或 UEFI)。

我使用 PXE 启动、Ubuntu 20.04.1 和 20.10 以及自动安装文件(20.10 见下文)进行了所有测试。要了解有关为 20.04 及更高版本逐步设置 PXE 的详细信息,请在此处阅读我的其他指南:https://askubuntu.com/a/1292097/1080682

注意:下面列出的命令也可以通过其他方式执行,例如在 Live-CD 或任何其他实时启动会话中手动执行,我也使用 PXE 启动到安装程序 (subiquity),然后在 subiquity 实时会话中通过 SSH 执行。请确保启动的会话/安装程序与您计划安装的 Ubuntu Base 具有相同的主要版本,例如用于创建 Ubuntu Base 20.10 的 Ubuntu 20.10 Live-CD

自动安装脚本通过 PXE 作为“用户数据”文件提供。

用户数据

#cloud-config

autoinstall:
  version: 1
  early-commands:
    - dd if=/dev/zero of=/dev/sda bs=8M count=30
    - (echo o; echo n; echo p; echo 1; echo ""; echo +200M; echo n; echo p; echo 2; echo ''; echo ''; echo a; echo 1; echo p; echo w) | fdisk /dev/sda
    - mkfs.fat -F 32 -D 0x80 -M 0xF8 -n BOOT /dev/sda1
    - mkfs.ext4 -F /dev/sda2
    - mkdir /mnt/boot /mnt/root
    - mount /dev/sda2 /mnt/root
    - curl http://cdimage.ubuntu.com/ubuntu-base/releases/20.10/release/ubuntu-base-20.10-base-amd64.tar.gz -o /ubuntu-base-20.10-base-amd64.tar.gz
    - tar -xzvf /ubuntu-base-20.10-base-amd64.tar.gz -C /mnt/root
    - touch /mnt/root/etc/resolv.conf
    - echo "nameserver 8.8.8.8" > /mnt/root/etc/resolv.conf
    - chroot /mnt/root sh -c "apt-get update"
    - chroot /mnt/root sh -c "apt-get install -y linux-image-5.8.0-28-generic initramfs-tools init dbus iproute2 sudo nano --no-install-recommends"
    - chroot /mnt/root sh -c "useradd -m ubuntu -s '/bin/bash' && echo ubuntu:ubuntu | chpasswd"
    - chroot /mnt/root sh -c "addgroup ubuntu adm"
    - chroot /mnt/root sh -c "addgroup ubuntu sudo"
    - apt-get update
    - apt-get install -y syslinux
    - syslinux -i /dev/sda1
    - dd if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sda bs=440 count=1 conv=notrunc
    - mount /dev/sda1 /mnt/boot
    - touch /mnt/boot/syslinux.cfg
    - (echo PROMPT 0; echo DEFAULT base; echo LABEL base; echo KERNEL vmlinuz; echo APPEND root=/dev/sda2 rw; echo INITRD initrd.img) > /mnt/boot/syslinux.cfg
    - cp /mnt/root/boot/vmlinuz /mnt/boot
    - cp /mnt/root/boot/initrd.img /mnt/boot
    - touch /mnt/root/etc/systemd/network/00-wired.network
    - (echo [Match]; echo Name=enp0s10f0; echo [Network]; echo Address=10.10.2.101/24; echo Gateway=10.10.2.99; echo DNS=8.8.8.8) > /mnt/root/etc/systemd/network/00-wired.network
    - chroot /mnt/root sh -c "systemctl enable systemd-networkd.service"
    - chroot /mnt/root sh -c "apt-get clean"
    - umount /mnt/boot
    - umount /mnt/root
    - reboot

以上脚本只是纯脚本适用于 BIOS / 传统启动,它应该可以正常工作,复制/粘贴。

要添加 UEFI 功能,请在 apt-get clean 之后和 umount 和 reboot 命令之前插入以下行。

    - mkdir -p /mnt/boot/EFI/BOOT/
    - cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi /mnt/boot/EFI/BOOT/BOOTX64.EFI
    - cp /usr/lib/syslinux/modules/efi64/ldlinux.e64 /mnt/boot/EFI/BOOT/
    - cp /mnt/boot/syslinux.cfg /mnt/boot/EFI/BOOT/syslinux.cfg
    - cp /mnt/root/boot/vmlinuz /mnt/boot/EFI/BOOT/
    - cp /mnt/root/boot/initrd.img /mnt/boot/EFI/BOOT/

需要注意的可能需要更改的行:

  • useraddaddgroup- 更改为您自己的用户名和密码,或保留它ubuntu/ubuntu
  • /etc/systemd/network/00-*.network- 随意更改配置文件名,并确保将接口名称(在我的情况下enp0s10f0)、IP(10.10.2.101/24)和网关(10.10.2.99)更改为您实际期望的内容
  • 如果你还安装了 DHCP 客户端包(isc-dhcp-client),你可以使用类似的方法echo [Match]; echo Name=eth0; echo [Network]; echo DHCP=yes(只需检查接口名称)
  • 您也可以完全保留脚本,并在重启后更改用户/密码或网络

通过自动安装程序运行脚本后,它将安装 Ubuntu Base 并重新启动。重新启动后,使用用户ubuntu密码ubuntu(或您自己的密码,如果您更改了密码)登录。请注意,我是不是运行的安装xubuntu-core,请参阅下面脚本中的注释,以及答案下的评论。

更多详细信息

为了解释这个过程,我还粘贴了带有所有注释的脚本,以便其他想要获得更多细节、了解这个过程并对其进行扩展以根据自己的喜好进行更改的人。

用户数据(带评论)

#cloud-config

autoinstall:
  version: 1
  early-commands:
# delete any old partition data, up to 240MB size, if this was reinstall
# erases partition tables and whole boot partition as well, by erasing 30x8MB=240MB (partition is 200MB)
    - dd if=/dev/zero of=/dev/sda bs=8M count=30
# create new 200MB boot partition and rest as root partition
    - (echo o; echo n; echo p; echo 1; echo ""; echo +200M; echo n; echo p; echo 2; echo ''; echo ''; echo a; echo 1; echo p; echo w) | fdisk /dev/sda
# format boot as FAT 32
    - mkfs.fat -F 32 -D 0x80 -M 0xF8 -n BOOT /dev/sda1
# format rest as ext4
    - mkfs.ext4 -F /dev/sda2
# create mount points for boot and root
    - mkdir /mnt/boot /mnt/root
# don't mount boot yet, as later syslinux requires it unmounted, or mount it here and unmount before syslinux -i
#    - mount /dev/sda1 /mnt/boot
    - mount /dev/sda2 /mnt/root
# optional commands to see what's mounted, note if you did not mount it, don't ls it because subiquity installer will fail
#    - df -h
#    - ls -al /mnt
#    - ls -al /mnt/boot
#    - ls -al /mnt/root
# download ubuntu Base from official repo, we download 20.10 below, this will download to / (root) of ubiquity installer, which means - into memory
# if you want 20.04 or 20.10 or anything else (future releases) just change following these two lines (curl and tar) to reflect that, plus later in script change kernel version
    - curl http://cdimage.ubuntu.com/ubuntu-base/releases/20.10/release/ubuntu-base-20.10-base-amd64.tar.gz -o /ubuntu-base-20.10-base-amd64.tar.gz
# extract all files to our sda2, mounted at /mnt/root
    - tar -xzvf /ubuntu-base-20.10-base-amd64.tar.gz -C /mnt/root
# create temporary resolv.conf in the new system
    - touch /mnt/root/etc/resolv.conf
    - echo "nameserver 8.8.8.8" > /mnt/root/etc/resolv.conf
# chroot to /mnt/root and start executing commands one by one
# update apt's package cache
    - chroot /mnt/root sh -c "apt-get update"
# install Linux image, which will install kernel and create initrd and all
# you need to install specific version depending on OS, eg 20.04 will use linux-image-5.4.0-42-generic
# we also install: init, dbus, iproute2, sudo, which also pull systemd - to have actually usable system
# additionally install nano to be able to edit confs, you can change that to any other editor
    - chroot /mnt/root sh -c "apt-get install -y linux-image-5.8.0-28-generic initramfs-tools init dbus iproute2 sudo nano --no-install-recommends"
# I personally always install openssh-server as well, ping for debugging
# and you may also want to add isc-dhcp-client package to enable networking setup by DHCP server
    - chroot /mnt/root sh -c "apt-get install -y openssh-server isc-dhcp-client iputils-ping --no-install-recommends"
# add at least one user, here we add user ubuntu with password ubuntu, change it here or later after first login
    - chroot /mnt/root sh -c "useradd -m ubuntu -s '/bin/bash' && echo ubuntu:ubuntu | chpasswd"
# add this new user to correct groups to enable it to be admin and to have sudo access
    - chroot /mnt/root sh -c "addgroup ubuntu adm"
    - chroot /mnt/root sh -c "addgroup ubuntu sudo"
# this would installs Xubuntu ... or switch to whatever you need... if you install some other package or desktop environment - it will be there after your login
# but it is quite large (2GB) so if ANY package fails or throws ANY error - whole subiquity installer crashes; so I recommend this to be done on first interactive login after reboot
#    - chroot /mnt/root sh -c "apt-get install -y xubuntu-core"
# below is syslinux install the easy way, through Ubuntu's official package/repo
# get the syslinux package, note this is not in chroot, this installs just to subiquity memory, so we need to run apt update again
    - apt-get update
    - apt-get install -y syslinux
# tell syslinux to install itself to your sda1 which is your boot partition
# if you mounted it earlier, unmount boot!! use command below (which is commented out by default)
#    - umount /mnt/boot
    - syslinux -i /dev/sda1
# now that syslinux is installed, burn it's mbr.bin (or maybe gptmbr.bin if you plan to use GPT + UEFI) to start of your disk; note we target whole device "sda" - NOT sda1
    - dd if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sda bs=440 count=1 conv=notrunc
# now we can safely mount boot partition
    - mount /dev/sda1 /mnt/boot
# we create syslinux.cfg, I do touch, as if it doesn't exist it will break subiquity again
    - touch /mnt/boot/syslinux.cfg
# echo your config to it; explaining
# PROMPT 0 - don't ask use default / 1 - ask for user input (good for diag); DEFAULT - set which label is default so syslinux can autoboot; LABEL - this is config for our Ubuntu Base OS; KERNEL - vmlinuz or eqivalent kernel name; APPEND - to mount your /root partiton as writeable; INITRD - name of your initrd image
    - (echo PROMPT 0; echo DEFAULT base; echo LABEL base; echo KERNEL vmlinuz; echo APPEND root=/dev/sda2 rw; echo INITRD initrd.img) > /mnt/boot/syslinux.cfg
# copy vmlinuz & initrd files that you've installed in your chroot, you can specify exact version, just make sure to change syslinux.cfg echo (above) accordingly
# can also copy * to copy all, but all we need is these ones really
    - cp /mnt/root/boot/vmlinuz /mnt/boot
    - cp /mnt/root/boot/initrd.img /mnt/boot
# setup EFI boot, you can keep both BIOS and UEFI bootloaders at the same time
# install additional package
    - apt-get install -y syslinux-efi
# create directories, will create both BOOT and parent EFI folders
    - mkdir -p /mnt/boot/EFI/BOOT/
# copy all files, in order: UEFI bootloader, bootloader's module (required), syslinux config (same as above), kernel and initrd (same as above)
    - cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi /mnt/boot/EFI/BOOT/BOOTX64.EFI
    - cp /usr/lib/syslinux/modules/efi64/ldlinux.e64 /mnt/boot/EFI/BOOT/
    - cp /mnt/boot/syslinux.cfg /mnt/boot/EFI/BOOT/syslinux.cfg
    - cp /mnt/root/boot/vmlinuz /mnt/boot/EFI/BOOT/
    - cp /mnt/root/boot/initrd.img /mnt/boot/EFI/BOOT/
# now we create network config, make sure to change: interface name, IP, gateway
    - touch /mnt/root/etc/systemd/network/00-wired.network
    - (echo [Match]; echo Name=enp0s10f0; echo [Network]; echo Address=10.10.2.101/24; echo Gateway=10.10.2.99; echo DNS=8.8.8.8) > /mnt/root/etc/systemd/network/00-wired.network
# and enable networkd service so it runs on first boot already
    - chroot /mnt/root sh -c "systemctl enable systemd-networkd.service"
# this is optional, but cleans 100+MB from our chroot partition
    - chroot /mnt/root sh -c "apt-get clean"
# and finally, I leave this uncommented sometimes, to allow me to do anything in interactive bash shell before final reboot (or to just pause and wait for you if you took coffee and don't want your system to reboot unattended)
#    - bash -c "exec bash"
# unmount partitions
    - umount /mnt/boot
    - umount /mnt/root
# and reboot!
    - reboot
# after reboot login with your user (ubuntu/ubuntu in this script) and complete installation and/or configuration
# you can also connect using ssh to this machine, sudo, and install or configure whatever you wish! Congrats!

带注释的脚本也可以按原样使用,复制/粘贴。和以前一样,请检查您的用户/密码和网络(接口名称、IP、网关等)。同样,它将不是安装 Xubuntu,我已经将其注释掉了。

这将引导至 400MB/(根)分区以下的位(加上用于引导的小分区,它设置为 200MB,但可以更小,BIOS+EFI 文件大约需要 58MB)。添加 Xubuntu Core 需要大约 1.8GB(apt 如此表示)。xubuntu-core安装后,分区使用量增加到 2.4GB,之后apt clean下降到 1.9GB,因此它更像是 Ubuntu Base 之上的 1.5GB 额外空间。

如果您遇到任何问题,请告诉我,以便为每个人修复说明。

这一切都是在 Ubuntu 上测试的20.04.1(PXE 服务器、实时安装 ISO 映像和基本映像)以及 20.10“客户端”,并且对于任何未来版本都应该相同或相似,只要您在需要的地方更改文件名(例如在 curl 和 tar 命令中,以及 apt 安装 linux 映像的地方)。其余部分应该相同,直到 Canonical 更改某些内容。

测试环境(PXE 服务器和服务以及测试客户端)均在 Hyper-V VM 上完成。

注意:这最初是针对旧版 BIOS 安装的,现在我已添加 UEFI 支持。UEFI 的更改很小,syslinux 安装已扩展。

文档:

Ubuntu Base wiki(已过时)

Ubuntu Base 存储库

Ubuntu 基础安装示例指南(严重过时,GUI 工具)

编辑 - 2020-11-22:修改了 Ubuntu 20.10 的脚本。如果您查看修订历史记录,早期的脚本适用于 20.04.1,但与此同时我也做了一些调整,因此请比较它们以查看更改。

编辑 - 2020-12-06:修改了脚本,使其更简单、更直接,具有更好的网络,并添加了 EFI 引导加载程序支持。我做到了不是为 20.04 编写新脚本,但实际上只有带有curltarapt-get install的行linux-image-x.x.x-xx-generic需要更改,您可以检查此答案的修订版本,并且第一个版本具有 20.04.1 Ubuntu Base 及其内核的路径和名称。

答案2

你说得对。Xubuntu Core 无法在 VirtulaBox 6.1 上安装

此时,唯一的选择是上网、创建用户 ID,然后让机器离线。

请拜访https://core.docs.ubuntu.com/en/guides/manage-devices/安装 Xubuntu Core,以防您想调整这个要求并创建一个新的 ISO...

相关内容