惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
C
Check Point Blog
B
Blog RSS Feed
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
小众软件
小众软件
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
GbyAI
GbyAI
The Cloudflare Blog
博客园 - 叶小钗
S
SegmentFault 最新的问题
博客园 - Franky
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
B
Blog
Jina AI
Jina AI

BlogFinder

日常漫步 Vol.24 之漫步前山河 - 雅余 周报 #1-聊聊本周的收获 - Edwin's Blog 我的OpenCode必装插件与Skill Write Something 掌中之物未必在掌握之中 · CRIVU PiliNara,一个更顺手的 PiliPlus 分支 「NekoEcho」:做一个必有回响的猫娘主题博客 2026-05 书影音总结 简化博客主题 - 安迪 我第一次发布 npm 包 拾花小记#45:中考前的二三事 – 小改学习志 黛西花园5月游 #18 枇杷又熟了的五月月报 一些奇奇怪怪的需求?word仿方正书版的几个小操作 - Xiobb's Blog 0419 御温泉之旅 修复了一些bug,网站基本上趋于稳定了 - 新锐博客 又回到四十年前 如何定义成功 迷鹿屋2026已重新上线 科技冰火两重天+一周回顾 ${title} 热度退了,我反而用得更深了-咕咚同学 我到底该不该换个域名? 随身WIFI折腾记 - 安迪 博客撰写体验提升——hexo pro插件 为什么不用相机把屏幕上的接关密码拍下来? 国清寺与天台山 – Ouroboros ★★★★☆《挽救计划》——久违的经济上行感 - Davidの3号基地 删除右键“打开方式”里多余选项 第三周刊_No.53|一切都会被支付两次
Ubuntu 26.04 Btrfs+LUKS2安装
GoodBoyboy · 2026-06-18 · via BlogFinder

前言

Ubuntu官方的安装器手动安装下只能识别普通设备分区,并不能把系统安装在mapper设备上。

这篇教程非新手教程,需要有一定相关知识积累。

新手建议走官方启动器安装流程。

正文

后面教程以/dev/sda设备作为演示,请根据自身实际情况调整

创建分区

创建三个分区,怎么创建都行,这里不做演示

  • /dev/sda1 512MB EFI分区
  • /dev/sda2 1G Boot分区
  • /dev/sda3 剩余空间 系统分区

下载镜像

可以下载Desktop版,也可以下载Server版,Server版会精简很多,下面演示采用Server版,安装流程和Desktop版没有什么差别,有差别的地方后文会标注出。

制作Live CD启动盘

使用rufus工具(如果自己有其他的烧录工具都行)将镜像烧录至准备的U盘(光盘或者其他什么介质都行,能启动就行)

前置准备

重启进入Live CD环境,选择试用Ubuntu。

Desktop镜像打开终端,Server镜像按ALT+F2切换至终端。

首先查看并确认设备以及分区

1
lsblk

确认完成后切换为root用户

1
sudo -i

后面操作均以root身份操作

配置LUKS2加密容器

对系统分区进行LUKS2加密,并将其解锁。

1
2

cryptsetup luksFormat --type luks2 /dev/sda3

打开刚刚创建的加密分区,并将其映射为"cryptroot"

1
cryptsetup open /dev/sda3 cryptroot

格式化并创建Btrfs子卷

1
2
3
4
5
6
7
8

mkfs.fat -F32 /dev/sda1


mkfs.ext4 /dev/sda2


mkfs.btrfs /dev/mapper/cryptroot
1
2
3
4
mount /dev/mapper/cryptroot /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
umount /mnt

重新挂载目录树

1
2
3
4
5
mount -o subvol=@ /dev/mapper/cryptroot /mnt
mkdir -p /mnt/home
mount -o subvol=@home /dev/mapper/cryptroot /mnt/home
mount /dev/sda2 /mnt/boot
mount /dev/sda1 /mnt/boot/efi

解压SquashFS

