docker-raspbian
docker-raspbian copied to clipboard
Increase disk size
Scenario
The pulled images only has 2G disk space which is set in qemu-img resize raspbian-lite.qcow2 +4G \
, and get easily out of space after installing some apps.
pi@raspberrypi:/dev $ df --human-readable
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.5G 1.4G 4.2M 100% /
devtmpfs 124M 0 124M 0% /dev
tmpfs 124M 0 124M 0% /dev/shm
tmpfs 124M 1.9M 122M 2% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 124M 0 124M 0% /sys/fs/cgroup
/dev/sda1 253M 53M 200M 21% /boot
tmpfs 25M 0 25M 0% /run/user/1000
Changes I made
I increased the size to 10G in qemu-img resize raspbian-lite.qcow2 +10G \
, but the newly built image has the same size as the 2G version.
raspbian. 10g 8b2e42cc8522 4 minutes ago 8.14GB
hannseman/raspbian latest afb4152be6c6 8 weeks ago 8.14GB
Is there any other changes I need to make?
+1 for this. you can't even run apt update.
You guys were on the right path but there's a few more things to do after allocating more space on the (virtual) physical disk.
As you noted, by default the allocation size for /dev/sda2
(the root fs) is small ... just 1.5G.
root@raspberrypi:~# fdisk -l | grep /dev/sda2
/dev/sda2 532480 3612671 3080192 1.5G 83 Linux
What needs to be done, is 1) resize/expand the root partition and 2) resize/expand the root file system.
Expand the root partition
- Run
parted /dev/sda
- Execute the
resizepart
on the/dev/sda
device -resizepart 2
- For the
end
of the partition, enter-1
to use all remaining unallocated space.
root@raspberrypi:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 3997MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 4194kB 273MB 268MB primary fat32 lba
2 273MB 1850MB 1577MB primary ext4
(parted) resizepart 2
End? [1850MB]? -1
(parted) p
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 3997MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 4194kB 273MB 268MB primary fat32 lba
2 273MB 3996MB 3724MB primary ext4
(parted) q
Information: You may need to update /etc/fstab.
Expand the root filesystem
Execute resize2fs /dev/sda2
and it will automatically expand to the newly expanded partition size.
root@raspberrypi:~# 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 = 1
The filesystem on /dev/sda2 is now 909068 (4k) blocks long.
Check the final available filesystem size
root@raspberrypi:~# fdisk -l | grep /dev/sda2
/dev/sda2 532480 7805023 7272544 3.5G 83 Linux
As you can see, by default the docker image allows allocating up to 3.5G which seems sufficient for many uses. You can tweak the physical size as you noted above, by changing this line in the Dockerfile
:
qemu-img resize raspbian-lite.qcow2 +2G \
to, e.g.
qemu-img resize raspbian-lite.qcow2 +4G \
to get an extra 2G allocated (for a new total of 5.5G).
Thank you so much for the detailed explanation!