更改 fstab 会使系统变为只读

更改 fstab 会使系统变为只读

我在 /etc/fstab 文件中写入更改时遇到问题,这会导致系统变为只读。

我的笔记本电脑上有两个驱动器 - SSD 和 HDD。我阅读了很多关于 SSD 优化的意见,有人说现在没有必要担心,但我在尝试优化 SSD 使用时遇到了问题。在 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/sda2 during installation
UUID=b6ebbe28-8654-4919-8094-5eee18954247 /               ext4    discard, noatime, errors=remount-ro 0 1
# /boot/efi was on /dev/sda1 during installation
UUID=A5F0-7D4E  /boot/efi       vfat    umask=0077      0       1
# /home was on /dev/sda4 during installation
UUID=1e4e6052-c8ba-4548-8ffd-457a4bc460bf /home           ext4    discard, noatime, defaults 0 2
# /var was on /dev/sdb1 during installation
UUID=d1fa1a62-eca1-4e13-8bf6-f30300a01cab /var            ext4    defaults        0       2
# swap was on /dev/sda3 during installation
UUID=69c38a83-596d-4ad1-ab87-599445c4e910 none            swap    sw              0       0

# moving temporary files from SSD to RAM
tmpfs /tmp tmpfs defaults 0 0
#tmpfs /var/tmp tmpfs defaults 0 0
#tmpfs /var/lock tmpfs defaults 0 0
#tmpfs /var/spool/postfix tmpfs defaults 0 0

UUID="ec529d46-81de-43e5-ad88-d50818f93421" /sghdd ext4 defaults 0 2

# mount MEDIA partition as sghdd folder
UUID="ec529d46-81de-43e5-ad88-d50818f93421" /sghdd ext4 defaults 0 2

# moving SSD/home folders to MEDIA
/sghdd/Downloads /home/ornichola/Downloads none bind 0 0
/sghdd/Public /home/ornichola/Public none bind 0 0
/sghdd/Videos /home/ornichola/Videos none bind 0 0
/sghdd/Pictures /home/ornichola/Pictures none bind 0 0
/sghdd/Music /home/ornichola/Music none bind 0 0

在 /dev/sda2 和 /dev/sda4 中添加任何选项(discard、noatime、relatime)后,系统重启后会出现问题。根据只读文件系统,所有使用 aptitude 的尝试都会被阻止。

为了避免这种情况,我应该从 liveCD 启动,挂载我的 / 分区并从 fstab 中删除添加的选项。之后我在 liveCD 系统中执行:

sudo mount -o remount,rw /dev/sda2 /

重新启动到安装好的系统,执行:

sudo fsck -n -f  

只有在此之后我才能再次使用 aptitude。

修改 fstab 的主要目的是给 SSD 分区添加 discard、relatime、nodiratime(或 noatime)选项。为什么系统会变成只读?

输出

ornichola@silver:~$ sudo blkid
/dev/sda1: LABEL="EFIBOOT" UUID="A5F0-7D4E" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="9a3525d1-9e84-4a06-84d2-2b96818ac1b8"
/dev/sda2: UUID="b6ebbe28-8654-4919-8094-5eee18954247" TYPE="ext4" PARTUUID="a5cd0868-f118-40a5-9ffd-09282504722d"
/dev/sda3: UUID="69c38a83-596d-4ad1-ab87-599445c4e910" TYPE="swap" PARTUUID="9199a9cb-9656-489f-83ef-4fe2800e6706"
/dev/sda4: UUID="1e4e6052-c8ba-4548-8ffd-457a4bc460bf" TYPE="ext4" PARTUUID="4bf6d060-a7bf-491d-ae53-da80b13c838d"
/dev/sdb1: UUID="d1fa1a62-eca1-4e13-8bf6-f30300a01cab" TYPE="ext4" PARTUUID="6c06b7b5-67dd-4b39-9f63-58c3876b9cfb"
/dev/sdb2: LABEL="MEDIA" UUID="ec529d46-81de-43e5-ad88-d50818f93421" TYPE="ext4" PARTUUID="869b4d14-7a3b-4eb3-b784-e6fbe3db5514"
ornichola@silver:~$ 

并输出文件系统检查当系统为只读且选项添加到 fstab 时:

ornichola@silver:~$ sudo fsck -n -f
fsck from util-linux 2.27.1
fsck: /etc/fstab: parse error at line 9 -- ignore
fsck: /etc/fstab: parse error at line 13 -- ignore
fsck.fat 3.0.28 (2015-05-16)
0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
 Automatically removing dirty bit.
Leaving filesystem unchanged.
/dev/sda1: 9 files, 870/130812 clusters
e2fsck 1.42.13 (17-May-2015)
Warning!  /dev/sdb1 is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
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
Free blocks count wrong (4853291, counted=4853223).
Fix? no

Free inodes count wrong (1301362, counted=1301355).
Fix? no

/dev/sdb1: 9358/1310720 files (0.4% non-contiguous), 389589/5242880 blocks
e2fsck 1.42.13 (17-May-2015)
Warning!  /dev/sdb2 is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
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
MEDIA: 16/59744256 files (0.0% non-contiguous), 3800856/238947328 blocks
e2fsck 1.42.13 (17-May-2015)
Warning!  /dev/sdb2 is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
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
MEDIA: 16/59744256 files (0.0% non-contiguous), 3800856/238947328 blocks
ornichola@silver:~$ 

答案1

编辑您的/etc/fstab

terminal...

gksudo gedit /etc/fstab

改变这个:

# / was on /dev/sda2 during installation
UUID=b6ebbe28-8654-4919-8094-5eee18954247 /               ext4    discard, noatime, errors=remount-ro 0 1
# /home was on /dev/sda4 during installation
UUID=1e4e6052-c8ba-4548-8ffd-457a4bc460bf /home           ext4    discard, noatime, defaults 0 2

对此:

# / was on /dev/sda2 during installation
UUID=b6ebbe28-8654-4919-8094-5eee18954247 /               ext4    discard,noatime,errors=remount-ro 0 1
# /home was on /dev/sda4 during installation
UUID=1e4e6052-c8ba-4548-8ffd-457a4bc460bf /home           ext4    discard,noatime,defaults 0 2

并且,正确fsck您的系统并修复错误...

要检查 Ubuntu 分区上的文件系统...

  • 启动到 GRUB 菜单
  • 选择高级选项
  • 选择恢复模式
  • 选择 Root 访问
  • 在 # 提示符下,键入sudo fsck -f /# check /
  • 在 # 提示符下,输入sudo fsck -f /dev/sda4# check /home
  • 在 # 提示符下,键入sudo fsck -f /dev/sdb1# check /var
  • 如果有错误,请重复 fsck 命令
  • 类型reboot

相关内容