我的 Raspberry Pi microSD 卡的每个备份映像似乎都已损坏。如果我创建图像文件或将 microSD 卡直接备份到其他 microSD 卡,这并没有什么区别。
我已经尝试过不同的方法。已使用的备份命令:
dd if=/dev/sde of=pi.img
cat /dev/sde > pi.img
dd if=/dev/sde2 of=pi_part2.img
dd if=/dev/sde2 of=pi_part2.img oflag=dsync bs=64k
pv /dev/sde > /dev/sdf
在原始文件系统上运行 fsck 没有显示错误:
fsck.ext4 -fnv /dev/sde2
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
169390 inodes used (17.63%, out of 960992)
686 non-contiguous files (0.4%)
153 non-contiguous directories (0.1%)
# of inodes with ind/dind/tind blocks: 0/0/0
Extent depth histogram: 159486/127
2576756 blocks used (67.10%, out of 3840256)
0 bad blocks
1 large file
141540 regular files
17848 directories
30 character device files
0 block device files
2 fifos
53 links
9898 symbolic links (9674 fast symbolic links)
63 sockets
------------
169434 files
我尝试在新的 microSD 卡上、直接在映像文件上、在使用 losetup 创建的循环设备上以及在使用 kpartx 创建的循环设备上运行 fsck。结果始终相同,并且与分区映像还是整个驱动器映像无关。
losetup -vf pi.img
or
kpartx -a pi.img
or
losetup -vf pi_part2.img
or
kpartx -a pi_part2.img
fsck.ext4 -fnv /dev/sdf2
Pass 1: Checking inodes, blocks, and sizes
Inode 651592 has an invalid extent node (blk 2661556, lblk 0)
Clear? no
Inode 651592 extent tree (at level 1) could be shorter. Optimize? no
Inode 651592, i_blocks is 200, should be 0. Fix? no
Inode 652399 has an invalid extent node (blk 2656133, lblk 0)
Clear? no
Inode 652399 extent tree (at level 1) could be shorter. Optimize? no
Inode 652399, i_blocks is 96, should be 0. Fix? no
Inode 653587 has an invalid extent node (blk 2655215, lblk 0)
Clear? no
Inode 653587 extent tree (at level 1) could be shorter. Optimize? no
Inode 653587, i_blocks is 51776, should be 0. Fix? no
Inode 781825 seems to contain garbage. Clear? no
Inode 781825 has inline data and extent flags set but i_block contains junk.
Clear inode? no
Inode 781825 has INLINE_DATA_FL flag on filesystem without inline data support.
Clear? no
...
Directories count wrong for group #99 (275, counted=0).
Fix? no
Free inodes count wrong (791602, counted=786221).
Fix? no
/dev/sdf2: ********** WARNING: Filesystem still has errors **********
169390 inodes used (17.63%, out of 960992)
592 non-contiguous files (0.3%)
140 non-contiguous directories (0.1%)
# of inodes with ind/dind/tind blocks: 0/0/0
Extent depth histogram: 134099/114
2576756 blocks used (67.10%, out of 3840256)
0 bad blocks
1 large file
118579 regular files
15409 directories
30 character device files
0 block device files
0 fifos
4294967090 links
8110 symbolic links (7886 fast symbolic links)
58 sockets
------------
142315 files
它给出了 1093872 行错误。
我已经尝试过使用替代超级块。我尝试将图像保存在 zfs 文件系统的 ext4 上。我尝试制作图像并将其放在新的 microSD 卡上。我尝试过直接复制(cat)到其他 microSD 卡,取出该卡并在适配器上滑动写锁,以确保 100% 确定之后无法更改任何内容。
结果总是一样的。
挂载原始文件系统并进行 rsync 备份可以完美地工作。
编辑: 制作映像/备份时,SD 卡上的文件系统绝对没有使用。它尚未安装,并且根据 iostat 没有写入或读取任何块。我还使用两台不同的电脑来完成这项工作。一种带有 Kali 和内置读卡器,另一种带有 Debian Buster 和外部 USB 读卡器。
编辑: 我在干净的 microSD 卡上分区并创建了等效的文件系统,然后用文件填充它。如上所述创建的备份映像没有任何错误。原来的microSD卡或者原来的ext4文件系统肯定有问题。为什么 fsck 不会显示任何错误并且安装和使用文件系统不会造成任何问题?
编辑: e2fsck 的版本相当新(Debian Buster 的最新版本):
e2fsck -V
e2fsck 1.44.5 (15-Dec-2018)
Using EXT2FS Library version 1.44.5, 15-Dec-2018
检查使用的命令主要是fsck.ext4
.有时我尝试过e2fsck
。没什么区别。
编辑:
mount | grep /dev/sde
/dev/sde2 on /mnt/oldpi type ext4 (rw,relatime,stripe=1024)
blkid /dev/sde
/dev/sde: PTUUID="21f74a8c" PTTYPE="dos"
blkid | grep /dev/sde
/dev/sde1: UUID="4B06-547E" TYPE="vfat" PARTUUID="21f74a8c-01"
/dev/sde2: UUID="e6935217-65c8-44be-bde3-79d93b146920" TYPE="ext4" PARTUUID="21f74a8c-02"
编辑: 制作两个独立的图像会产生相同的图像:
sha256sum *
da464bf4884c8f5db546637cd3e82c41ddd63d65f91f38ca1ec85af1f71c6757 pi_sdcard_20200404_1.img
da464bf4884c8f5db546637cd3e82c41ddd63d65f91f38ca1ec85af1f71c6757 pi_sdcard_20200404_2.img
在救援模式下直接在 Raspberry pi 上制作副本并在 ro 重新挂载后会产生错误更少的可用副本:
fsck.ext4 -nvf /dev/sde2
e2fsck 1.44.5 (15-Dec-2018)
Warning: skipping journal recovery because doing a read-only filesystem check.
Pass 1: Checking inodes, blocks, and sizes
Inode 653587 has an invalid extent node (blk 2655215, lblk 0)
Clear? no
Inode 653587 extent tree (at level 1) could be shorter. Optimize? no
Inode 653587, i_blocks is 51776, should be 0. Fix? no
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Block bitmap differences: -2655215 -(2895872--2896020) -(2898068--2898069) -(2902016--2902036) -(2902038--2902039) -(2902043--2902200) -(2902233--2902297) -(2902330--2902648) -(2902681--2904063) -(2906112--2906552) -(2906554--2906617) -(2906619--2907710) -(2907712--2907775) -(2907777--2907840) -(2907842--2908115) -(2908117--2908871) -(2908873--2908936) -(2908938--2909256) -(2909258--2909321) -(2909323--2909386) -(2909388--2909451) -(2909453--2909516) -(2909518--2909581) -(2909583--2909646) -(2909648--2909711) -(2909713--2909776) -(2909778--2909841) -(2909843--2909906) -(2909908--2909971) -(2909973--2910036) -(2910038--2910207) -(2912405--2912406) -(2914448--2914455) -(2916498--2916504) -(2943123--2943129) -(2945171--2945242) -(2945244--2945266) -(2945268--2945331) -(2945333--2945392) -(2945394--2945428) -(2945430--2945441) -(2945472--2945478)
Fix? no
/dev/sde2: ********** WARNING: Filesystem still has errors **********
169390 inodes used (17.63%, out of 960992)
685 non-contiguous files (0.4%)
153 non-contiguous directories (0.1%)
# of inodes with ind/dind/tind blocks: 0/0/0
Extent depth histogram: 159485/126
2575505 blocks used (67.07%, out of 3840256)
0 bad blocks
1 large file
141539 regular files
17847 directories
30 character device files
0 block device files
2 fifos
53 links
9898 symbolic links (9674 fast symbolic links)
65 sockets
------------
169434 files
使用 fsck 自动更正错误后。一切似乎都很好。
有什么办法可以调试它或检查 microSD 卡是否损坏?对我来说最重要的问题是:为什么会发生这种情况?我可以依赖这种备份方法(dd、cat、pv 等)来备份 SD 卡、闪存驱动器等吗?