Preventing the first-boot SD card resize

Raspberry Pi OS expands the root partition to fill the SD card on first boot. There are two mechanisms, depending on image age.

Old images (pre-2022)
It’s init=/usr/lib/raspi-config/init_resize.sh in /boot/cmdline.txt that expands the partition size before /etc/init.d/resize2fs_once runs. If init=/usr/lib/raspi-config/init_resize.sh is removed, /etc/init.d/resize2fs_once still runs /usr/sbin/resize2fs which finds there’s nothing to do and immediately exits without anything being changed. /etc/init.d/resize2fs_once then removes itself and it’s end-of-story.
The full story: https://forums.raspberrypi.com/viewtopic.php?t=313003

  • which is debian-like ancient -

Current images (Bullseye and later)
cmdline.txt instead contains init=/usr/lib/raspberrypi-sys-mods/firstboot. On Bookworm and later the boot partition is mounted at /boot/firmware, so the file is /boot/firmware/cmdline.txt.
Edit /usr/lib/raspberrypi-sys-mods/firstboot and disable the resize call in main():

if check_variables; then  
	do_resize  
fi

Comment out do_resize, or replace it with echo “resize prevented”. Find it by name, not by line number - it currently sits around line 211, but that moves between releases.
(https://forums.raspberrypi.com/viewtopic.php?t=343765)

Caution: removing the whole init= parameter also skips the rest of firstboot - firstrun.sh / custom.toml customisation from Raspberry Pi Imager, SSH host key regeneration and the PARTUUID fix. Patching only do_resize keeps those.

First boot setup

After initial startup - setup:
raspi-config

Cameras

The legacy camera stack (raspistill, raspivid, the original picamera library) has been superseded by libcamera:
Bullseye: libcamera-still, libcamera-vid; the legacy stack can still be enabled in raspi-config
Bookworm and later: renamed to rpicam-still, rpicam-vid, rpicam-hello (libcamera-* names kept as symlinks); legacy stack removed entirely
Python: picamera -> picamera2
Official cameras are found via camera_auto_detect=1 in config.txt; third-party sensors need an explicit dtoverlay.

Renaming users

sudo apt install userconf-pi (preinstalled on Desktop images, needed on Lite)
sudo rename-user

The rename is carried out on the next reboot from outside the session, so it must be run by the user being renamed, and not over VNC. sudo cancel-rename aborts a pending rename.
Headless alternative: a userconf.txt file (username:hashed-password) on the boot partition.
(scripts by Simon Long of the Pi Foundation)

Slow SSH**** login on Bullseye (Pi 1)

SSH login delay on Raspberry Pi 1B (Raspbian Bullseye)
Symptom: 6–7 second delay between entering the SSH password and getting a shell prompt.
Root cause: Raspbian Bullseye defaults to yescrypt ($y$) for password hashing in /etc/pam.d/common-password. Yescrypt is intentionally CPU-intensive to resist brute-force attacks. On a Pi 1B (700MHz single-core ARMv6) this takes 6+ seconds per login.
Diagnosis: Check the hash algorithm in use on the Pi:
$sudo grep <user> /etc/shadow | cut -d: -f2 | cut -c1-4
$y$ confirms yescrypt. $6$ is sha512crypt.
Fix 1: keep yescrypt, lower its cost factor
The better option - still a memory-hard hash, but tuned to slow hardware. Add rounds= to the pam_unix line in /etc/pam.d/common-password:
password [success=1 default=ignore] pam_unix.so obscure yescrypt rounds=3
Then rehash: sudo passwd <user> - the existing hash keeps its old cost until it is rewritten.
The cost factor is logarithmic, range 1-11, default 5; each step down roughly halves the work, so rounds=3 is about a quarter of the default. Values above 11 silently fall back to 5. Time a login and pick the lowest acceptable value.
YESCRYPT_COST_FACTOR in login.defs does not help: pam_unix never reads it (linux-pam issue #607), the rounds= option is the only way.
Verified against pam_unix(8), Linux-PAM 1.4.0 (Bullseye).

Fix 2: switch PAM to sha512crypt
$sudo sed -i ’s/yescrypt/sha512/’ /etc/pam.d/common-password
Then rehash the password:
$sudo passwd <user>
Verify:
$sudo grep <user> /etc/shadow | cut -d: -f2 | cut -c1-4
Should return $6$.
Note: login.defs has a separate ENCRYPT_METHOD setting but PAM overrides it — changing only login.defs is not sufficient.
Trade-off: sha512crypt (5000 rounds by default) is considerably cheaper to brute-force than yescrypt.

Fix 3: avoid password hashing entirely
SSH public-key authentication never goes through pam_unix password hashing, so the delay disappears without touching the stored hash at all.