我该如何修复 Xubuntu 启动时出现的“无法激活交换 /swapfile”错误?

我该如何修复 Xubuntu 启动时出现的“无法激活交换 /swapfile”错误?

当我启动笔记本电脑时,我看到:

systemd[1]: Failed to activate swap /swapfile.
[FAILED]: Failed to activate swap /swapfile.
[DEPEND]: Dependency failed for swap.

然后我被带到 Ubuntu 终端。

我正在使用 Xubuntu 21.10。

一旦我登录终端,我就会看到:

/usr/lib/ubuntu-release-upgrader/release-upgrade-motd: 39: cannot create /var/lib/ubuntu/release-upgrader/release-upgrade-available: Read-only file system
mktemp: failed to create file via template '/var/lib/update-notifier/tmp.XXXXXXXXXX': Read-only file system
run-parts: /etc/update-motd.d/95-hwe-eol exited with return code 1
/usr/lib/update-notifier/update-motd-fsck-at-reboot: 38: cannot create /var/lib/update-notifier/fsck-at-reboot: Read-only file system
cat: /var/lib/update-notifier/fsck-at-reboot: No such file or directory
run-parts: /etc/update-motd.d/98-fsck-at-reboot exited with return code 1

我怎样才能修复出错的地方?

注意:我正在使用休眠模式,因此我需要 16 GB 的交换文件。

这里是一个带有启动修复输出的 Pastebin。

ls -al /显示:

total 16777312

drwxr-xr-x  20  root    root            4096        mar 16  18:09   .
drwxr-xr-x  20  root    root            4096        mar 16  18:09   ..
lrwxrwxrwx  1   root    root            7           mar 14  07:09   bin -> usr/bin
drwxr-xr-x  4   root    root            4096        apr 22  07:02   boot
drwxrwxr-x  2   root    root            4096        mar 14  07:11   cdrom
drwxr-xr-x  21  root    root            4800        may 2   05:57   dev
drwxr-xr-x  141 root    root            12288       may 1   08:39   etc
drwxr-xr-x  3   root    root            4096        mar 14  07:11   home
lrwxrwxrwx  1   root    root            7           mar 14  07:09   lib -> usr/lib
lrwxrwxrwx  1   root    root            9           mar 14  07:09   lib32 -> usr/lib32
lrwxrwxrwx  1   root    root            9           mar 14  07:09   lib64 -> usr/lib64
lrwxrwxrwx  1   root    root            10          mar 14  07:09   libx32 -> usr/libx32
drwx------  2   root    root            16384       mar 14  07:09   lost+found
drwxr-xr-x  3   root    root            4096        mar 14  17:51   media
drwxr-xr-x  3   root    root            4096        apr 1   17:19   mnt
drwxr-xr-x  3   root    root            4096        mar 14  07:47   opt
dr-xr-xr-x  246 root    root            0           may 2   05:57   proc
drwx------  9   root    root            4096        apr 25  16:10   root
drwxr-xr-x  30  root    root            880         may 2   05:57   run
lrwxrwxrwx  1   root    root            8           mar 14  07:09   sbin -> usr/sbin
drwxr-xr-x  29  root    root            4096        apr 29  14:22   snap
drwxr-xr-x  2   root    root            4096        okt 12  2021    srv
-rw-------  1   root    root     17179869184        mar 16  18:34   swapfile
dr-xr-xr-x  13  root    root            0           may 2   05:57   sus
drwxrwxrwt  8   root    root            12288       may 1   08:40   tmp
drwxr-xr-x  15  root    root            4096        apr 6   18:08   usr
drwxr-xr-x  14  root    root            4096        okt 12  2021    var

cat /proc/mounts显示:

/dev/nvme0n1p2  /           ext4 ro,relatime 0 0
/dev/nvme0n1p2  /mnt/hd2    ext4 ro,relatime 0 0
/dev/nvme0n1p1  /boot/efi   vfat rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0

看来我以某种方式设法将根分区也挂载为非根挂载文件夹,我猜这是不正确的。

设备 SMART 数据(这是 NVMe SSD):

ubuntu@ubuntu:~$ sudo nvme smart-log /dev/nvme0
Smart Log for NVME device:nvme0 namespace-id:ffffffff
critical_warning                        : 0
temperature                             : 29 C
available_spare                         : 100%
available_spare_threshold               : 10%
percentage_used                         : 1%
endurance group critical warning summary: 0
data_units_read                         : 15,270,156
data_units_written                      : 12,745,135
host_read_commands                      : 158,291,363
host_write_commands                     : 162,929,827
controller_busy_time                    : 4,393
power_cycles                            : 1,257
power_on_hours                          : 1,912
unsafe_shutdowns                        : 43
media_errors                            : 0
num_err_log_entries                     : 0
Warning Temperature Time                : 0
Critical Composite Temperature Time     : 0
Thermal Management T1 Trans Count       : 116
Thermal Management T2 Trans Count       : 0
Thermal Management T1 Total Time        : 464
Thermal Management T2 Total Time        : 0

只读文件系统故障排除:

ubuntu@ubuntu:~$ sudo fdisk -l

Disk /dev/nvme0n1: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: KINGSTON SA2000M8500G                   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F7DDADFD-E9EA-445D-8A89-E71D0688372F

Device           Start       End   Sectors   Size Type
/dev/nvme0n1p1    2048   1050623   1048576   512M EFI System
/dev/nvme0n1p2 1050624 976771071 975720448 465.3G Linux filesystem

