关于Ubuntu的神秘Snap设置及其移除

在22.04中使用最小安装系统会强制自带一个snap,虽然它是空的,没有自带任何snap包,但是依旧不能删除。

原因是snap被写进了ubuntu-server-minimal这个元包的依赖关系里,让我们来看看Canonical有多逆天。

Package: ubuntu-server-minimal
Version: 1.481.2
Priority: optional
Section: metapackages
Source: ubuntu-meta
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 54.3 kB
Depends: apparmor, apport, apt, bcache-tools, btrfs-progs, cloud-init, cryptsetup, dbus, lvm2, mdadm, multipath-tools, netbase, ntfs-3g, open-iscsi, pollinate, snapd, ssh-import-id, sudo, systemd, systemd-sysv, ubuntu-drivers-common, ubuntu-release-upgrader-core, udev, xfsprogs
Recommends: needrestart, unattended-upgrades
Task: server-minimal
Download-Size: 2692 B
APT-Manual-Installed: yes
APT-Sources: http://mirrors.tencent.com/ubuntu jammy-updates/main amd64 Packages
Description: The Ubuntu Server minimal systemThis package depends on all of the packages in the Ubuntu Server minimalsystem.It is also used to help ensure proper upgrades, so it is recommended thatit not be removed.

有多逆天才能想到把snap塞进这个元包里,没看见里面坐着APTsudosystemd

这问题也不是第一天了,在不删除 ubuntu-server-minimal 的情况下删除snap-asked Jul 9, 2022 at 23:56

另外还有月度新闻 – 2020 年 5 月 – The Linux Mint 博客,Linux Mint作为Ubuntu的下游版本移除了snap,因为Ubuntu只提供snap版本的Chromium。

还有更加神秘的Installing snap on Linux Mint | Snapcraft documentation,我不知道他们怎么好意思的。

不过还好只是在最小安装里强依赖,只要恢复到标准版就可以卸载了,原因也很简单,在ubuntu-serversnapd只是一个推荐包。

sudo unminimize

但先不急,让我们看看又发生了什么。

Package: lxd-installer
Version: 1
Priority: optional
Section: admin
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 22.5 kB
Conflicts: lxd
Download-Size: 3108 B
APT-Sources: http://mirrors.tencent.com/ubuntu jammy/main amd64 Packages
Description: Wrapper to install lxd snap on demand Installing this package in an image instead of the lxd snap allows it to be smaller whilst preserving the command line interface of the full server image.

snap现在不是空的了,已经准备好工作了。

snap list
Name    Version         Rev    Tracking       Publisher   Notes
core22  20240408        1380   latest/stable  canonical✓  base
lxd     5.21.2-34459c8  29568  5.21/stable    canonical✓  -
snapd   2.63            21759  latest/stable  canonical✓  snapd

多么熟悉的三件套,它又回来了。不过接下来也简单,只要依次卸载lxdcorexxsnapd就行了。

然而意外发生了,这个逼养的命令没有恢复到标准版,不过也无所谓了。

sudo apt install ubuntu-server

我把你爹请来就行了,你可以麻溜的滚蛋了。

sudo apt autoremove --purge snapd*

结束。

总结:直接请它爹来,APTsudosystemd等众位大哥会自己变成手动安装,不用担心依赖崩溃进而使系统崩溃。

另附:

使用unminimize解除最小安装后的22.04Ubuntu手动安装标记软件列表

base-files
base-passwd
bash
bsdutils
dash
diffutils
e2fsprogs
findutils
grep
gzip
hostname
libc-bin
libdebconfclient0
libss2
linux-generic
login
mawk
ncurses-bin
openssh-server
sysvinit-utils
ubuntu-minimal
ubuntu-server-minimal
ubuntu-standard
usrmerge

使用ubuntu-server替换ubuntu-server-minimal后。

apparmor
apport
apt
base-files
base-passwd
bash
bcache-tools
bsdutils
btrfs-progs
cloud-init
cryptsetup
dash
dbus
diffutils
e2fsprogs
findutils
grep
gzip
hostname
libc-bin
libdebconfclient0
libss2
linux-generic
login
lvm2
mawk
mdadm
multipath-tools
ncurses-bin
needrestart
netbase
ntfs-3g
open-iscsi
openssh-server
pollinate
ssh-import-id
sudo
systemd
systemd-sysv
sysvinit-utils
ubuntu-drivers-common
ubuntu-minimal
ubuntu-release-upgrader-core
ubuntu-server
ubuntu-standard
udev
unattended-upgrades
usrmerge
xfsprogs

标准安装的Ubuntu22.04

base-files
base-passwd
bash
cloud-init
dash
diffutils
efibootmgr
findutils
grep
grub-efi-amd64
grub-efi-amd64-signed
gzip
hostname
init
libc6
libdebconfclient0
libsodium23
linux-generic
linux-generic-hwe-20.04
ncurses-base
ncurses-bin
openssh-server
python3-nacl
python3-pymacaroons
shim-signed
sysvinit-utils
ubuntu-minimal
ubuntu-server
ubuntu-standard

整个依赖关系已经乱糟糟的了,感觉还是重装简单。

尝试抢救一下,手动恢复auto标记看看。

sudo apt-mark auto auto xfsprogs ubuntu-drivers-common ubuntu-release-upgrader-core unattended-upgrades udev pollinate ssh-import-id sudo systemd systemd-sysv systemd-sysv open-iscsi ntfs-3g netbase needrestart multipath-tools mdadm lvm2 dbus cryptsetup cloud-init btrfs-progs bcache-tools apt apport apparmor 

检查一下包依赖关系

sudo apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  python3-xkit ubuntu-drivers-common
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 415 kB disk space will be freed.
Do you want to continue? [Y/n] n

在标准版里检查这两个包,发现没有被默认安装,由此可见最小安装也没有直接恢复到标准版。

神秘。