Warm tip: This article is reproduced from serverfault.com, please click

linux-压缩后出现Raspberry Pi Boot错误

(linux - Error with Raspberry Pi Boot after compressing)

发布于 2020-12-03 09:01:52

首先,我在Raspberry Pi OS上使用Raspberry Pi 4 ModelB。

我已经制作了具有某些功能的Raspbian映像,后来我使用Win32DiskImager克隆了它,最后我使用以下脚本压缩了该映像:https : //raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh

我所做的最后一步是使用BalenaEtcher将压缩的.img闪存到SD

在克隆和压缩图像之前,我将其置于只读模式。

我已经意识到具有只读状态ON且被压缩=>的图像不起作用
但是,如果只读模式为OFF并且我压缩了图像=> IT WORKS FINE

引入具有只读模式ON的SD时,它将停留在引导屏幕中并打印以下内容:

raspi_boot_error

我认为使用PishRink脚本压缩图像会删除一些不需要删除的内容...

它是否发生在某人身上,或者发生了与上一张图片相同的错误?知道会是什么吗?

Questioner
edu
Viewed
0
edu 2020-12-05 19:31:28

问题是PishRink脚本正在删除不需要删除的内容...

我使用了一个新脚本:

***此脚本仅适用于RASPBIAN图像。***

要使用此脚本,请将代码复制到名为“ resizeimage.pl”的文件中。

#!/usr/bin/perl

use utf8;
use 5.010;
use strict;
#use autodie;
use warnings;
#use diagnostics;

my $who = `whoami`;

if ($who !~ /root/)
{

    print "This should be run as root or with the sudo command.\n";
    exit 1;

}

if (!$ARGV[0])
{
    
    print "No image file given.\n";
    exit 1;
    
}

my $image = $ARGV[0];

if ($image !~ /^\//)
{

    print "Please enter full path to image file.\n";
    exit 1;
    
}

if (! -e $image)
{

    print "$image does not exist.\n";
    exit 1;
    
}

my @name = split (/\//, $image);
print "\n$name[(scalar @name) - 1]:\n";
print "=" x (length ($name[(scalar @name) - 1]) + 1) . "\n";

my $info = `parted -m $image unit B print | grep ext4`;

(my $num, my $start, my $old, my $dummy) = split (':', $info, 4);
chop $start;
chop $old;
printf "Old size - %d MB (%1.2f GB)\n", int ($old / 1048576), ($old / 1073741824);

my $loopback = `losetup -f --show -o $start $image`;
chop $loopback;

`e2fsck -p -f $loopback`;

if ($? != 0)
{

    print "There was an error in the file system that can't be automatically fixed... aborting.\n";
    `losetup -d $loopback`;
    exit 1;

}

$info = `resize2fs -P $loopback 2>&1`;

($dummy, my $size) = split (': ', $info, 2);
chop $size;
$size = $size + 1024;

`sudo resize2fs -p $loopback $size 2>&1`;
sleep 1;
`losetup -d $loopback`;

$size = ($size * 4096) + $start;

`parted $image rm $num`;
`parted -s $image unit B mkpart primary $start $size`;

$size = $size + 58720257;
printf "New size - %d MB (%1.2f GB)\n", int ($size / 1048576), ($size / 1073741824);

`truncate -s $size $image`;

my $diff = $old - $size;
printf "Image file was reduced by %d MB (%1.2f GB)\n", int ($diff / 1048576), ($diff / 1073741824);

exit 0;

最后转到控制台,然后:

sudo perl ./resizeimage.pl /path_to_your_image