User avatar
DeanC
Posts: 136
Joined: Thu Sep 26, 2013 4:07 pm
Location: Vancouver, Canada

Reminding to expand the filesystem

Thu Nov 14, 2013 9:32 pm

I have written a script to help remind me to expand the file system. This was to counteract any forgetfulness from using my image file reduction script: http://www.raspberrypi.org/phpBB3/viewt ... 91&t=58069

This script must be run on the filesystem just before it is made into an image. All traces of this script are removed once it's run.

Copy the following script into a file called 'expand.pl'

Code: Select all

#!/usr/bin/perl

########################################################################
# This script is used to remind users to expand the RPi's filesystem   #
# The script was written on November 14, 2013 by Dean C.               #
########################################################################

use utf8;
use 5.010;
use strict;
#use autodie;
use warnings;
#use diagnostics;
use File::Copy;

my $script = '/home/pi/expand_fs';
my $filenew = '/home/pi/.profile';
my $fileold = "${filenew}.old";
copy($filenew, $fileold);

open (DATA1, '>>', $filenew);
print DATA1 "$script\n";
close DATA1;

open (DATA2, '>', $script);
print DATA2 "#!/usr/bin/perl\n\n";

print DATA2 "use utf8\;\n";
print DATA2 "use 5.010\;\n";
print DATA2 "use strict\;\n";
print DATA2 "#use autodie\;\n";
print DATA2 "use warnings\;\n";
print DATA2 "#use diagnostics\;\n";
print DATA2 "use File::Copy\;\n\n";

print DATA2 "move('$fileold', '$filenew')\;\n";
print DATA2 "unlink \$0\;\n\n";

print DATA2 "exec ('sudo /usr/bin/raspi-config')\;";
close DATA2;
chmod 0755, $script;
unlink $0;

exit 0;
Then issue the following command:

Code: Select all

perl ./expand.pl


I have only tested this script with a RPi booting to the command line. I have not done any testing on RPi's booting to a gui.
We 'idiot proofed' the world, and now it's full of idiots!

User avatar
ilovemipi
Posts: 152
Joined: Mon Dec 02, 2013 11:52 am
Location: UK + Cyprus
Contact: Website

Re: Reminding to expand the filesystem

Tue Dec 10, 2013 3:28 pm

Bit confused by this.

Surely your other script is to reduce the size of SD card images. If we expand the filesystem BEFORE we take the image then a 32GB card will give a 32GB image even if it only has 1GB of data.

What am I missing?

Great script for reducing image size though, not tried it yet but will do asap.

User avatar
DeanC
Posts: 136
Joined: Thu Sep 26, 2013 4:07 pm
Location: Vancouver, Canada

Re: Reminding to expand the filesystem

Tue Dec 10, 2013 4:35 pm

Ok, a better explanation is required.

All this script does is make 'raspi-config' run automatically the next time you login to the command prompt. It also removes any trace of the script once completed. So you run this script on your system, then make the backup image of it and shrink it. Then the next time you login, it will remind you to expand the file system.

The reason for the script is...

Say you make a back-up image and use the shrinking script for it. This means that once you burn this image to another SD card, you will have about of 50 MB extra space.

If you don't expand the file system after burning the image to another SD card, you will quickly run out of space. And because I have been using this system for a while, I have found this script can save you a lot of troubles when you get busy and forgetful.
We 'idiot proofed' the world, and now it's full of idiots!

Return to “Beginners”