-
Notifications
You must be signed in to change notification settings - Fork 123
Resizing Filesystem
(found at https://jamesachambers.com/raspberry-pi-4-usb-boot-config-guide-for-ssd-flash-drives/)
This is a guide for resizing a filesystem and it's partition.
Note that it is for resizing primary partition #2, so adjust as necessary for other partitions, especially extended types.
By default the partition on the SSD / Flash drive will only be 1.8G. The Pi expands this automatically on micro SD drives but we will need to do it ourselves for a SSD / Flash drive. To do this we need to expand the partition and then resize the file system.
First let’s open fdisk and print the partitions:
pi@raspberrypi:~ $ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 sectors
Disk model: 2115
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x0634f60c
Device Boot Start End Sectors Size Id Type
/dev/sda1 8192 532480 524289 256M c W95 FAT32 (LBA)
/dev/sda2 540672 4292607 3751936 1.8G 83 Linux
There is the line we need. Our start value for /dev/sda2 (rootfs) is 540672. Next we need to remove and recreate the partition as a larger size. If you make any mistakes during this command just close fdisk by pressing q. The changes won’t be written to disk. If you mess up any of the commands the drive will no longer boot and you’ll have to start over again so be careful!
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (532481-500118191, default 589815): 540672 (enter the start value exactly as it was, the default will be wrong)
Last sector, +/-sectors or +/-size{K,M,G,T,P} (540672-500118191, default 500118191): (press enter to accept default which is the full disk)
Created a new partition 2 of type 'Linux' and of size 238.2 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n (don't remove signature)
If everything went well then type “w” and press enter. Otherwise press “q” to quit and try again. Once you enter “w” the changes will be permanently written to disk!
Now reboot the system. Type “df -h” to view the current disk:
pi@raspberrypi:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.8G 1.2G 450M 73% /
devtmpfs 866M 0 866M 0% /dev
tmpfs 995M 0 995M 0% /dev/shm
tmpfs 995M 8.4M 987M 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 995M 0 995M 0% /sys/fs/cgroup
/dev/sda1 253M 40M 213M 16% /boot
tmpfs 199M 0 199M 0% /run/user/1000
We can see our disk is still 1.8G even after resizing the partition. That’s because we still have one more step! We need to resize the filesystem to fill our new partition space. For this we will use “sudo resize2fs /dev/sda2”:
sudo resize2fs /dev/sda2
resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 15
The filesystem on /dev/sda2 is now 62447190 (4k) blocks long.
Now let’s check df -h again:
Filesystem Size Used Avail Use% Mounted on
/dev/root 235G 1.2G 224G 1% /
devtmpfs 866M 0 866M 0% /dev
tmpfs 995M 0 995M 0% /dev/shm
tmpfs 995M 8.4M 987M 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 995M 0 995M 0% /sys/fs/cgroup
/dev/sda1 253M 40M 213M 16% /boot
tmpfs 199M 0 199M 0% /run/user/1000
And that’s it! You will now be using all of your space on your SSD / Flash drive.