ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5240
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Automatic Expand Filesystem after cloning a Rasbian imag

Thu Mar 16, 2017 11:42 pm

TimG wrote:For me the recipe still works with the updated official cmdline.txt patch file. It will fail if you forget the first line, which downloads the matching official cmdline.txt.
Careful, that should make your system unbootable until the cmdline.txt is fixed.

We switched to using PARTUUID in cmdline.txt and fstab instead of referring to the dev node. That will make the next image bootable from USB or SD. To do this, the cmdline.txt in pi-gen has a placeholder 'ROOTDEV' and 'BOOTDEV' which is replaced when the image is created. If you use that in your actual cmdline.txt the kernel won't know which filesystem to run init from.

User avatar
TimG
Posts: 252
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Automatic Expand Filesystem after cloning a Rasbian imag

Fri Mar 17, 2017 12:07 am

Aaah, I see. Thanks.

davethomaspilot
Posts: 75
Joined: Tue Apr 29, 2014 6:18 pm

Re: Automatic Expand Filesystem after cloning a Rasbian imag

Fri Mar 17, 2017 12:08 am

No, I did both--five (maybe more) times. It definitely doesn't work for me with the cmdline.txt that results from the patch.

My "use case" is after running a "hacked" version of rpi-clone. The "hacking" is just modifying some application files that differ based on one of four versions of the clone I create. So, it's essentially the same as rpi-clone.

reaperofshred
Posts: 1
Joined: Thu Apr 26, 2018 1:14 am

Re: Automatic Expand Filesystem after cloning a Rasbian image

Thu Apr 26, 2018 1:31 am

Hey, sorry to post on an older thread. I just wanted to offer how I do it. I have to make new images a lot, and I shrink them down pretty good, and I don't have access to them when they boot etc... I had issues with the above using Raspbian Lite, so I just made this quick script that uses raspi-config. Note that the threshold here is in kilobytes, and you can just change that to your liking. Something like this:

Code: Select all

#!/bin/bash

# Expand the filesystem if < 2 GB 
PARTSIZE=$( df | sed -n '/root/{s/  */ /gp}' | cut -d ' ' -f2 )
THRESHOLD=2097152

if (("$PARTSIZE" < "$THRESHOLD")) ; then  
        raspi-config --expand-rootfs && reboot
fi

exit 0
Just put that somewhere and call it to your /etc/rc.local. It might not be suitable in many situations, but it works for me. Hope it helps!

nex86
Posts: 9
Joined: Sat Aug 06, 2016 10:39 pm

Re: Automatic Expand Filesystem after cloning a Rasbian image

Thu Jul 26, 2018 8:52 am

why not just take the resize2fs_once out of an untouched image and copy it back?
don't forget to chmod +x resize2fs_once

sunzone
Posts: 1
Joined: Fri Aug 17, 2018 7:28 am
Location: Seoul
Contact: Twitter

Re: Automatic Expand Filesystem after cloning a Rasbian image

Fri Aug 17, 2018 7:41 am

When I checked before everything worked fine after following the steps as mentioned above

1. Add quiet init=/usr/lib/raspi-config/init_resize.sh to /boot/cmdline.txt
(add at the end of the line after a space.)
2. Copy contents from github repo to resize2fs_once
sudo wget -O /etc/init.d/resize2fs_once https://github.com/RPi-Distro/pi-gen/ra ... ze2fs_once
sudo chmod +x /etc/init.d/resize2fs_once
sudo update-rc.d resize2fs_once defaults
Reboot
---Above is previous tested steps---

But now https://github.com/RPi-Distro/pi-gen/ra ... _once link is not available
Can someone please confirm the new link for the above non-working url is


I tested with https://github.com/RPi-Distro/pi-gen/bl ... ze2fs_once link.
And it worked!

I manually created /etc/init.d/resize2fs_once with the content of the new link and gave permission with sudo chmod +x /etc/init.d/resize2fs_once and sudo systemctl enable resize2fs_once

Added quiet init=/usr/lib/raspi-config/init_resize.sh to /boot/cmdline.txt
after the next boot partition has been expanded and added lines to /boot/cmdline.txt has disappeared

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 13 guests