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?
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?
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.
mount
.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 mmcblk0p
.
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.
Uses 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.
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.
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.
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 04 '16 at 01:30