Now when you flash the new Jessie image (released 2016-05-10) on the SD card and boot the first time, it auto expands the file system on the whole SD card. I want to stop that script. Reason i want this is because when backing-up the image from the SD card it consumes 16 GB of my disk space and i want to save that space. I am using a 16 GB SD card.
Looks like this is going to be part of the newest updates; Desktop & Lite versions:
When flashing a new Raspbian image, the file system will automatically be expanded to use all the space on the card when it is first booted.
On Ubuntu you can edit the image to stop auto file system expansion.
Here is an example using 2016-05-10-raspbian-jessie-lite.img.
fdisk -lu ./2016-05-10-raspbian-jessie-lite.img
You'll get this information:
Device Boot Start End Blocks Id System 2016-05-10-raspbian-jessie-lite.img1 8192 137215 64512 c W95 FAT32 (LBA) 2016-05-10-raspbian-jessie-lite.img2 137216 2707455 1285120 83 Linux
So for the boot section your offset is (Start*512) = 8192 * 512 = 4194304
For the Raspbian filesystem your offset is (Start*512) = 137216 * 512 = 70254592
mkdir boot sudo mount -t vfat -o loop,offset=4194304 2016-05-10-raspbian-jessie-lite.img boot
If you want to view/edit the Raspbian Filesystem. Not needed though.
mkdir test sudo mount -t ext4 -o loop,offset=70254592 2016-05-10-raspbian-jessie-lite.img test
Then you need to modify the ./boot/cmdline.txt file.
sudo gedit ./boot/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet
sudo umount ./boot
If you mounted the Raspbian filesystem:
sudo umount ./test
Now flash the new image to your SD card.
It won't automatically expand after booting up on your Pi.
Or you can flash the original image onto your SD card.
Before you plug it into your Raspberry Pi.
Edit the file:
Remove the following text:
"Remove the following text:
init=/usr/lib/raspi-config/init_resize.sh. This no longer works with the Stretch release (there is no init parameter to remove)".
This no longer works with the Stretch release (there is no init parameter to remove).
The pishrink.sh (download script from github) script accepts a -s flag that will prevent expansion at the next reboot. You need a Linux machine or a virtual machine to run the script. The script works by rewriting /etc/rc.local to either expand the filesystem (default) or leave it as is (if the -s flag is given).
On a Windows 10 laptop, you can use win32diskimager to get the image from your SD card, and I used a Lubuntu image from osboxes.org to run under VirtualBox.