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.
-
How do you backup the card? – Milliways May 23 '16 at 06:15
-
Hit the read option in Win32DiskImager and it creates a backup image of the SDcard – user3601278 May 23 '16 at 06:26
-
2I can't say I am familiar with Win32DiskImager, but if it is like other imagers the resultant image will be the size of the device imaged - in this case the size of the SD Card. This is independent of the size of the partitions. If you search this site you will find hundreds of similar questions, although most of the "solutions" are geared to Unix/Linux. – Milliways May 23 '16 at 07:48
-
I also see this auto expansion as potentially making it harder to produce copies of a standard working setup for distribution (in the past I used 'trucate' to chop the image off just above the unexpanded size, even though 'dd' had made an image of the whole SD card including the empty part). Does jessie lite not do the expansion? – paddyg May 26 '16 at 17:47
3 Answers
Looks like this is going to be part of the newest updates; Desktop & Lite versions:
https://www.raspberrypi.org/blog/another-update-raspbian/
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.
Try this:
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
From:
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
To:
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.
- 2016-05-10-raspbian-jessie-lite.img
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: /boot/cmdline.txt
Remove the following text: init=/usr/lib/raspi-config/init_resize.sh

- 111
- 3
"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)".
Remove /etc/init.d/resize2fs_once
.

- 534
- 3
- 5
-
The init parameter still exists in Raspbian Stretch. Removing both the
init
parameter and theresize2fs_once
file are necessary. – Scott May 17 '18 at 03:34 -
2018-11-13-raspbian-stretch-lite definitly has the call to init_resize.sh in boot/cmdline.txt until you boot the first time. The script removes itself from cmdline.txt – Andy Jan 07 '19 at 15:28
-
Ubuntu Server 20.04 arm64 does not have neither
init_resize.sh
norresize2fs_once
. And it still performs the autoexpand. Any idea on how it does so? – MestreLion Nov 21 '21 at 16:24 -
Ok, got it: for cloud-init distros such as Ubuntu, the resize setting is at
/etc/cloud/cloud.cfg
in the 2nd partition (labeled "writeable"). See this answer for details – MestreLion Nov 22 '21 at 00:39
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.

- 31
- 5