If you got your Raspberry PI from RS like I did I also ordered both a power supply & an SD card. Now you’ll probably find that you got a 4GB card. The problem is that the Debian image that you can download for the pi only uses 2GB of it, so you will find that you’ll run out of space pretty quickly. This article shows how you can allocate the remainder of the card so it’s available for use.
You do this at your own risk. Make sure you have backed up everything you need before doing this.
Now there is a good video tutorial on YouTube by RaspberryPiTutorials which shows one method of resizing the image.
[youtube]http://www.youtube.com/watch?v=DztSRaFyaVE[/youtube]
Now this is fine although it does go through hoops using a VM etc but what about from the pi itself?
Well here I’m not going to resize the root partition. What I’m going to do is to create a new partition using up the remainder of the space and move /home to that new partition.
The benefit of this is that you are freeing up the root partition for just the OS and the remainder of the card for user files.
Creating the new partition
First log into the pi:
alios@mylinux:~$ ssh -Y pi@raspberrypi |
Remember from a previous article, the -Y allows the pi to use your local X11 display.
Next we need to run gparted:
pi@raspberrypi:~$ gksudo gparted |
You should now see a display with the partitions displayed and a large unallocated section to the right in grey. Select that unallocated space right click and select new.
In that dialog you’ll see aot of boxes. The main two you want are the first one (top left) which says space before the partition, it will show 0 but you need to change it to 1. This follows the layout of the other partitions which have a 1Mb buffer between each partition.
The other one is the file system dropdown. I chose ext4 as thats the same as the root.
Apply these and you should then see the partition is now marked as allocated.
Click on apply. This now applies your changes.
Next right click the new partition, select format to and choose ext4.
Now make a cup of coffee – as it will run for a few minutes as it formats the new drive.
Once it’s done you can close gparted.
Moving home to the new partition
Now at the command line you need to mount the new partition so you can copy your home directories.
pi@raspberrypi:~$ sudo vi /etc/fstab |
And add the following to the end of the file:
/dev/mmcblk0p4 /mnt ext4 defaults 0 0 |
Save that and exit vi then mount the drive. You should then see the new drive present.
pi@raspberrypi:~$ sudo mount -a |
pi@raspberrypi:~$ df -k |
Filesystem 1K-blocks Used Available Use% Mounted on |
tmpfs 95416 0 95416 0% /lib/init/rw |
udev 10240 148 10092 2% /dev |
tmpfs 95416 0 95416 0% /dev/shm |
rootfs 1602528 1311868 209252 87% / |
/dev/mmcblk0p1 76186 28549 47637 38% /boot |
/dev/mmcblk0p4 1994640 35744 1857572 2% /mnt |
Now we need to copy the home directories across:
pi@raspberrypi:~$ sudo su - |
X11 connection rejected because of wrong authentication. |
root@raspberrypi:~# mv /home/pi /mnt |
root@raspberrypi:~# ls -l /mnt |
total 4 |
drwxr-xr-x 12 pi pi 4096 Jun 19 11:57 pi |
Next whilst we are still in the root shell we’ll unmount /mnt and move it back to /home:
root@raspberrypi:~# umount /mnt |
root@raspberrypi:~# vi /etc/fstab |
Now change the entry for /mnt to /home and save it. Next we’ll mount it again this time as /home
root@raspberrypi:~# mount -a |
root@raspberrypi:~# df -k |
Filesystem 1K-blocks Used Available Use% Mounted on |
tmpfs 95416 0 95416 0% /lib/init/rw |
udev 10240 148 10092 2% /dev |
tmpfs 95416 0 95416 0% /dev/shm |
rootfs 1602528 1305236 215884 86% / |
/dev/mmcblk0p1 76186 28549 47637 38% /boot |
/dev/mmcblk0p4 1994640 42380 1850936 3% /home |
There it’s done, now /home is a 1.8Gb partition whilst root holds the base OS.
Now reboot the pi & log in again. You should now see all your files present but it’s now in the new larger partition.