前言

在服务器场景中,有些虚拟机只用于单一服务、实验环境、GPU/AI 计算节点或内网运维节点,并不需要普通桌面用户目录,也不希望系统自动创建 /home 等额外分区。

Ubuntu Server 24.x 的安装器基于 Subiquity,默认安装流程会要求创建一个普通用户,并且默认磁盘布局可能会使用 LVM。这对很多通用场景是合理的,但如果目标是一个简洁的服务器系统,常见需求会变成:

  • 只保留 root 用户;
  • 不创建独立 /home 分区;
  • 不使用 LVM;
  • 磁盘只保留 EFI 分区和根分区 /
  • 安装完成后允许 root 通过 SSH 密码登录。

本文记录一套适用于 Ubuntu Server 24.x live-server 系列镜像 的完整安装流程,例如:

  • ubuntu-24.04-live-server-amd64.iso
  • ubuntu-24.04.1-live-server-amd64.iso
  • ubuntu-24.04.2-live-server-amd64.iso
  • ubuntu-24.04.3-live-server-amd64.iso
  • ubuntu-24.04.4-live-server-amd64.iso
  • 后续 Ubuntu 24.04 LTS 同系列 live-server 镜像

本文以 VMware ESXi 虚拟机为例,但安装器内的步骤同样适用于大多数虚拟化平台。

目标效果

最终系统状态如下:

用户:
  root

磁盘:
  /boot/efi    FAT32    约 1G
  /            ext4     剩余全部磁盘空间

不包含:
  /home 独立分区
  LVM
  ubuntu-vg
  ubuntu-lv
  临时安装用户

示例验证结果:

lsblk -f

期望类似:

NAME   FSTYPE FSVER LABEL UUID                                 MOUNTPOINTS
sda
├─sda1 vfat   FAT32       xxxx-xxxx                            /boot/efi
└─sda2 ext4   1.0         xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /
sr0

为什么不能在安装器里直接只创建 root

Ubuntu Server 24.x 安装器不提供“直接创建 root 用户作为唯一登录用户”的常规选项。安装过程中必须创建一个普通用户。

所以本文采用的方案是:

  1. 安装时创建临时用户 installer
  2. 安装完成后设置 root 密码;
  3. 开启 root 的 SSH 密码登录;
  4. 确认 root 登录可用后删除 installer
  5. 最终系统只保留 root。

这个方案比修改安装镜像或写 cloud-init/autoinstall 更直观,适合手动安装、临时部署和少量虚拟机初始化。

虚拟机准备

在 VMware ESXi 中创建虚拟机时,可以按以下配置:

虚拟机名称:AI Server 或自定义名称
客户机操作系统:Linux
版本:Ubuntu Linux (64-bit)
兼容性:ESXi 8.0 虚拟机或当前宿主机支持的版本
CPU:按需,例如 4 vCPU
内存:按需,例如 4 GB
硬盘:按需,例如 200 GB
网卡:连接到可 DHCP 获取地址的端口组
CD/DVD:挂载 Ubuntu Server 24.x live-server ISO
固件:UEFI

如果使用 BIOS 启动,分区细节会略有差异。本文以 UEFI 启动为主,因此会创建 /boot/efi

启动安装器

虚拟机从 ISO 启动后,进入 Ubuntu Server 安装器。

不同 Ubuntu 24.x 小版本界面文字可能略有变化,但整体页面顺序基本一致。

选择语言

页面标题通常为语言选择。

选择:

English

然后回车继续。

安装器更新

如果出现安装器更新页面,可以选择:

Continue without updating

或者保持默认继续。

生产环境中也可以选择更新安装器,但为了流程稳定,手动安装时通常直接继续即可。

键盘布局

页面通常为:

Keyboard configuration

保持默认即可:

Layout:  English (US)
Variant: English (US)

选择底部:

[ Done ]

安装类型

页面通常为:

Choose type of install

选择默认:

[X] Ubuntu Server
[ ] Ubuntu Server (minimized)

不要选择 minimized,除非你明确知道后续需要自己补齐常用工具。

如果页面中有第三方驱动选项,也可以按需选择。普通服务器场景保持默认即可。

继续:

[ Done ]

网络配置

页面通常为:

Network connections

确认网卡已经通过 DHCP 获取地址,例如:

ens34
  DHCPv4 192.168.3.49/24

只要能联网并能访问镜像源即可。

继续:

[ Done ]

代理配置

页面通常为:

Proxy configuration

如果没有 HTTP 代理,保持为空:

Proxy address: [                                      ]

继续:

[ Done ]

Ubuntu 镜像源配置

页面通常为:

Ubuntu archive mirror configuration

