I am using Raspberry OS for a batch of zeros, I wanted to prepare the OS one time and then flash the prepared image for the others. After flashing the OS I installed some useful things for later, I inserted the SD in the computer, I resized to the minimum size the rootfs partition with gparted and I created an img file. To re-expand the partition I readded into /boot/cmdline.txt
the init=/usr/lib/raspi-config/init_resize.sh
, when I boot the raspberry but nothing happens, the partition is always little and the string in cmdline is removed like it should after the operation. How can I auto-expand the partition at the boot? I am using latest Raspberry OS, April '22 release. All I found is a bunch of answers really old that I don't think they fit anymore and to add that line as I described.
To create the custom image I am doing sudo dd if=/dev/sdb of=pi.img bs=1M count=4500
and then use a script I found pishrink. However the method doesn't work even if I flash the base image, I start the raspberry, I resize back the image, I add the line and plug in it again.
Since it was asked, this is the SD card before shrinking:
Disk /dev/sdb: 14,84 GiB, 15931539456 bytes, 31116288 sectors
Disk model: Transcend
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1a66848a
Device Boot Start End Sectors Size Id Type
/dev/sdb1 8192 532479 524288 256M c W95 FAT32 (LBA)
/dev/sdb2 532480 31115263 30582784 14,6G 83 Linux
dd
and for compatibility with other sd cards – Ripper346 Aug 08 '22 at 11:01sudo fdisk -l /dev/mmcblk0
will show details of the original image. You need to use appropriate device if mounted elsewhere. The tool I use use (which is not my code) is in https://raspberrypi.stackexchange.com/a/103991/8697.dd
is a poor backup strategy - see https://raspberrypi.stackexchange.com/a/5492/8697 for reasons – Milliways Aug 08 '22 at 11:24sudo /mnt/usb/image-backup --initial /mnt/usb/pi.img,,4500
. Even if it allocated 4.5gb more there are almost 2gb more than it should. However, looking at the script, the script does only a backup, if I made it from a 16gb card and I load it to a 32gb (can't try right now), the partition will be of 16gb, which doesn't answer my question. – Ripper346 Aug 08 '22 at 13:34