User avatar
DougieLawson
Posts: 36575
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How do I use a bigger sd card for the Raspberry Pi?

Sun May 18, 2014 7:34 pm

If you start with non-NOOBS raspbian booted in the RPi there's three special files: /dev/mmcblk0 /dev/mmcblk0p1 and /dev/mmcblk0p2 which are the whole card, the FAT /boot filesystem and the ext4 root filesystem.

When you mount a blank SDCard in your USB reader that (normally) appears as /dev/sda and /dev/sda1 (full card FAT filesystem)

So we can start by copying /dev/mmcblk0 to /dev/sda
sudo dd if=/dev/mmcblk0 of=/dev/sda bs=20M # give it 20MB to play in.

You now have
/dev/sda, /dev/sda1 (FAT) and /dev/sda2 (ext4) in the first 4GB of the new card and xxxGB of unused/unassigned space.

You need to pop the card out and back in to get Linux to spot that the partition table has been updated by that sudo dd copy.

sudo fdisk /dev/sda # re-write the partition table
Note: Here's the arcane commands (my comments are in parentheses)
p (print the current partition table you need some numbers from that later)
d (delete a partition)
2 (partition #2)
n (new)
p (primary - same type as from the p command)
2 (partition #2)
122880 (use the starting value from p command for the start of the second partition)
[enter] (use the rest of the card)
w (write)

sudo e2fsck -f /dev/sda2 # runs a checkdisk process
sudo resize2fs /dev/sda2 # stretches it out to fill the second partition.

sudo shutdown -h now
pop both cards out. Pop the bigger card in the normal slot.

Job done. Time to get a beer.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: How do I use a bigger sd card for the Raspberry Pi?

Sun May 18, 2014 9:00 pm

I'm running Windows 7 64-bit.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

Return to “Beginners”