可以保持默认:

http://archive.ubuntu.com/ubuntu/

国内网络环境可以使用清华源:

http://mirrors.tuna.tsinghua.edu.cn/ubuntu

如果安装器自动检测到可用镜像,页面会显示类似:

This mirror location passed tests.

看到测试通过后继续:

[ Done ]

磁盘分区策略

这是本文最关键的一步。

页面通常为:

Guided storage configuration

默认可能是:

(X) Use an entire disk
    [X] Set up this disk as an LVM group

不要使用默认 LVM。选择:

( ) Use an entire disk
    [ ] Set up this disk as an LVM group

(X) Custom storage layout

然后继续:

[ Done ]

清空默认分区布局

进入:

Storage configuration

如果你看到类似下面内容,说明之前已经生成了默认 LVM 布局:

FILE SYSTEM SUMMARY

MOUNT POINT   SIZE       TYPE
/             98.472G    new ext4    new LVM logical volume
/boot          2.000G    new ext4    new partition of local disk
/boot/efi      1.049G    new fat32   new partition of local disk

USED DEVICES
ubuntu-vg
ubuntu-lv

这不是本文要的布局。

此时选择底部:

[ Reset ]

重置后,正确的初始状态应类似:

FILE SYSTEM SUMMARY

  No disks or partitions mounted.

AVAILABLE DEVICES

DEVICE       TYPE         SIZE
/dev/sda     local disk   200.000G
  free space              199.998G

USED DEVICES

  No used devices

创建 EFI 分区

AVAILABLE DEVICES 中选择:

free space

回车,选择:

Add GPT Partition

填写:

Size:   1G
Format: fat32
Mount:  /boot/efi

创建:

[ Create ]

创建完成后,USED DEVICES 中会出现:

partition 1  new, primary ESP, to be formatted as fat32, mounted at /boot/efi

创建根分区

再次选择剩余的:

free space

回车,选择:

Add GPT Partition

填写:

Size:   留空,或使用默认最大值
Format: ext4
Mount:  /

创建:

[ Create ]

检查最终分区摘要

最终页面必须类似下面这样:

Storage configuration

FILE SYSTEM SUMMARY

MOUNT POINT   SIZE       TYPE        DEVICE TYPE
/             198.948G   new ext4    new partition of local disk
/boot/efi       1.049G   new fat32   new partition of local disk

AVAILABLE DEVICES

  No available devices

USED DEVICES

DEVICE       TYPE         SIZE
/dev/sda     local disk   200.000G
partition 1  new, primary ESP, to be formatted as fat32, mounted at /boot/efi
partition 2  new, to be formatted as ext4, mounted at /

确认以下内容不存在:

/home
/boot 独立 ext4 分区
LVM volume group
ubuntu-vg
ubuntu-lv

确认无误后选择:

[ Done ]

安装器会提示写入磁盘,选择确认继续:

[ Continue ]

创建临时用户

页面通常为:

Profile configuration

Ubuntu Server 24.x 安装器必须创建一个普通用户。这里创建临时用户:

Your name:           installer
Your server's name:  ai-server
Pick a username:     installer
Choose a password:   Ubuntu123.
Confirm password:    Ubuntu123.

注意:

  • installer 只是临时用户;
  • 后面会删除;
  • 如果你不想使用本文示例密码,可以替换为自己的密码,但后续命令中的密码也要对应替换。

继续:

[ Done ]

Ubuntu Pro

页面通常为:

Upgrade to Ubuntu Pro

选择:

(X) Skip for now

继续:

[ Continue ]

SSH 配置

页面通常为:

SSH configuration

选择:

[X] Install OpenSSH server
[X] Allow password authentication over SSH
[ ] Import SSH key

不要导入 SSH key,除非你明确要使用密钥登录。

继续:

[ Done ]

Featured Server Snaps

页面通常为:

Featured Server Snaps

什么都不要选择。

直接继续:

[ Done ]

等待安装完成

页面进入:

Installing system

等待安装完成。

完成后选择:

[ Reboot Now ]

如果看到提示:

Please remove the installation medium, then press ENTER

在 ESXi 中断开 CD/DVD ISO,或者取消“启动时连接”,然后按回车。

如果重启后又进入安装器,说明仍然从 ISO 启动,需要回到虚拟机设置中断开 ISO 后再重启。

首次登录

系统启动后,可以通过控制台登录:

login: installer
Password: Ubuntu123.

也可以通过 SSH 登录:

ssh installer@192.168.3.49

192.168.3.49 替换为实际 IP。

设置 root 密码

登录 installer 后执行:

sudo passwd root

交互过程如下:

