I just booted a Raspberry Pi 3 with Raspbian.

Can somebody tell me what the Expand Filesystem action actually does?

Is the filesystem already expanded by default? Is there a way to verify if the filesystem is expanded?


The base image is sized so that it will take as little as possible of the SD card space as practical. That's probably 4GB for Raspbian (full). Many people will use larger capacity cards. Unless the file system is expanded all the extra space provided by larger capacity cards will be wasted.

Use the df -h command to see the SD card utilisation before and after file system expansion.


raspi-config is POSIX shell script and fairly easy to read if you understand shell scripting; on Raspbian it's in /usr/bin, and runs via an init service the first time you boot, but is kept updated thereafter. The version I'm referring to is from a Raspbian jessie system and was last modified August 10/2016.

Can somebody tell [me] what the Expand Filesystem action actually does ?

The "Expand Filesystem" option calls a function, do_expand_rootfs(), which goes through the following steps:

  1. Checks if this is a systemd based system; Raspbian jessie and most other Pi distros are.

    • If yes, it gets a device node by parsing the output of mount.
    • If no, it gets a device node via readlink /dev/root. If this does not exist, it reports an error and fails.

    Presuming this succeeds, we now have a partition to expand.

  2. Checks whether the device node refers to an SD card partition based on whether it includes mmcblk0p.

  3. Checks that the device node is the second partition on mmcblk0. There's a comment in the source:

    the NOOBS partition layout confuses parted. For now, let's only agree to work with a sufficiently simple partition layout

    If this isn't the second partition: Error message, fail.

    Note that parted isn't used to do the expansion. It is just used in the next step to check for additional partitions.

  4. Uses parted to check if there are more partitions beyond this one, which might make it impossible to expand. If so: Error message, fail.

  5. Gets the offset of the root partition and uses this with fdisk to expand the partition.

  6. Creates an /etc/init.d script to run on the next boot; this depends on update-rc.d being available, which it is on Raspbian but may not be on other distros. The script calls resize2fs to resize the filesystem on the partition, then deletes itself.

Note in the last step the distinction between filesystem and partition. The first five steps are only about expanding the latter, but both must be done in order for this process to be useful. If the distinction is unclear to you, see here.

  • An excellent and detailed answer, but it reminded me of a book review I heard, which stated "TITLE told me more about penguins than I wished to know". And I can't agree that "raspi-config is … fairly easy to read"
    – Milliways
    Oct 4 '16 at 0:59
  • @Milliways Perhaps the book would have been interesting if you were living at Macquarie Island Station? Or maybe that's seals... Raspi-config is straight forward -- there's a few nested whiptail menus (quick glance at man whiptail will tell you everything you need to know about that) that branch using function calls. There are some globals set at the top but the logic unfolds from the bottom. I think shell scripts are ugly and esoteric because the features and conventions evolved haphazardly over a long time in a lot of different places.
    – goldilocks
    Oct 4 '16 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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