Xubuntu 20.04 最小安装

And*_*ger 5 xubuntu iso system-installation

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

  • 对网站的Xubuntu核心的Xubuntu描述仍然是指没有正式支持> 18.04 mini.iso。没有为20.04一mini.iso在描述这个帖子,虽然不是正式支持了。它可能随时消失或在未来版本 > 20.04 中完全停止。现在,这个镜像允许我安装一个最小版本的 Xubuntu。

  • 当安装程序崩溃时,无法安装Xubuntu Core 映像(自发布以来我尝试了多次,并且使用了不同版本的 VirtualBox): 安装程序崩溃

  • xubuntu-core通过apt在 Ubuntu 实时服务器上安装软件包,该服务器被列为 mini.iso 的推荐替代品,会产生 >4 GB 的已用磁盘空间,因此似乎与 20.04 mini.iso 执行的最小安装显着不同18.04 mini.iso。

  • Ubuntu Core 不适合我,因为它需要创建并将其链接到用户帐户。由于这个限制,我到目前为止还没有尝试过。我只想在 VM 中安装 Xubuntu 并离线使用它。

  • Ubuntu Base 太小了,需要大量的准备步骤。我只想安装Xubuntu。

鉴于这些选项,我是否遗漏了任何可以以官方支持的方式为我提供 Xubuntu 20.04 最小安装并且可能会在未来版本中得到支持的内容?

Lux*_*xZg 5

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

下面是一个自动安装模板文件,您可以使用它自动安装Ubuntu Base 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) 来完成此操作,然后通过 SSH 在 subiquity 实时会话中执行此操作。请确保启动的会话/安装程序与您计划安装的 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
Run Code Online (Sandbox Code Playgroud)

上面的脚本只是用于 BIOS / 传统启动的纯脚本,它应该按原样运行良好,复制/粘贴。

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

    - 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/
Run Code Online (Sandbox Code Playgroud)

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

  • useradd并且addgroup- 更改为您自己的用户名和密码,或保留为您自己的用户名和密码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!
Run Code Online (Sandbox Code Playgroud)

带注释的脚本也可以按原样使用,复制/粘贴。和以前一样,请检查您的用户/密码和网络(接口名称、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 基础存储库

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

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

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