ubuntu@ubuntu:~$ sudo fsck -f /dev/nvme0n1p2
fsck from util-linux 2.36.1
e2fsck 1.46.3 (27-Jul-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/nvme0n1p2: 570684/30498816 files (0.9% non-contiguous), 86783963/121965056 blocks

输出grep -i nvme /var/log/syslog*(略有删节):

ubuntu@ubuntu:~$ grep -i nvme /var/log/syslog*
/var/log/syslog: systemd-fsck[811]: /dev/nvme0n1p1: 20 file, 2337/130812 clusters
/var/log/syslog: kernel: nvme nvme0: pci function 0000:02:00.0
/var/log/syslog: kernel: nvme nvme0: missing or invalid SUBNQN field.
/var/log/syslog: kernel: nvme nvme0: 4/0/0 default/read/poll queues
/var/log/syslog: kernel: nvme nvme0: nvme0n1: p1 p2
/var/log/syslog: kernel: nvme nvme0: EXT4-fs (nvme0n1p2): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
/var/log/syslog: kernel: nvme nvme0: EXT4-fs (nvme0n1p2): re-mounted. Opts: errors=remount-ro. Quota mode: none.
/var/log/syslog: sensors[942]: nvme-pci-0200

也许是因为我们有两个条目,所以重新安装正在发生/proc/mounts

输出cat /etc/fstab(略有删节):

# / was on /dev/nvme0n1p2 during installation
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=D3D0-8EA5    /boot/efi    vfat     umask=0077    0    1
/swapfile                               none         swap  sw    0    0
UUID=7815fe4f-cefe-49da-ba97-e12382a98395 /mnt/hd2 ext4 errors=remount-ro 0 1

ls -al /boot注释掉/swapfile以下行之后的输出/etc/fstab

ls -al /boot

total 116196

drwxr-xr-x  20  root    root            4096        apr 22  07:02   .
drwxr-xr-x  20  root    root            4096        mar 16  18:09   ..
-rw-r--r--  1   root    root            257253      mar 24  16:24   config-5.13.0-39-generic
-rw-r--r--  1   root    root            257253      mar 29  16:09   config-5.13.0-40-generic
drwx------  3   root    root            4096        jan 1   1970    efi
drwxr-xr-x  4   root    root            4096        apr 20  06:22   grub
lrwxrwxrwx  1   root    root            28          apr 20  06:21   initrd.img -> initrd.img-5.13.0-40-generic
-rw-r--r--  1   root    root            43008308    mar 31  06:21   initrd.img-5.13.0-39-generic
-rw-r--r--  1   root    root            42423530    apr 22  07:02   initrd.img-5.13.0-40-generic
lrwxrwxrwx  1   root    root            28          apr 20  06:21   initrd.img.old -> initrd.img-5.13.0-39-generic
-rw-r--r--  1   root    root            182704      oct 7   2021    memtest86+.bin
-rw-r--r--  1   root    root            184380      oct 7   2021    memtest86+.elf
-rw-r--r--  1   root    root            184884      oct 7   2021    memtest86+_multiboot.bin
-rw-------  1   root    root            5975219     mar 24  16:24   System.map-5.13.0-39-generic
-rw-------  1   root    root            5976259     mar 29  16:09   System.map-5.13.0-40-generic
lrwxrwxrwx  1   root    root            25          apr 20  06:21   vmlinuz -> vmlinux-5.13.0-40-generic
-rw-------  1   root    root            10242240    mar 24  16:27   vmlinuz-5.13.0-39-generic
-rw-------  1   root    root            5975219     mar 24  16:13   vmlinuz-5.13.0-40-generic
lrwxrwxrwx  1   root    root            25          apr 20  06:21   vmlinuz -> vmlinux-5.13.0-39-generic

输出sudo filefrag -v /swapfile |grep " 0:"| awk '{print $4}'

98336768..

输出grep -i GRUB /etc/default/grub

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
#   info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=7815fe4f-cefe-49da-ba97-e12382a98395 resume_offset=98336768"
GRUB_CMDLINE_LINUX=""
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

答案1

R/O文件系统

您的文件系统已变为只读。

  • 以“试用 Ubuntu”模式启动 Ubuntu Live DVD/USB
  • terminalCtrl+ Alt+打开窗口T
  • 类型sudo fdisk -l
  • 识别“Linux 文件系统”的 /dev/sdXX 设备名称
  • 输入sudo fsck -f /dev/sdXX,替换sdXX为您之前找到的数字
  • fsck如果有错误则重复命令
  • 类型reboot

现在我们解决导致 SSD 进入只读模式的真正问题。

启动到恢复模式,Root 访问

在里面terminal...

sudo mount -o rw,remount /# 以 r/w 模式重新挂载 SSD。

编辑/etc/fstab...

改变...

UUID=7815fe4f-cefe-49da-ba97-e12382a98395 /mnt/hd2 ext4 errors=remount-ro 0 1

UUID=7815fe4f-cefe-49da-ba97-e12382a98395 / ext4 errors=remount-ro 0 1

并取消注释我们之前注释掉的 /swapfile 行。

保存文件并正常重启。

free -h# 确认 /swapfile 显示正确


交换/休眠

我们将 resume= 和 resume_offset= 添加到 /etc/default/grub。

在里面terminal...

sudo filefrag -v /swapfile |grep " 0:"| awk '{print $4}

请记下打印的号码。

编辑 /etc/default/grub。

改变...

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=7815fe4f-cefe-49da-ba97-e12382a98395 resume_offset=98336768"

sudo update-grub

reboot


SSD 固件

从安装较新的 SSD 固件https://github.com/vulgo/kingston-a2000-firmware-bin-linux。此报告有助于解决“修复可能导致驱动器在 Linux 系统上无响应的问题”。

相关内容