doughboy
Posts: 51
Joined: Tue Nov 01, 2016 12:04 pm

init_resize.sh suggestion

Tue Nov 01, 2016 7:13 pm

I've noticed the last few versions of raspbian resize to fill the (micro)SD instead of it being a function in raspi-config.
Script can be found in /usr/lib/raspi-config/init_resize.sh

Is it possible for the script to ask a question asking the user if they want to specify how big to make their partitions and for the user to state the size?

Reason being is that when using large (micro)SD cards, copying/making an image of them takes a long time for backup purposes, before playing with various configuration changes, and the offline shrink options I've not had any success with, either using gparted or the cli.

For now I can mount the image in a linux distro, and delete the script before manually expanding the partition to the size before its run for the first time in a rpi which works, but I am posting this as much as a suggestion and can anyone make changes to scripts in github, not something I've had to use before?
https://github.com/RPi-Distro/raspi-con ... 854cc14682

I understand some users had problems expanding their partitions, but equally some users have problems shrinking them offline.

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

Re: init_resize.sh suggestion

Tue Nov 01, 2016 7:17 pm

The script can't be interactive, it's only there to run on first boot instead of systemd. If it interferes with your use case, you can take it out of cmdline.txt.
doughboy wrote:but equally some users have problems shrinking them offline.
Everybody needs to expand the partition at some point, but only a few need to shrink it.

Might be best if you described the issues you ran into with offline shrink.

doughboy
Posts: 51
Joined: Tue Nov 01, 2016 12:04 pm

Re: init_resize.sh suggestion

Tue Nov 01, 2016 7:23 pm

you can take it out of cmdline.txt.
I'll check that out, still finding my way round.

When shrinking, the rpi would show colour pallette, start to boot with commands/info going up screen and then would freeze at a certain point. I'd have to do the process again to find out exactly what line it froze at if that info is needed.

ejolson
Posts: 4506
Joined: Tue Mar 18, 2014 11:47 am

Re: init_resize.sh suggestion

Wed Nov 02, 2016 6:38 am

ShiftPlusOne wrote:Everybody needs to expand the partition at some point, but only a few need to shrink it.
It seems a mistake to automate simple things that instead could serve as small steps in a gentle learning curve for understanding how computers work.

mmdave
Posts: 2
Joined: Thu Jan 25, 2018 2:12 pm

Re: init_resize.sh suggestion

Thu Jan 25, 2018 2:26 pm

Hi, I know this is an old thread so maybe this has been added? I would like to be able to control the size of the partition during initial install on large SD cards. A parameter in cmdline.txt would be ideal. Every time I install a fresh image I mount the SD card and manually modify /usr/lib/raspi-config/init_resize.sh so target_size is fixed and not calculated. After the first boot I'm then left with free space on the SD card that I can use to create partitions. You could also remove init_resize.sh from cmdline.txt, boot, modify the init_resize script, add it back to cmdline.txt and reboot but a cmdline.txt parameter would make this process much simpler!

mmdave
Posts: 2
Joined: Thu Jan 25, 2018 2:12 pm

Re: init_resize.sh suggestion

Thu Jan 25, 2018 3:34 pm

Just thought I'd post the reason for wanting multiple partitions in case it's of any use to anyone (and to ask if anyone has a more elegant way of doing backups). I run a few Pis 24/7 for various purposes and I've had a few SD cards fail over the years so wanted a way of getting the Pi up and running quickly (without doing a from scratch install) after a failure. A complete image of the SD card is nice and simple and very quick to get going, just swap the card to the backup and I'm up and running again but I never remember to take a copy of the SD card regularly so I needed something automated so here is what I do:

1) Create a 2nd partition (the reason for shrinking the root partition at installation time) and mount in fstab as /backup to allow it to be accessed.

2) Create a script called init_backip.sh in /usr/lib/raspi-config/ based on the init_resize.sh script:

Code: Select all

#!/bin/sh

reboot_pi () {
  umount /boot
  sync
  echo b > /proc/sysrq-trigger
  sleep 5
  exit 0
}

mount -t proc proc /proc
mount -t sysfs sys /sys

mount /boot
# Remove the backup script from cmdline.txt so it runs only once
sed -i 's| init=/usr/lib/raspi-config/init_backup.sh||' /boot/cmdline.txt
mount /boot -o remount,ro
sync

echo 1 > /proc/sys/kernel/sysrq

for COMMAND in whiptail grep cut sed dd; do
  if ! command -v $COMMAND > /dev/null; then
    echo ="$COMMAND not found"
    sleep 10
    reboot_pi
  fi
done

# Mount the backup partition
mount /dev/mmcblk0p3 /mnt 
# Make a raw copy of the root partition
dd if=/dev/mmcblk0p2 | gzip > /mnt/snapshot.dd.gz
whiptail --infobox "Root backup complete..." 20 60
sleep 5
reboot_pi

# End of script
3) Create a script in /usr/local/bin called run_reboot_root_backup.sh:

Code: Select all

#!/bin/sh

# Add some commands here to delete /backup/snapshot.dd.gz and ensure there is enough space for the new image to be created.
# I upload the snapshots to a file server then delete the file using another cron job so I always have an image on the server which I can quickly create a new SD card from.

# Add the backup command to cmdline.txt so it runs next reboot in place of the normal root
sed -i 's|rootwait|rootwait init=/usr/lib/raspi-config/init_backup.sh|' /boot/cmdline.txt

# Reboot so the backup script can run without root mounted
/sbin/shutdown -r now

4 ) Update root’s crontab to run /usr/local/bin/run_reboot_root_backup.sh once a week at a time when the Pi is idle. The Pi will reboot and run the backup script to create an image of the root partition with the root partition unmounted and then reboot back to normal operation and the backup image will be available in /backup/snapshot.dd.gz from where it can be copied to another machine over the network.

rreboto
Posts: 2
Joined: Tue Jul 07, 2015 4:10 pm

Re: init_resize.sh suggestion

Mon Dec 31, 2018 9:40 pm

mmdave wrote:
Thu Jan 25, 2018 2:26 pm
Every time I install a fresh image I mount the SD card and manually modify /usr/lib/raspi-config/init_resize.sh so target_size is fixed and not calculated. After the first boot I'm then left with free space on the SD card that I can use to create partitions.
This is a great, thank you! As you suggest, I update `/usr/lib/raspi-config/init_resize.sh` and set `TARGET_END=4194304`, which makes the root partition 2G in size. From there, I then use the remaining space for other partitions.

Thanks again!

dgerman
Posts: 12
Joined: Sat May 04, 2013 7:27 pm

Re: init_resize.sh suggestion

Sun Jan 20, 2019 12:05 am

Modifying /usr/lib/raspi-config/init_resize.sh is impossible without a running linux system

Please see https://github.com/RPi-Distro/pi-gen/issues/232

Maybe enough likes will get someone to implement my suggestion

Return to “General discussion”