Bootstrap

解决在linux执行删除时报错:Read-only file system

Read-only file system

rm: cannot remove ‘/mnt/sda1/logs/user/2022-12/warn-2022-12-28-1.log’: Read-only file system
rm: cannot remove ‘/mnt/sda1/logs/user/2022-12/warn-2022-12-20-1.log’: Read-only file system
rm: cannot remove ‘/mnt/sda1/logs/user/2022-12/error-2022-12-15-1.log’: Read-only file system

遇到 Read-only file system 错误,说明文件系统处于只读模式,无法对其进行写入或删除操作。这通常是由于以下几种情况引起的:

  1. 文件系统遭遇错误:如果文件系统出现错误,Linux 会将其挂载为只读模式,以避免进一步损坏数据。
  2. 文件系统挂载时指定了只读模式:在挂载时,如果加上了 ro 选项,文件系统会被设置为只读。

解决方法:

修复文件系统: 如果文件系统因错误而被挂载为只读,尝试使用 fsck 命令进行修复。首先,确保目标文件系统没有被挂载:

sudo umount /mnt/sda1

然后运行 fsck 修复文件系统:

sudo fsck /dev/sda1

修复完成后,重新挂载文件系统:

sudo mount /mnt/sda1

操作

[root@appnode-237 ~]# sudo umount /mnt/sda1
[root@appnode-237 ~]# sudo fsck /dev/sda1
fsck from util-linux 2.23.2
e2fsck 1.42.9 (28-Dec-2013)
/dev/sda1: recovering journal
/dev/sda1 contains a file system with errors, check forced.
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
Block bitmap differences:  -215564219 -215580075 -(215580346--215580363) -215580418 -215754658 -215760450 -(219252736--219253253) -(219253256--219254783) -(219265024--219267882) -(219267885--219268199) -(219268202--219268476) -(219268479--219268603) -(219268606--219268999) -(219269001--219269119) -(219271168--219271511) -(219271514--219271603) -219271605 -(219271608--219271692) -(219271695--219271866) -(219271869--219272117) -(219272120--219272205) -(219272208--219272378) -(219272381--219272464) -(219272467--219272548) -(219272551--219272635) -(219272642--219272722) -(219272729--219272819) -(219272824--219272986) -(219272991--219273071) -(219273074--219273215) -(219276527--219276528) -(219277312--219277343) -(219277346--219277436) -(219277445--219277532) -(219277539--219277625) -(219277632--219277718) -(219277723--219277811) -(219277820--219277900) -(219277909--219277988) -(219277993--219278072) -(219278075--219278153) -(219278156--219278236) -(219278239--219278322) -(219278339--219278416) -(219278427--219278507) -(219278512--219278598) -(219278607--219278763) -(219278770--219278852) -(219278857--219278937) -(219278948--219279027) -(219279032--219279114) -(219279123--219279210) -(219279219--219279303) -(219279314--219279401) -(219279408--219279488) -(219279493--219279572) -(219279587--219279676) -(219279689--219279771) -(219279776--219279864) -(219279869--219279955) -(219279958--219280039) -(219280044--219280126) -(219280129--219280211) -(219280222--219280305) -(219280314--219280399) -(219280408--219280491) -(219280500--219280578) -(219280581--219280659) -(219280674--219280757) -(219280766--219280848) -(219280861--219281026) -(219281035--219281207) -(219281210--219281291) -(219281344--219281384)
Fix<y>? yes
Free blocks count wrong for group #6578 (311, counted=332).
Fix<y>? yes
Free blocks count wrong for group #6691 (1, counted=11897).
Fix<y>? yes
Free blocks count wrong (120871174, counted=120883391).
Fix<y>? yes
yInode bitmap differences:  -53871779 -53871986 -53876437 -53877735 -(53877747--53877774) -(53877776--53877801) -(53877803--53877805) -53878322 -53878329 -(53878785--53878788) -(53878795--53878819) -53878889 -53878897 -(54803334--54803335)
Fix<y>? yes
Free inodes count wrong for group #6576 (496, counted=561).
Fix<y>? yes
Free inodes count wrong for group #6577 (8153, counted=8186).
Fix<y>? yes
Free inodes count wrong (57510425, counted=57519167).
Fix<y>? yes

/dev/sda1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda1: 3535809/61054976 files (0.5% non-contiguous), 123306999/244190390 blocks
[root@appnode-237 ~]# sudo mount /mnt/sda1
[root@appnode-237 ~]# rm -rf /mnt/sda1/logs/api-gateway/
[root@appnode-237 ~]# 

;