Bad magic number in super-block

发布时间 2023-03-30 09:01:26作者: opencoder

提交svn时报一下错误:

Commit failed (details follow):
Can't flush file to disk: Input/output error

出现该错误后, 重启svn服务器, 服务器启动不了。 拆除其中一块硬盘的数据线和电源线后,重启电脑,可以进入系统。 修改配置文件,先关闭对该硬盘的开机启动自动挂载:

sudo nano /etc/fstab

打开该文件后,注释文件的最后一行

# LABEL=/ext4-2T-disk-1    /home/yourname/dir    ext4    defaults    0    2

关闭电脑,给该磁盘接上数据和电源线,启动电脑。

网络搜索方案,可以用 fsck 命令进行磁盘扫描和修复命令,命令行下执行如下:

sudo fsck -y /dev/sdb

输出结果如下:

fsck from util-linux 2.25.1
e2fsck 1.42.10 (18-May-2014)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: <device> trying backup blocks...
fsck.ext2: Bad magic number in super-block <device> /dev/sdb ?

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

根据提示执行命令:

sudo e2fsck -b 8193 /dev/sdb  ## 执行后无效果

再执行命令:

sudo e2fsck -b 32768 /dev/sdb

该命令执行时会提示按Y键修复损坏分区,一直按Y键直到命令结束。但是当我再次执行该命令时,仍然再次让我修复。转向 ChatGPT,它给出的解释是磁盘真的有坏道了,修复不了了,还是格式化重来吧!

对于磁盘上的数据ChatGPT给出了先备份分区,格式化磁盘,然后还原分区内容的方式。备份分区和还原分区的方法如下:

How to use e2image to backup a disk?

  1. Install e2image: Open a terminal window and type the following command to install e2image:
    sudo apt-get install e2image
  2. Create a backup: Now that e2image is installed, you can create a backup of a disk. For example, to create a backup of the disk /dev/sdb, run the following command:
    sudo e2image -ra /dev/sdb /path/to/backup.img
    The -ra option tells e2image to create a disk image including the partition table and all the data.
  3. Verify the backup: To verify the backup, you can run the following command:
    sudo e2image -rv /dev/sdb /path/to/backup.img
    The -rv option tells e2image to compare the backup image with the original disk and report any discrepancies.
  4. Restore the backup: To restore the backup, run the following command:
    sudo e2image -ra /path/to/backup.img /dev/sdb
    This will overwrite the contents of the disk /dev/sdb with the contents of the backup image.

ChatGPT给出的命令是用作备份和还原磁盘,备份分区也是可以的,即上面的命令修改为如下方式:

# 备份磁盘分区
sudo e2image -ra /dev/sdb1 /path/to/backup.img

# 还原磁盘分区
sudo e2image -ra /path/to/backup.img /dev/sdb1

这里值得注意的是,备份文件的大小为分区大小。例如分区大小为1000G,数据大小为200G,备份文件大小为1000G。这个需要注意,也就是在作备份时,要预留有足够的空间大小。

对于初次接触Ubuntu的人来说,这里有点让人混淆:

/dev/sdb    ## 表示某块硬盘
/dev/sdb1   ## 表示某块硬盘上的第一个分区,若有需要一块硬盘上可以有多个分区

恰好手里有一块2T的磁盘以及读盘器,将该磁盘连接机箱后置USB口,执行fdisk命令:

sudo fdisk -l

找到外接磁盘设备分区/dev/sda1,挂载上去

sudo makedir /usb
sudo mount /dev/sda1 /usb

把磁盘分区备份到/usb目录下

cd /usb
sudo e2image -ra /dev/sdb1 ./disk-backup.img
  • 格式化磁盘:
    sudo mkfs -t ext4 /dev/sdb
  • 对磁盘进行分区(该块磁盘上就分一个主分区):
    sudo fdisk /dev/sdb
  • 格式化分区:
    sudo mkfs -t ext4 /dev/sdb1
  • 还原分区
    cd /usb
    sudo e2image -ra ./disk-backup.img /dev/sdb1
  • 然后重新挂载设置,并设置启动自动挂载,到此工作就完成了!
  • 参考链接:
    https://article.itxueyuan.com/qMjLl
    https://blog.csdn.net/linzhiji/article/details/121993364