Thank you. That's shrunk my 32GB card down to 5GB.DeanC wrote:I have also written another script to help in reminding to expand the filesystem.
http://www.raspberrypi.org/phpBB3/viewt ... 91&t=60918
Thank you. That's shrunk my 32GB card down to 5GB.DeanC wrote:I have also written another script to help in reminding to expand the filesystem.
http://www.raspberrypi.org/phpBB3/viewt ... 91&t=60918
Hello Dean, thank you for the script.DeanC wrote:Ok, here is a newer version. This one uses the truncate command, which eliminates the need to duplicate the image file.
To use this script, copy the code to a file called 'resizeimage.pl'. Then issue 'sudo perl ./resizeimage.pl'.
....
Please let me know if any problems arise from this script.
Sorry, but the only Mac I have ever worked on was the Macintosh 512K, so I can't say off the top of my head. But I have had no problems with this script on Linux or Windows, so I am curious if maybe it has something to do with this:tvjon wrote:I'm unfamiliar with perl, so wonder if you have any ideas please?
Well, the reason the script is so straight foreword is because I wanted beginners to be able to use it with little fuss. If all you do is input the image file's location, then very little confusion can arise. If I add options to the script (ie. file output and desired image size), it lends itself to a myriad of ridiculous questions because beginning users are using features they don't understand or need.tvjon wrote:I think it would be useful if your script had an option to write the shrunken image to a different file, preferably on a different volume.
Unfortunately, this script was written for Raspbian images. I may have forgotten to mention that.ilovemipi wrote:Maybe the script can't handle berryboot squashfs images, anyone know before I try it?
Thanks for your prompt reply.DeanC wrote:Unfortunately, this script was written for Raspbian images. I may have forgotten to mention that.ilovemipi wrote:Maybe the script can't handle berryboot squashfs images, anyone know before I try it?
If I have some free time in the future, I will look at the other file systems, and how to reduce their images.
tvjon wrote:I've tried some more images, & it looks like your script may be a handy quick "image integrity check", as one image I've tried reports:
Old size - 7646 MB (7.47 GB)
/dev/loop0: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
(i.e., without -a or -p options)
Use of uninitialized value $size in scalar chop at ./resize.pl line 71.
Use of uninitialized value $size in addition (+) at ./resize.pl line 72.
New size - 120 MB (0.12 GB)
Image file was reduced by 7526 MB (7.35 GB)
Code: Select all
#!/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;
I can't help you as my RPi's are learning devices, and therefore they refuse to run a GUI.tvjon wrote:If you get a spare moment, can you open this forum page in a browser on your RPi, NOT an external computer, please?
If this is really bothersome for you, you could look at starting another post under the troubleshooting forum. http://www.raspberrypi.org/phpBB3/viewforum.php?f=28tvjon wrote:Yes, I agree it's not a script problem, just wondered where those characters were introduced in the chain.
I didn't mention a specific browser as they all produce the same result, so pick any.
Speaking of "learning devices", that's where I imagine the extra char's to be a problem - for folk who don't have additional traditional computers, but are learning & using just a RPi alone.
Code: Select all
sudo perl resizeimage.pl '/tmp/win/8gb.img'
8gb.img:
========
Use of uninitialized value $start in scalar chop at resizeimage.pl line 53.
Use of uninitialized value $old in scalar chop at resizeimage.pl line 54.
Use of uninitialized value $old in division (/) at resizeimage.pl line 55.
Use of uninitialized value $old in division (/) at resizeimage.pl line 55.
Old size - 0 MB (0.00 GB)
Use of uninitialized value $start in concatenation (.) or string at resizeimage.pl line 57.
losetup: invalid offset '/tmp/win/8gb.img' specified
From my last post with the updated code:DeanC wrote:*** THIS SCRIPT ONLY WORKS ON RASPBIAN IMAGES. ***
From the subject line of this ENTIRE post:DeanC wrote:*** THIS SCRIPT ONLY WORKS ON RASPBIAN IMAGES. ***
So what program(s) are you using to create the .img file?mikerr wrote:By various I meant various different backups of raspbian sd cards
See post 782.DeanC wrote:So what program(s) are you using to create the .img file?mikerr wrote:By various I meant various different backups of raspbian sd cards
His post doesn't list a program.ilovemipi wrote:See post 782.DeanC wrote:So what program(s) are you using to create the .img file?mikerr wrote:By various I meant various different backups of raspbian sd cards
Sorry, I guess I'm having an off day.ilovemipi wrote:Yes it does but I can't easily see what the post number is. The 782 I referred to is his current post total. Technically it is post number 487581.
If you read what he wrote he states:
I take it this should work on images created with win32diskimager ?
I guess the most popular disk imaging software in the world today.
mikerr wrote:I don't tend to use noobs at all.
Code: Select all
cd home/pi
sudo nano resizeimage.pl
Code: Select all
sudo perl ./resizeimage.pl '/media/usb0/test.img'
Code: Select all
/media/usb0/test.img does not exist.
Code: Select all
cd /home/pi
mkdir image
sudo perl ./resizeimage.pl '/home/pi/image/test.img'
Code: Select all
/home/pi/image/test.img does not exist.
Code: Select all
pi@raspberrypi ~ $ sudo perl ./resizeimage.pl '/home/pi/image/test.img'
Useless use of a constant (losetup -d $loopback) in void context at ./resizeimage.pl line 66.
Useless use of a constant (e2fsck -p -f $loopback) in void context at ./resizeimage.pl line 60.
Useless use of a constant (sudo resize2fs -p $loopback $size 2>&1) in void context at ./resizeimage.pl line 77.
Useless use of a constant (losetup -d $loopback) in void context at ./resizeimage.pl line 79.
Useless use of a constant (parted $image rm $num) in void context at ./resizeimage.pl line 83.
Useless use of a constant (parted -s $image unit B mkpart primary $start $size) in void context at ./resizeimage.pl line 84.
Useless use of a constant (truncate -s $size $image) in void context at ./resizeimage.pl line 89.
This should be run as root or with the sudo command.