rashid
is used to shrink Raspbian images. This is useful if you've used dd or similar utility to create a bit-wise copy of a Raspberry Pi SD card. The image so created is the same size as the card capacity, but the working software occupies only a small fraction of that space. This utility shrinks the image reducing the size, thereby reducing storage requirements and transfer times.
All the heavy lifting is provided by the excellent raspbian-shrink
tool written by Andrew Oakley at cotswoldjam. I recommend you have a look at the instructions in their repository.
The script rashid
- RAspbian SHrink In Docker - should run stand-alone alongside a copy of raspbian-shrink
, but it is designed as the entry point for a Docker container. I created this because I wanted to use raspbian-shrink
on my MacBook, but couldn't because macOS doesn't have native support for ext4 (the filesystem used in Raspbian). Also because everything should run in containers.
The following dependencies are required:
- Working installation of Docker >v17.05 (we use multi-stage builds);
- Raspbian image (for example a dd copy of an SD-card), this does not work with Noobs;
- Tested working with
commit 2909def47f675aea43ed8d915cab683e15c7fdf9
of cotswoldjam.
You have two options available to use rashid
: using a pre-built image, or building your own image.
I provide pre-built multi-architecture images for Intel and ARM (for Raspberry Pi), which can be downloaded by Docker like this:
# For linux/amd64, linux/arm64, linux/arm:
docker pull r.j2o.it/rashid
And then jump right to the "Shrinking an image" section below, wherein you replace <tag>
with r.j2o.it
.
Building your own image from this repository is simple:
- Clone this repository:
git clone https://github.com/jjo93sa/rashid.git
- Build the Docker image like this, from within the directory containing the Dockerfile:
cd rashid
docker build --no-cache --shrink -t <tag>/rashid .
Replacing <tag>
with the name of your Docker repository. The Cotswoldjam repository is pulled in during the first build stage.
Shrinking a disk image is achieved by running a rashid
container, thus:
- Assuming the disk image you want to shrink is contained in the current working directory, and called
source.img
, run the container (scrolling required):
# Replace <tag> with the tag you used to build this image in the previous step.
# For example if you downloaded the pre-built ARM image, <tag> would be r.j2o.it/arm32v6
docker run --rm -it -v `pwd`:/work-dir --device=/dev:/dev/ --cap-add=SYS_ADMIN --name rashid <tag>/rashid [-e] [-d] [-f] [-m MB] [-y] source.img shrunk.img
- Consider setting the
docker run
command as function in your.bashrc
, or elsewhere, for easier future use:
# Replace <tag> with the value you used above
DOCKER_REPO_PREFIX=<tag>
rashid()
{
docker run --rm \
-it \
-v `pwd`:/work-dir \
--device=/dev/:/dev/ \
--cap-add=SYS_ADMIN \
--name rashid \
${DOCKER_REPO_PREFIX}/rashid "$@"
}
- After (2) reload your
.bashrc
to load the function into your environment:
source .bashrc
Ping me if you have any questions, suggestions or requests for new features.
Distributed under the MIT License, see LICENSE file in the repository root for more information.