Ubuntu 20.04 升级到 22.04 的标准流程如下,按步骤操作即可:


1. 升级前准备

备份重要数据 — 升级前务必备份 /home 目录及重要配置文件。

更新现有系统:

sudo apt update
sudo apt upgrade -y
sudo apt dist-upgrade -y
sudo apt autoremove -y
sudo apt install update-manager-core -y

2. 修改升级配置

编辑配置文件,确保允许升级到 LTS 版本:

sudo nano /etc/update-manager/release-upgrades

Prompt 修改为:

Prompt=lts

保存退出(Ctrl+O,回车,Ctrl+X)。


3. 执行升级

sudo do-release-upgrade
  • 如果提示 "No new release found",可以加上 -d 参数强制检查:

    sudo do-release-upgrade -d
  • 过程中会多次询问确认,按提示输入 Y 或按回车继续。

  • 升级过程可能需要 30 分钟到数小时,取决于网络速度和硬件性能。


4. 升级完成后

重启系统:

sudo reboot

重启后验证版本:

lsb_release -a

应显示 Ubuntu 22.04.x LTS (Jammy Jellyfish)


⚠️ 注意事项

  1. 20.04 已结束标准支持(2025 年 4 月),建议尽快升级。
  2. 如果有 PPA 源第三方软件源,升级后可能需要重新添加适配 22.04 的版本。
  3. 服务器环境建议先在测试环境验证,避免生产环境直接升级。
  4. 若使用 SSH 远程连接,建议在本地控制台操作,或确保有 IPMI/iLO 等备用连接方式,防止网络中断导致升级失败。

完全卸载软件步骤

要完全卸载 Variety(包括软件包、系统配置、用户配置),按以下步骤执行:

1. 先停止 Variety 进程

pkill -f variety

2. 完全卸载软件包 + 系统级配置文件

sudo apt purge variety

3. 删除用户级配置文件和缓存

rm -rf ~/.config/variety
rm -rf ~/.cache/variety
rm -f ~/.config/autostart/variety.desktop

4. 清理不再需要的依赖包

sudo apt autoremove

5. 可选:清理 apt 下载缓存

sudo apt clean

多系统启动grub.cfg

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${initrdfail}" = 2 ]; then
   set initrdfail=
elif [ "${initrdfail}" = 1 ]; then
   set next_entry="${prev_entry}"
   set prev_entry=
   save_env prev_entry
   if [ "${next_entry}" ]; then
      set initrdfail=2
   fi
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}
function initrdfail {
    if [ -n "${have_grubenv}" ]; then if [ -n "${partuuid}" ]; then
      if [ -z "${initrdfail}" ]; then
        set initrdfail=1
        if [ -n "${boot_once}" ]; then
          set prev_entry="${default}"
          save_env prev_entry
        fi
      fi
      save_env initrdfail
    fi; fi
}
function recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_gpt
insmod ext2
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root  a104621c-4598-4c2f-95ca-52517d9c926e
else
  search --no-floppy --fs-uuid --set=root a104621c-4598-4c2f-95ca-52517d9c926e
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=zh_CN
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; then
  set timeout=10
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=hidden
    set timeout=0
  # Fallback hidden-timeout code in case the timeout_style feature is
  # unavailable.
  elif sleep --interruptible 0 ; then
    set timeout=0
  fi
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
    set gfxpayload="${1}"
    if [ "${1}" = "keep" ]; then
        set vt_handoff=vt.handoff=7
    else
        set vt_handoff=
    fi
}
if [ "${recordfail}" != 1 ]; then
  if [ -e ${prefix}/gfxblacklist.txt ]; then
    if [ ${grub_platform} != pc ]; then
      set linux_gfx_mode=keep
    elif hwmatch ${prefix}/gfxblacklist.txt 3; then
      if [ ${match} = 0 ]; then
        set linux_gfx_mode=keep
      else
        set linux_gfx_mode=text
      fi
    else
      set linux_gfx_mode=text
    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
