I'm new to RPi and and confused about why a step to "expand the file system" is frequently listed as part of the standard instructions for setting up a RPi (using a downloaded OS image).

Why is it necessary to "expand the file system" in order to have access to all the space on an SD card? Shouldn't it all be accessible by default; and why isn't it?

up vote 6 down vote accepted

People are commonly confused by the difference between three distinct things:

  1. A random access block storage device such as an SD card (or HDD).
  2. A storage partition which is a section of a device; there may only be one which occupies pretty much the whole device.
  3. A filesystem which is something used to organize the data on a partition.

The significance of #2 is that it is defined according to a particular scheme, and this information is stored somewhere on the device separate from the partition itself1. Currently there are two such schemas used predominantly, MBR and GPT. What these primarily implement is a partition table which describes the layout of the partitions on a device.

The partition table may include a clue about what kind of filesystem can be expected to be found in a partition, and thus where most people get most confused is the difference between #2 and #3. They are not synonymous. A partition may be indicated to exist in the partition table, containing a certain kind of filesystem, but this does not mean that the partition actually does contain such a filesystem. For that to be true, the partition must be formatted correctly.

Beware this formatting is distinct from the formatting of the device, which just creates the MBR or GPT style partition table. Some tools (such as fdisk) may create partitions and tag them as containing a particular kind of filesystem, but they do not create the actual filesystem -- so again, that a partition table lists a partition as being of a certain sort does not make it true!

The partition/filesystem formatting includes information about what and where things like directories and files are. Pi image files generally contain two partitions with two different kinds of filesystem:

  1. A small (usually ~50-60 MB) partition with a FAT32 filesystem. This is the "boot partition" which the hardware loads firmware from, then the firmware loads a bootloader, then the bootloader loads an operating system kernel. Or something along those lines. The Pi hardware requires this partition, and it requires the SD card use an MBR style partition table.

  2. A second, much larger partition containing an ext4 filesystem. This is not required and since it is the OS kernel that accesses it, it could be of any sort. Ext4 is the "native" filesystem used by the linux kernel, although again, it could be many other things. There is a much wider variety of filesystems than there are partitioning schemes.

Image Files

Can represent either devices or partitions. The image files used to format Raspberry Pi SD cards are usually device images, complete with MBR and multiple partitions. When these are copied block for block onto a physical medium, presto, it is as if someone formatted the device and a set of partitions containing data.

Partitions and filesystems have defined sizes that can be changed, but they still must be defined. Filesystems may contain any amount of data up to their defined size limit.

A 5 GB filesystem requires a partition >= 5GB. If it only contains 100 MB of data, this means 4.9 GB of the filesystem is free, and the partition mostly empty. However, that space must actually exist, or else things start to become complicated in a way that most users will not find entertaining.

The image files distributed for use on the Pi are minimal in size for a couple of obvious reasons:

  • So they will fit on as small a card as possible.
  • So that people do not waste bandwidth transferring, e.g., 4.9 GB of nothing.

That's why you need to expand first the partition and then the filesystem to fill whatever card you are using (the tools used to do this, such as raspi-config, do both things at once for you, see here). Recent editions of Raspbian may do this automatically.


1. It is possible to format a device "partitionless", with just one filesystem on it, which is different from a device containing one big partition, but you can't do this with the pi's SD card and it isn't worth further discussion here.

it is not nessesary to expand the file system, but gives you the maximum of available space of the SD card. Therefore it's recommended and in newer releases the resize will be done automatically ( i think i was reading something like that) Auto resize a part of NOOBs and will not be done in Raspbian.

The downloaded images are mostly smaller than a SD Card and there will be disk space unused left on the card. By expanding the space this will be available for additional package installations or for data as user data, logs, ...

The addidional space made available by resize cant be there by default, because after copying the image to the card raspbian doesn't know how much space is there or if the user wants to create another partitions with it.

  • Doesn't "addidional space made available by resize cant be there by default" contradict "in newer releases the resize will be done automatically"? – orome Jul 11 '16 at 19:11
  • 1
    no, many instructions and tutoriala will not be updated everytime when there are new features. therefore in tutorials or instructions frequently contain outdated informations. also i am not sure if the autoresize happen in Raspbian or NOOBs – Joe Platano Jul 11 '16 at 19:18
  • 1
    I was asking about your question: if (as you say) the former is the case, then how (as you say) can the latter be accomplished? I'm not saying that either statement is wrong; but there's got to be some missing piece in you answer that explains how they can both be true. – orome Jul 11 '16 at 19:22
  • i want to say that during the copy process the partition will not be resized. before the first boot the partition have the same size as the downloaded image. it doesnt contradict the autoresize on first boot. this autoresize only will be executed in noobs (raspberrypi.org/documentation/configuration/raspi-config.md) srry for the confusing part in the awnser – Joe Platano Jul 11 '16 at 19:34
  • Ah, I see (I think): the auto-resize happens on first boot. That's the missing bit of explanation, I think. – orome Jul 11 '16 at 19:50

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.