如何启用似乎隐藏的交换分区?

如何启用似乎隐藏的交换分区?

在尝试排除内存不足且经常崩溃的机器故障时: 如果机器内存不足并崩溃,我该怎么办?

我发现虽然在以下位置有一个交换分区/dev/sda8

Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 sectors
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: 9A31978F-5B21-44F6-BF08-34F2D2AD62B6

Device         Start       End   Sectors  Size Type
/dev/sda1       2048   2050047   2048000 1000M Windows recovery environment
/dev/sda2    2050048   2582527    532480  260M EFI System
/dev/sda3    2582528   2844671    262144  128M Microsoft reserved
/dev/sda4    2846720 256557055 253710336  121G Linux filesystem
/dev/sda5  457578496 485437439  27858944 13.3G Windows recovery environment
/dev/sda6  485437440 500117503  14680064    7G Intel Fast Flash
/dev/sda7  256557056 441047039 184489984   88G Linux filesystem
/dev/sda8  441047040 457578495  16531456  7.9G Linux swap

尽管它在那里,但是并未被使用。

              total        used        free      shared  buff/cache   available
Mem:           7.7G        3.9G        1.8G        1.3G        2.0G        2.2G
Swap:            0B          0B          0B

看起来它被注释掉了fstab

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda7 during installation
UUID=1c458890-63a1-4c38-befa-66148cb6f8c2 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda2 during installation
UUID=F232-FC61  /boot/efi       vfat    defaults        0       1
# swap was on /dev/sda8 during installation
#UUID=968be4fc-0850-471c-b6f8-21ecb10626dc none            swap    sw              0       0
#/dev/mapper/cryptswap1 none swap sw 0 0
/dev/disk/by-uuid/2C883E19883DE1CE /mnt/2C883E19883DE1CE auto nosuid,nodev,nofail,x-gvfs-show 0 0
/dev/disk/by-uuid/32033d20-8c17-48f4-b014-6f581099441b /media/misc auto nosuid,nodev,nofail,x-gvfs-show 0 0

但我甚至不确定这是否是正确的 uuid,因为它/dev/sda8没有出现在ls -lha /dev/disk/by-uuid/

amanda@Flatbush:~$ ls -lha /dev/disk/by-uuid/
total 0
drwxr-xr-x 2 root root 140 Mar 10 19:08 .
drwxr-xr-x 8 root root 160 Mar 10 19:08 ..
lrwxrwxrwx 1 root root  10 Mar 10 19:08 1c458890-63a1-4c38-befa-66148cb6f8c2 -> ../../sda7
lrwxrwxrwx 1 root root  10 Mar 10 19:08 32033d20-8c17-48f4-b014-6f581099441b -> ../../sda4
lrwxrwxrwx 1 root root  10 Mar 10 19:08 76B631A3B63164B1 -> ../../sda1
lrwxrwxrwx 1 root root  10 Mar 10 19:08 8E9A2F109A2EF3FD -> ../../sda5
lrwxrwxrwx 1 root root  10 Mar 10 19:08 F232-FC61 -> ../../sda2

blkid显示不同的 UUID /etc/fstab

amanda@Flatbush:~$ sudo blkid
/dev/sda1: LABEL="WINRE_DRV" UUID="76B631A3B63164B1" TYPE="ntfs" PARTUUID="8df271fe-b011-4817-99d6-a73603990fed"
/dev/sda2: LABEL="SYSTEM_DRV" UUID="F232-FC61" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="e022f5a1-9ef4-470b-b245-fc3f808e990a"
/dev/sda4: UUID="32033d20-8c17-48f4-b014-6f581099441b" TYPE="ext4" PARTLABEL="Media" PARTUUID="5561a792-93fe-41ca-b8ce-decf065bcae2"
/dev/sda5: LABEL="Lenovo_Recovery" UUID="8E9A2F109A2EF3FD" TYPE="ntfs" PARTUUID="120ea024-5d62-414f-86e7-20b4dc584b58"
/dev/sda7: UUID="1c458890-63a1-4c38-befa-66148cb6f8c2" TYPE="ext4" PARTUUID="f86d11cd-ae91-49af-b93e-944e3da180cc"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"
/dev/loop6: TYPE="squashfs"
/dev/loop7: TYPE="squashfs"
/dev/sda3: PARTLABEL="Microsoft reserved partition" PARTUUID="7a7bbfd5-6b38-4a5c-9c9e-dc9b9dd2a601"
/dev/sda6: PARTLABEL="Basic data partition" PARTUUID="9e10a03b-af15-4ee1-a14f-95c570100a40"
/dev/sda8: PARTUUID="401fbf68-8440-4f27-9337-9f11689a705b"
/dev/loop8: TYPE="squashfs"
/dev/loop9: TYPE="squashfs"
/dev/loop10: TYPE="squashfs"
/dev/loop11: TYPE="squashfs"
...

e2fsck说有一个“糟糕的神奇数字”:

amanda@Flatbush:~$ sudo e2fsck /dev/sda8
e2fsck 1.44.1 (24-Mar-2018)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/sda8

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>
 or
    e2fsck -b 32768 <device>

考虑到所有这些,正确的方法™ 在这台机器上获取交换分区。运行 18.04.2。

附言:我认为这并不重要,但当我最初制造机器时,我认为他可能会讨厌运行 Linux,所以我保留了 Windows 恢复分区。他一直都运行 Linux,直到它开始卡住。

答案1

我不能保证我做到了正确的方法™但是我……

  • 安装 gparted 和
  • 重新格式化交换分区然后
  • /etc/fstab在新行中添加了正确的 UUID
  • 启用它sudo swapon

即使重新启动后,也free -h显示总交换空间为 7.9G。所以这似乎奏效了。不幸的是,我仍然不知道它是如何阻塞的,但我想你不可能知道一切。

相关内容