export linux_gfx_mode
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-a104621c-4598-4c2f-95ca-52517d9c926e' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part_gpt
    insmod ext2
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root  a104621c-4598-4c2f-95ca-52517d9c926e
    else
      search --no-floppy --fs-uuid --set=root a104621c-4598-4c2f-95ca-52517d9c926e
    fi
    linux   /boot/vmlinuz-5.15.0-139-generic root=UUID=a104621c-4598-4c2f-95ca-52517d9c926e ro  quiet splash $vt_handoff
    initrd  /boot/initrd.img-5.15.0-139-generic
}
submenu 'Ubuntu 的高级选项' $menuentry_id_option 'gnulinux-advanced-a104621c-4598-4c2f-95ca-52517d9c926e' {
    menuentry 'Ubuntu,Linux 5.15.0-139-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-139-generic-advanced-a104621c-4598-4c2f-95ca-52517d9c926e' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_gpt
        insmod ext2
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root  a104621c-4598-4c2f-95ca-52517d9c926e
        else
          search --no-floppy --fs-uuid --set=root a104621c-4598-4c2f-95ca-52517d9c926e
        fi
        echo    '载入 Linux 5.15.0-139-generic ...'
        linux   /boot/vmlinuz-5.15.0-139-generic root=UUID=a104621c-4598-4c2f-95ca-52517d9c926e ro  quiet splash $vt_handoff
        echo    '载入初始化内存盘...'
        initrd  /boot/initrd.img-5.15.0-139-generic
    }
    menuentry 'Ubuntu, with Linux 5.15.0-139-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-139-generic-recovery-a104621c-4598-4c2f-95ca-52517d9c926e' {
        recordfail
        load_video
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_gpt
        insmod ext2
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root  a104621c-4598-4c2f-95ca-52517d9c926e
        else
          search --no-floppy --fs-uuid --set=root a104621c-4598-4c2f-95ca-52517d9c926e
        fi
        echo    '载入 Linux 5.15.0-139-generic ...'
        linux   /boot/vmlinuz-5.15.0-139-generic root=UUID=a104621c-4598-4c2f-95ca-52517d9c926e ro recovery nomodeset dis_ucode_ldr 
        echo    '载入初始化内存盘...'
        initrd  /boot/initrd.img-5.15.0-139-generic
    }
    menuentry 'Ubuntu,Linux 5.15.0-67-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-67-generic-advanced-a104621c-4598-4c2f-95ca-52517d9c926e' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_gpt
        insmod ext2
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root  a104621c-4598-4c2f-95ca-52517d9c926e
        else
          search --no-floppy --fs-uuid --set=root a104621c-4598-4c2f-95ca-52517d9c926e
        fi
        echo    '载入 Linux 5.15.0-67-generic ...'
        linux   /boot/vmlinuz-5.15.0-67-generic root=UUID=a104621c-4598-4c2f-95ca-52517d9c926e ro  quiet splash $vt_handoff
        echo    '载入初始化内存盘...'
        initrd  /boot/initrd.img-5.15.0-67-generic
    }
    menuentry 'Ubuntu, with Linux 5.15.0-67-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-67-generic-recovery-a104621c-4598-4c2f-95ca-52517d9c926e' {
        recordfail
        load_video
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_gpt
        insmod ext2
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root  a104621c-4598-4c2f-95ca-52517d9c926e
        else
          search --no-floppy --fs-uuid --set=root a104621c-4598-4c2f-95ca-52517d9c926e
        fi
        echo    '载入 Linux 5.15.0-67-generic ...'
        linux   /boot/vmlinuz-5.15.0-67-generic root=UUID=a104621c-4598-4c2f-95ca-52517d9c926e ro recovery nomodeset dis_ucode_ldr 
        echo    '载入初始化内存盘...'
        initrd  /boot/initrd.img-5.15.0-67-generic
    }
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/10_linux_zfs ###
### END /etc/grub.d/10_linux_zfs ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Windows Boot Manager (在 /dev/nvme0n1p1)' --class windows --class os $menuentry_id_option 'osprober-efi-ED30-73C2' {
    insmod part_gpt
    insmod fat
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root  ED30-73C2
    else
      search --no-floppy --fs-uuid --set=root ED30-73C2
    fi
    chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
