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

Error with Raspberry Pi Boot after compressing

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

First of all I am using Raspberry Pi 4 Model B with Raspberry Pi OS.

I've made an image of Raspbian with some functionalities, later I've cloned it using Win32DiskImager and finally I compressed this image using this script: https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh.

The last step I did was flashing the compressed .img to the SD using BalenaEtcher.

Before cloning and compressing the image I put it in read-only mode.

I have realized that the image with the read-only ON and being compressed => does NOT work.
But if read-only mode is OFF and I compress the image => IT WORKS FINE.

When introducing the SD that has the read-only mode ON, it stays in the boot screen and prints this:

raspi_boot_error

I think that compressing the image with PishRink script removes something that it don't have to remove...

Has it happened to someone or have someone suffered the same error that I have shown in the previous image? Any idea what it can be?

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

The problem was the PishRink script that was removing something that it doesn't have to remove...

I used a new script:

*** THIS SCRIPT ONLY WORKS ON RASPBIAN IMAGES. ***

To use this script, copy the code to a file called '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;

Finally go to the console and:

sudo perl ./resizeimage.pl /path_to_your_image