[sudo] password for installer:

这里输入临时用户密码:

Ubuntu123.

然后设置 root 密码:

New password:
Retype new password:

两次都输入:

Ubuntu123.

成功时应看到:

passwd: password updated successfully

切换到 root

执行:

su - root

输入 root 密码:

Ubuntu123.

成功后提示符类似:

root@ai-server:~#

开启 root SSH 密码登录

Ubuntu 默认不允许 root 通过 SSH 密码登录,需要手动配置。

在 root shell 中执行:

printf '%s\n' \
'PermitRootLogin yes' \
'PasswordAuthentication yes' \
> /etc/ssh/sshd_config.d/99-root-login.conf

设置文件权限:

chmod 644 /etc/ssh/sshd_config.d/99-root-login.conf

重启 SSH:

systemctl restart ssh

验证配置:

sshd -T | grep -E '^(permitrootlogin|passwordauthentication) '

正确输出应为:

permitrootlogin yes
passwordauthentication yes

验证 root SSH 登录

从本机或其他管理机测试:

ssh root@192.168.3.49

输入密码:

Ubuntu123.

登录成功后执行:

whoami
id
hostname

期望:

root
uid=0(root) gid=0(root) groups=0(root)
ai-server

删除临时用户 installer

确认 root SSH 可用后,再删除临时用户。

如果当前还有 installer 登录会话,先退出该会话。也可以在 root 中强制结束该用户进程:

pkill -KILL -u installer || true

删除用户和 home:

deluser --remove-home installer

如果看到:

userdel: user installer is currently used by process ...

说明仍然有 installer 进程占用。再次执行:

pkill -KILL -u installer || true
deluser --remove-home installer

最终验证

检查是否还存在普通用户:

getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 {print}'

期望无输出。

检查 /home

ls -la /home

期望类似:

total 8
drwxr-xr-x  2 root root 4096 ...
drwxr-xr-x 23 root root 4096 ...

检查分区:

lsblk -f

期望类似:

NAME   FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 vfat   FAT32       8E1D-746A                                 1G     1% /boot/efi
└─sda2 ext4   1.0         a434ee90-0921-4fb3-9c61-9281fe1ac06f  178.2G     3% /
sr0

检查 SSH:

sshd -T | grep -E '^(permitrootlogin|passwordauthentication) '

期望:

permitrootlogin yes
passwordauthentication yes

查看 IP:

hostname -I

示例:

192.168.3.49 2408:823c:a618:7b18::d85 ...

最终使用:

ssh root@192.168.3.49

常见问题

root 密码已经设置,但 SSH 仍然拒绝登录

先通过 installer 登录,再切换 root:

ssh installer@192.168.3.49
su - root

然后检查:

cat /etc/ssh/sshd_config.d/99-root-login.conf
sshd -T | grep -E '^(permitrootlogin|passwordauthentication) '
systemctl restart ssh

如果 sshd -T 输出仍是:

permitrootlogin without-password

说明 root 登录配置没有生效,需要重新写入:

printf '%s\n' \
'PermitRootLogin yes' \
'PasswordAuthentication yes' \
> /etc/ssh/sshd_config.d/99-root-login.conf

chmod 644 /etc/ssh/sshd_config.d/99-root-login.conf
systemctl restart ssh

删除 installer 失败

如果提示:

userdel: user installer is currently used by process ...

说明当前还有 installer 会话或进程。

使用 root 执行:

pkill -KILL -u installer || true
deluser --remove-home installer

重启后又进入安装器

说明虚拟机仍然从 ISO 启动。

在 ESXi 中检查:

虚拟机设置 -> CD/DVD 驱动器 -> 断开 ISO

或取消:

启动时连接

然后重启虚拟机。

不想用示例密码

本文中 Ubuntu123. 只是示例密码。实际使用时建议换成自己的强密码。

需要替换的位置包括:

  • 安装器中的 installer 密码;
  • sudo passwd root 设置的 root 密码;
  • 后续 SSH 登录 root 使用的密码。

总结

Ubuntu Server 24.x 默认安装流程偏向通用服务器场景,会创建普通用户,也可能默认使用 LVM。通过自定义分区和安装后清理,可以得到一个更简洁的服务器系统:

  • EFI 分区负责 UEFI 启动;
  • 根分区 / 使用全部剩余空间;
  • 不创建 /home
  • 不使用 LVM;
  • 安装后只保留 root;
  • root 可通过 SSH 密码登录。

这套流程适合 VMware ESXi 中的 Ubuntu Server 24.x 系列 live-server 镜像,也适合需要快速重复部署的内网服务器环境。

标签: Linux, Ubuntu

添加新评论