Skip to content

Commit

Permalink
Initial version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroihier committed Oct 2, 2020
0 parents commit 01f068c
Show file tree
Hide file tree
Showing 3 changed files with 477 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 mbroihier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# shrinkRPImages - Shrink Raspberry PI SD Images

This repository contains a utility useful for shrinking Raspbian images on SD cards. I am often making appliances that are relatively small and while testing I often want to be able to clone images very quickly. Once I have image that I want as a baseline or a backup, I copy the image to a mass storage device and then I use this utility to compact it into a smaller format. This is done by using resize2fs and sfdisk to resize the file system and resize the partitions. Once that resizing is done, truncate eliminates the unused portion of the file. So an image that started out as 16G can be trimmed down the 2.5 or 3G - it all depends on what you have on your SD card.

The smaller image can then be copied to another card and you can boot a PI off that "new" card. The first boot of that image will expand the second/root file system to consume the whole device.

Installation & Use

1) Clone this repository
- git clone https://github.com/mbroihier/shrinkRPImage
2) Run the utility on an image file
- cd shrinkRPIImage
- sudo ./shrinkRPImage myRPI.img

My workflow is usually something like this:
- I copy an sd card to my mass storage device
+ sudo dd bs=4M status=progress if=/dev/sdc of=myRPI.img
- I shrink the image
+ sudo ./shrinkRPImage myRPI.img
- I copy it to another card
+ sudo dd bs=4M status=progress if=myRPI.img of=/dev/sdc

Of course, myRPI.img is any file name and /dev/sdc must point to where your (unmounted) Rasbian image is.

**** Note ****
This works only with Raspbian images (starting with buster) and the images are restricted to the following requirements: a) there must only be two partions on the SD card (the first one FAT32 and the second Linux), b) you must not be using any loop devices prior to starting this utility, and c) you must have a mount point at /mnt and there must not be anything mounted to that mount point.

Loading

0 comments on commit 01f068c

Please sign in to comment.