如何在 Raspberry Pi 上的 docker 图像上增加 /dev/root 的大小
How to increase the size of /dev/root on a docker image on a Raspberry Pi
我正在使用 https://github.com/lukechilds/dockerpi 项目在本地用 Docker 重新创建一个 Raspberry Pi。不过默认盘space很小,我赶紧填满:
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
如何给 RPi 移动 space?我看到了 this issue,但我不明白该解决方案是如何实施的,或者它是否相关。
如果解决方案确实是调整大小/dev/root,您可以按照this thread,得出结论:
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.
要增加磁盘大小,需要扩展容器内部使用的qemu磁盘的分区。
启动docker解压rootfs并将其挂载到主机路径
docker run --rm -v $HOME/.dockerpi:/sdcard -it lukechilds/dockerpi
当虚拟树莓派启动时,您可以停止它,运行 来自 docker 提示 sudo poweroff
然后你在$HOME/.dockerpi/filesystem.img
.
中有了qemu磁盘
它可以扩展为:
sudo qemu-img resize -f raw $HOME/.dockerpi/filesystem.img 10G
startsector=$(fdisk -u -l $HOME/.dockerpi/filesystem.img | grep filesystem.img2 | awk '{print }')
sudo parted $HOME/.dockerpi/filesystem.img --script rm 2
sudo parted $HOME/.dockerpi/filesystem.img --script "mkpart primary ext2 ${startsector}s -1s"
重新启动将使用调整大小的 qemu 磁盘的树莓派:
docker run --rm -v $HOME/.dockerpi:/sdcard -it lukechilds/dockerpi
运行 在 docker 提示符下,您可以使用 :
扩展根文件系统
sudo resize2fs /dev/sda2 8G
终于加根了
按照这个 df -h
给出:
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
我正在使用 https://github.com/lukechilds/dockerpi 项目在本地用 Docker 重新创建一个 Raspberry Pi。不过默认盘space很小,我赶紧填满:
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
如何给 RPi 移动 space?我看到了 this issue,但我不明白该解决方案是如何实施的,或者它是否相关。
如果解决方案确实是调整大小/dev/root,您可以按照this thread,得出结论:
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.
要增加磁盘大小,需要扩展容器内部使用的qemu磁盘的分区。
启动docker解压rootfs并将其挂载到主机路径
docker run --rm -v $HOME/.dockerpi:/sdcard -it lukechilds/dockerpi
当虚拟树莓派启动时,您可以停止它,运行 来自 docker 提示 sudo poweroff
然后你在$HOME/.dockerpi/filesystem.img
.
中有了qemu磁盘
它可以扩展为:
sudo qemu-img resize -f raw $HOME/.dockerpi/filesystem.img 10G
startsector=$(fdisk -u -l $HOME/.dockerpi/filesystem.img | grep filesystem.img2 | awk '{print }')
sudo parted $HOME/.dockerpi/filesystem.img --script rm 2
sudo parted $HOME/.dockerpi/filesystem.img --script "mkpart primary ext2 ${startsector}s -1s"
重新启动将使用调整大小的 qemu 磁盘的树莓派:
docker run --rm -v $HOME/.dockerpi:/sdcard -it lukechilds/dockerpi
运行 在 docker 提示符下,您可以使用 :
扩展根文件系统sudo resize2fs /dev/sda2 8G
终于加根了
按照这个 df -h
给出:
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