使用pishrink.sh缩小img镜像文件时遇到的一种报错及解决方法
报错过程
使用pishrink.sh制作树莓派等微机的最小系统镜像的朋友们可能会遇到如下的报错,从而无法完成镜像文件的缩小,占用硬盘存储空间不说,还可能会使得镜像文件无法被烧录进空间略小于镜像文件的TF卡中。
parted: invalid token: primary
Error: Expecting a file system type.
pishrink.sh: ERROR occurred in line 378: parted failed with rc 1
我在使用pishrink.sh缩小OrangePi 4B的Ubuntu镜像时遇见了该报错,在网上找了一圈,没有发现关于该报错的已有的解决办法的帖子,于是开始尝试自行解决。
通过实践发现,出现这种报错的原因可能是制作的镜像文件的部分格式不被pishrink.sh接受。当我在Ubuntu上使用dd指令备份OrangePi 4B的Ubuntu镜像,使用pishrink.sh缩小该系统镜像便会出现上述报错;而当我使用Win32DiskImager重新备份镜像后,便可以成功使用pishrink.sh缩小新的镜像文件了。
解决方法
- 更换镜像文件的制作方法。可以和我一样在win上使用Win32DiskImager读取TF卡内容,或者使用SD Card Copier等其他TF卡备份工具。或者还可能可以通过调整dd指令的参数备份出能被pishrink.sh接受的镜像文件,感兴趣的朋友们可以尝试一下,成功的话欢迎在评论区里补充。
- 更换最小镜像制作方法,如使用gparted调整分区大小。
资料补充
pishrink.sh基本使用方法
pishrink.sh的获取及使用十分简单,可以参考下面两篇博客:
pishrink.sh其他部分常见报错及解决方法
line 296: parted failed with rc 0
Line 287
partnewsize: 11562852352
newpartend: 13550952448
Error: Can't have overlapping partitions.
pishrink.sh: ERROR occured in line 296: parted failed with rc 0
~~~~~~ 解决方法
line 64: Filesystem recoveries failed
pishrink.sh: ERROR occured in line 64: Filesystem recoveries failed. Giving up...
~~~~~~ 解决方法
line 46: bc: command not found
resize2fs 1.42.12 (29-Aug-2014)
resize2fs: Bad magic number in super-block while trying to open /dev/loop0
/mnt/pi/pishrink.sh: line 46: bc: command not found
resize2fs 1.42.12 (29-Aug-2014)
resize2fs: Bad magic number in super-block while trying to open /dev/loop0
Couldn't find valid filesystem superblock.
ERROR: resize2fs failed...
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
~~~~~~ 解决方法
- 其他更多的报错可以尝试在GitHub仓库的问题中寻找解决办法,或直接提出新问题。