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?
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It only takes a minute to sign up.Sign up to join this community
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.
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:
Checks if this is a systemd based system; Raspbian jessie and most other Pi distros are.
readlink /dev/root. If this does not exist, it reports an error and fails.
Presuming this succeeds, we now have a partition to expand.
Checks whether the device node refers to an SD card partition based on whether it includes
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.
parted isn't used to do the expansion. It is just used in the next step to check for additional partitions.
parted to check if there are more partitions beyond this one, which might make it impossible to expand. If so: Error message, fail.
Gets the offset of the root partition and uses this with
fdisk to expand the partition.
/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.