Cam.Davidson.Pilon
Cam.Davidson.Pilon

Reputation: 1726

How to increase the size of /dev/root on a docker image on a Raspberry Pi

I'm using the https://github.com/lukechilds/dockerpi project to recreate a Raspberry Pi locally with Docker. However, the default disk space is very small and I quickly fill it up:

pi@raspberrypi:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.8G  1.2G  533M  69% /
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   52M  201M  21% /boot
tmpfs            25M     0   25M   0% /run/user/1000

How can I give move space to the RPi? I saw this issue, but I don't understand how that solution is implemented, or if it is relevant.

Upvotes: 6

Views: 1770

Answers (2)

mpromonet
mpromonet

Reputation: 11942

To increase the disk size, you need to extend the partition of the qemu disk used inside the container.

Start the docker to unzip rootfs and mounted it to an host path

docker run --rm -v $HOME/.dockerpi:/sdcard -it lukechilds/dockerpi

When the virtualized raspberry is up, you can stop it, running from the docker prompt sudo poweroff

Then you have the qemu disk in $HOME/.dockerpi/filesystem.img.
It could be extended with :

sudo qemu-img resize -f raw $HOME/.dockerpi/filesystem.img 10G
startsector=$(fdisk -u -l $HOME/.dockerpi/filesystem.img | grep filesystem.img2 | awk '{print $2}')
sudo parted $HOME/.dockerpi/filesystem.img --script rm 2
sudo parted $HOME/.dockerpi/filesystem.img --script "mkpart primary ext2 ${startsector}s -1s"

Restart the raspberry that will use the resized qemu disk with :

docker run --rm -v $HOME/.dockerpi:/sdcard -it lukechilds/dockerpi

Running from the docker prompt you can extend the root filesystem with :

sudo resize2fs /dev/sda2 8G

Finally the root is increased.
Following this df -h give :

Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.9G  1.2G  6.4G  16% /
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   52M  201M  21% /boot
tmpfs            25M     0   25M   0% /run/user/1000

Upvotes: 6

VonC
VonC

Reputation: 1324887

If the solution is indeed to resize /dev/root, you can follow this thread, which concludes:

Using the gparted live distro, I struggled for a little while until I realised that the /dev/root partition was within another partition.

Resizing the latter, then the former, everything works. I just gave the /dev/root partition everything remaining on the disk, the other partitions I left at their original sizes.

Upvotes: 0

Related Questions