set timeout_style=menu
if [ "${timeout}" = 0 ]; then
  set timeout=10
fi
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
    fwsetup
}
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/35_fwupd ###
### END /etc/grub.d/35_fwupd ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

多内核清理

在 Ubuntu 上清理旧内核可以释放 /boot 分区的空间。以下是安全操作步骤:

1. 查看当前正在使用的内核

uname -r

务必记住这个版本号,不要删除它。

2. 查看已安装的所有内核

dpkg -l | grep linux-image
dpkg -l | grep linux-headers

3. 自动清理(推荐)

Ubuntu 通常会自动保留最近两个内核。运行以下命令自动删除不再需要的旧内核:

sudo apt autoremove --purge

如果提示保留当前内核和上一个内核,确认即可。

4. 手动删除特定旧内核

如果 autoremove 没有清理干净,可以手动删除。例如删除 5.15.0-76-generic

sudo apt remove --purge linux-image-5.15.0-76-generic linux-headers-5.15.0-76-generic

5. 更新 GRUB 引导

sudo update-grub

6. 验证清理结果

df -h /boot
dpkg -l | grep linux-image

⚠️ 注意事项

  • 永远不要删除当前正在使用的内核uname -r 显示的那个)。
  • 建议至少保留 2 个内核(当前使用的 + 上一个稳定的),以防新内核出现问题无法启动。
  • 如果 /boot 分区已满导致 apt 无法运行,可以先手动删除一个最旧的内核包,释放空间后再执行 autoremove

如果你想彻底清理所有 5.15 内核

如果你确定不需要 5.15 内核作为 fallback,可以一次性清理:

sudo apt remove --purge \
    linux-image-5.15.0-139-generic \
    linux-image-5.15.0-186-generic \
    linux-headers-5.15.0-139 \
    linux-headers-5.15.0-139-generic \
    linux-headers-5.15.0-186 \
    linux-headers-5.15.0-186-generic \
    linux-image-generic \
    linux-headers-generic

sudo apt autoremove --purge
sudo update-grub

执行完命令后可以再贴一下 dpkg -l | grep linux-image 的输出,我帮你确认是否清理干净。

dpkg -l | grep linux-image
ii  linux-image-5.15.0-139-generic             5.15.0-139.149                                   amd64        Signed kernel image generic
ii  linux-image-5.15.0-186-generic             5.15.0-186.196                                   amd64        Signed kernel image generic
ii  linux-image-6.8.0-136-generic              6.8.0-136.136~22.04.1                            amd64        Signed kernel image generic
ii  linux-image-generic-hwe-22.04              6.8.0-136.136~22.04.1                            amd64        Generic Linux kernel image

5.15.0-139 这个最旧的内核还在,说明删除没有生效。可能是有依赖关系,或者命令执行时出错了。

直接删除 139 内核

# 先强制删除 139 的内核镜像和头文件
sudo dpkg --purge linux-image-5.15.0-139-generic linux-headers-5.15.0-139-generic linux-headers-5.15.0-139

# 如果上面报错说有依赖,改用 remove
sudo apt remove --purge linux-image-5.15.0-139-generic linux-headers-5.15.0-139-generic linux-headers-5.15.0-139

# 清理残留并更新引导
sudo apt autoremove --purge
sudo update-grub

如果报错依赖问题

如果提示 linux-image-5.15.0-139-generic 被其他包依赖,先解除依赖再删:

# 查看谁依赖了它
apt-cache rdepends linux-image-5.15.0-139-generic

# 强制删除(忽略依赖)
sudo dpkg --force-all --purge linux-image-5.15.0-139-generic
sudo apt --fix-broken install
sudo update-grub

# 必须一次性把所有 139 相关的包一起删掉,才能彻底清理
sudo apt remove --purge \
    linux-image-unsigned-5.15.0-139-generic \
    linux-modules-5.15.0-139-generic \
    linux-modules-extra-5.15.0-139-generic \
    linux-headers-5.15.0-139 \
    linux-headers-5.15.0-139-generic

sudo apt autoremove --purge
sudo update-grub