If you install a new raspberry pi it resizes the filesystem to fit the whole sdcard by default. You can avoid that behaviour and resize it yourself to a size that fits your needs. This is a short instruction on how to do that. In this example I have just used written the hassbian image to a 16GB card.
The first thing you need to do after writing the image file to your brand new sdcard is to edit the file cmdline.txt
on the card and remove the part that say:
init=/usr/lib/raspi-config/init_resize.sh
If you don’t remove it, the filesystem will be expanded to its maximum size on the first boot.
Pop your sdcard into the raspberry, start it and log in as the user pi.
homeassistant@hassbian:/home/pi $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.2G 1.2G 0 100% /
Using df -h
we can see that the filesystem size of / is 1.2GB, so let’s increase that to 4GB instead.
- Start fdisk:
sudo fdisk /dev/mmcblk0
- Print partition info:
p <enter>
- Note the start sector of partition 2 (96256 in this case).
- Delete partition 2
d <enter> 2 <enter>
- Create a new primary partition and make it 4GB, set the start sector to the same as before, 96256 and the end sector to 4GB bigger.
n <enter> p <enter> 2 <enter> 96256 <enter> +4G <enter>
- Confirm the new partition and write the changes
p <enter> w <enter>
Here is the full output from fdisk:
pi@hassbian:~ $ sudo fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.25.2).
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/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1234abcd
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 94864 86673 42.3M c W95 FAT32 (LBA)
/dev/mmcblk0p2 96256 2714519 2618264 1.3G 83 Linux
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):
First sector (2048-31116287, default 2048): 96256
Last sector, +sectors or +size{K,M,G,T,P} (96256-31116287, default 31116287): +4G
Created a new partition 2 of type 'Linux' and of size 4 GiB.
Command (m for help): p
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1234abcd
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 94864 86673 42.3M c W95 FAT32 (LBA)
/dev/mmcblk0p2 96256 8484863 8388608 4G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
Run partprobe to make the kernel know about the changes without rebooting:
pi@hassbian:~ $ sudo partprobe
Run resize2fs to expand the filesystem to use the new partition size:
sudo resize2fs /dev/mmcblk0p2
All done, we can run df -h
to see the new size:
pi@hassbian:/srv/homeassistant $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 4.0G 1.2G 2.6G 31% /