logo
background
 Home and Links
 Your PC and Security
 Server NAS
 Wargames
 Astronomy
 PhotoStory
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

Notes index links

Links to all my notes (includes mini-projects and source code etc)



(-) 0001 How do I change the Pi System partition size ?


Changing the Pi system partition

The 'standard' Pi Wheezy (v3.18) is a 0.9Gb zip download that expands to a .img of about 3.2Gb.

Jessie (v4.1) is a 1.4Gb .zip download that expands to a 3.8Gb .img. Jessie Lite (v4.1) is a 375Mb .zip that expands into a 1.4Gb .img (both boot straight into the GUI).

NOOBS 1.5 standard is a 1.0Gb zip that expands to folder of approx Gb, whilst NOOBS Lite zip (and folder) is less than 30Mb. NOOBS Standard includes the Jessie system, whilst Lite contains no system images. On first power-up you choose a system and the Pi then downloads what it needs from the web (although that's usually slower than using a PC). NOOBS 1.5 also consists of 5 partitions, so it's a right royal pain to change anything - avoid it like the plague. If you have to use it, DO NOT 'expand partition' (or you can forget about moving the drive image to another 'same sized' SD card).

For most 'stand-alone' projects, I would recommend using NOOBS Lite (30Mb) to select one of the minimal system images, although in many cases Jessie Lite is likley all you need (so download it once and 'burn' it multiple times).

When you 'burn' a .img, that sets the actual partition size, irrespective of the nominal SD card size. So, after plugging you SD card into the Pi, on first boot you will need to 'expand the drive' to make use of the free space = if you don't, you won't have enough room to load all the software you need, let alone anywhere to put your project files (images for display, camera recordings etc.).

NOOBS diffrs in that you format the SD card to exFAT (using SDFormatterv4.zip SD card formatter) on your PC, then 'drag and drop' the NOOBS folder to the SD card.

Note for the Pi Zero, you need the Jessie 4.1 (or later) or NOOBS 1.5 (or later). Neither NOOBS 1.4 nor Wheezy work on the Pi Zero. Of course the Pi Zero has no Ethernet connection, so, if you use NOOBS it must be the 'full' version (not Lite) and when presented with the 'system choice' on first boot, the only 'option' that's going to work is Raspbian Jessie (GUI). This is because Raspbian Jessie is included (as a 'zipped' package) in the NOOBS image, whilst the other 'system choice' options require the downloading of the selected system images from the Internet

On first launch, a newly copied 'Wheezy' will offer to 'use all available space' - DO NOT ALLOW IT TO DO SO - if you do, chances are you will never be able to back-up and restore to the same sized card again ! Fortunately, the Jessie (GUI) system root partition is 3.6Gb, so you already have a decent amount of free space (and are already making use of 'most' of a 4Gb SD card), so there is less need to change the partition size.

The Jessie image boots straight to the (single user) GUI and assumes you have a HDMI monitor connected (even if it can't detect one). If you want the (multi-user) CLI, you need to edit the system control settings (sudo systemctl, set-default multi-user.target)

How changing the partition size works

To change the system partition size, you actually 'delete' the existing partition(s) tables and 'recreate' them 'in RAM' before 'committing' the changes (and rebooting). Needless to say, get it wrong and you loose the whole system ...

The Jessie (and final version of Wheezy ?) distribution image has the usual 'boot' (/dev/mmcblk0p1) and extended (system) partition (/dev/mmcblk0p2) but may also include a 'swap file' partition (typically /dev/mmcblk0p5, but may be /dev/mmcblk0p3), which is used for 'virtual memory' (in much the same way as Windows). The 'swap' partition is typically contained within the 'extended' (system) partition (but ends at the same place as the end of the extended partition)

WARNING - the start of the replacement system partition tables MUST reference the same physical 'block number' as the original partition tables (his is because the actual data won't be moved). Of course the start of the 'swap partition' (which would have started after the end of the original system partition) will have to move

Launch fdisk and use the 'p' command to view the existing partition numbers and sizes :-

sudo fdisk /dev/mmcblk0 p
Note that the 'start', 'end' and 'blocks' count values are in 'sectors' of 512 bytes each (so, for example, a '4 GB' SD card = about 4,000,000,000 bytes or about 7,612,500 sectors (actually, up to 50MB or about 100,000 sectors less).

Below assumes system is '2' (mmcblk0p2).

If the swap partition ('3' ot '5') is 'contained' within the extended/system partition, just Delete partition 2 (this also removes the swap partition). If not, Delete the swap partition first and then the system.

Command (m for help): d Partition number (1,2,5, default 5): 2 Partition 2 is deleted
Recreate partition 2 as a 'primary' partition.
WARNING = the recreated partition MUST START at the exact same black number as the original
WARNING = DO NOT accept the 'default' end count .. leave about 50Mb (100,000 sectors) 'free space' per '4Gb' card size (i.e. 50Mb for 4Gb, 100Mb for 8Gb, 200Mb for a 16GB card) if you want expect to ever 'copy' the SD card using a 'cloning' process (such as dd) to the 'same sized' card

Type 'n' to create a new partition, 'e' for an Extended partition, then enter the SAME START value as the original partition (it should be the same as the default i.e. first sector of the now 'empty space'). For the 'end' value (of a 4Gb card), enter the SD card size MINUS 100,000

Command (m for help): n Partition type:   p   primary (1 primary, 0 extended, 3 free)   e   extended Select (default p): e Partition number (2-4, default 2): 2 First sector (186368-61863935, default 186368): Using default value 186368 Last sector, +sectors or +size{K,M,G} (186368-61863935, default 61863935): Using default value 61863935 Partition 2 of type Extended and of size 29.4 GiB is set
Use the "w" command to write the new partition table and then exit fdisk (q command) and reboot (sudo shutdown -r now)

Command (m for help): w Command (m for help): q sudo shutdown -r now
After rebooting, you must update the system file directory so it 'sees' the new end of partition. To do this, we use the "resize2fs" command :-

sudo resize2fs /dev/mmcblk0p2
To check the new size, you can use the "df -h" command

sudo df -h
This note last modified: 17th Sep 2016 08:09.

[top]

(+) 0100 Device tree settings

(+) 0201 Power over Ethernet - (PoE)

(+) 0202 Solar Power - (with WiFi)

(+) 0203 Power Bank pass through

(+) 0400 Accessing the SDHC card system image

(+) 0401 Accessing PC shares from the Pi

(+) 0402 Installing samba - (the Pi as a Network Share on your PC)

(+) 0900 Can this approach be scaled up to a PC UPS ?

(+) 1001 Pandora Spotify on the Pi

(+) 1002 Playing movies on the Pi

(+) 1003 Getting VGA from the HDMI socket

(+) 1004 Using the RCA socket

(+) 1005 Using the Pi RS232 serial links

(+) 1006 Using the GPIO pins

(+) 1007 Controlling the Pi Zero ACT LED

(+) 1200 List of standard camera modes

(+) 1300 Auto file names

(+) 6500 How to make the System partition read only ?

(+) 6501 Minimising SDHC corruption on power down

(+) 9000 diode switch

(+) 9001 Auto shut down

(+) 9001 MOSFET switch

(+) C201 High speed photos

(+) Dec 1969 (no desc)

(+) a000 Display setup - (for PhotoFrame)

(+) a001 go photoframe - (how it works)

(+) a002 set photo - (select for display)

(+) a003 go button script - (photoframe pause control)

(+) a005 get photos - (fetch resize)

(+) a00x Other display utilities

(+) c000 CCTV UPS requirements

(+) c001 countering low speed motion detect

(+) c002 Pi Overclocking

(+) c203 Pi ram disk - (tmpfs)

(+) c901 iR illumination

(+) c902 Viewing a video stream

(+) c905 Image anotation

(+) Dec 1969 (no desc)

(+) raspicamdocs.txt (no desc)

(+) s010 Elevation sensing

Next subject :- index

[top]