/cdrom/casper/下,寻找后缀为.squashfs的核心系统文件

1
ls -lh /cdrom/casper/*.squashfs

Server版通常叫ubuntu-server-minimal.squashfs,桌面版可能叫filesystem.squashfs

将这个文件挂载出来

1
2
mkdir -p /tmp/squashfs
mount -o loop /cdrom/casper/ubuntu-server-minimal.squashfs /tmp/squashfs

同步系统

1
rsync -aAXv /tmp/squashfs/ /mnt/

同步完成后解除挂载

1
umount /tmp/squashfs

Chroot

1
2
for i in /dev /dev/pts /proc /sys /run; do mount -B $i /mnt$i; done
chroot /mnt /bin/bash

最小配置

配置DNS

1
2
rm -f /etc/resolv.conf
echo "nameserver 223.5.5.5" > /etc/resolv.conf

配置普通用户(不建议直接使用root用户)

1
2
adduser your_username
usermod -aG sudo your_username

配置软件源

1
2
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ resolute main restricted universe multiverse" > /etc/apt/sources.list
apt update

补齐缺少软件包

安装核心套件

1
apt install linux-image-generic grub-efi-amd64 cryptsetup-initramfs btrfs-progs -y

安装桌面环境

1
apt install ubuntu-desktop^ -y

配置fstab与crypttab

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

LUKS_UUID=$(blkid -s UUID -o value /dev/sda3)
echo "cryptroot UUID=${LUKS_UUID} none luks,discard" > /etc/crypttab


BTRFS_UUID=$(blkid -s UUID -o value /dev/mapper/cryptroot)
BOOT_UUID=$(blkid -s UUID -o value /dev/sda2)
EFI_UUID=$(blkid -s UUID -o value /dev/sda1)

cat <<EOF > /etc/fstab
UUID=${BTRFS_UUID} / btrfs subvol=@,defaults,discard=async 0 0
UUID=${BTRFS_UUID} /home btrfs subvol=@home,defaults,discard=async 0 0
UUID=${BOOT_UUID} /boot ext4 defaults 0 2
UUID=${EFI_UUID} /boot/efi vfat umask=0077 0 1
EOF

生成引导

1
2
3
update-initramfs -u -k all
grub-install /dev/sda
update-grub

安全启动(可选)

这时的引导是没有签名的,如果BIOS开启了安全启动将无法引导,如果有安全启动需求可以安装带签名的GRUB和Shim模块

1
2
3
apt install grub-efi-amd64-signed shim-signed -y
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu
update-grub

最后退出并重启

1
2
3
exit
umount -R /mnt
reboot

设置中文

此时系统是英文的,可以在设置里安装Chinese语言包,然后

1
sudo localectl set-locale LANG=zh_CN.UTF-8

删除Snap(可选)

1
2
3
4
5
sudo apt purge snapd -y
sudo rm -rf ~/snap
sudo rm -rf /snap
sudo rm -rf /var/snap
sudo rm -rf /var/lib/snapd

安装桌面环境时虽然日志中有安装snap和snap的firefox之类的组件

但是进入桌面后却没看到任何snap应用,包括应用商店,不过snap服务还是在的

Bug解决

systemd-networkd-wait-online.service卡开机问题

取消开机自启

1
2
sudo systemctl disable systemd-networkd-wait-online.service
sudo systemctl mask systemd-networkd-wait-online.service

安装Timeshift

玩Btrfs当然少不了Timeshift

1
2
sudo apt update
sudo apt install timeshift -y

安装Flatpak(可选)

1
2
sudo apt update
sudo apt install flatpak -y
1
sudo apt install gnome-software gnome-software-plugin-flatpak -y
1
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo

cardcode

Invitation

created:09/04/2015

Welcome to MyBlog

Use this card to join MyBlog and participate in a pleasant discussion together .

Welcome to GoodBoyboy 's Blog,wish you a nice day .

赞助