laquica
Posts: 4
Joined: Mon Oct 29, 2018 11:23 am

Resize Root partition in .img file

Mon Oct 29, 2018 11:41 am

Hi guys,
First, I am sorry, if topic's location is wrong, let me briefly explain my issue.
I want to resize pi's root partition, and I know I did this with gparted, but I want to do writing img file before SD card, so I mounted raspbian .img files to on my system, but I don't know which files I should change. Thank you for your attetion.

User avatar
B.Goode
Posts: 9558
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Resize Root partition in .img file

Mon Oct 29, 2018 8:29 pm

Welcome to the Raspberry Pi forums.


Are you aware that by default one of the first actions of a newly-installed version of the Raspbian Operating System is to resize the root partition to occupy the largest possible area of the microSD card?

At first sight, therefore, what you are proposing appears pointless. Unless you already know this and plan to take steps to inhibit this default action.

Is there some background to your query that might allow someone to give a more informed reply?

aBUGSworstnightmare
Posts: 1673
Joined: Tue Jun 30, 2015 1:35 pm

Re: Resize Root partition in .img file

Tue Oct 30, 2018 6:42 am

laquica wrote:
Mon Oct 29, 2018 11:41 am
Hi guys,
First, I am sorry, if topic's location is wrong, let me briefly explain my issue.
I want to resize pi's root partition, and I know I did this with gparted, but I want to do writing img file before SD card, so I mounted raspbian .img files to on my system, but I don't know which files I should change. Thank you for your attetion.
Take a plain uSD card, use etcher (https://www.balena.io/etcher) to write the Raspbian image file (https://www.raspberrypi.org/downloads/raspbian/) to it. Insert into your Pi, reboot and - as said already - file size will be expanded as first action. Reboots automatically and once finished you can start working with it.

laquica
Posts: 4
Joined: Mon Oct 29, 2018 11:23 am

Re: Resize Root partition in .img file

Tue Oct 30, 2018 8:45 am

B.Goode wrote:
Mon Oct 29, 2018 8:29 pm
Welcome to the Raspberry Pi forums.


Are you aware that by default one of the first actions of a newly-installed version of the Raspbian Operating System is to resize the root partition to occupy the largest possible area of the microSD card?

At first sight, therefore, what you are proposing appears pointless. Unless you already know this and plan to take steps to inhibit this default action.

Is there some background to your query that might allow someone to give a more informed reply?
Yeah, I am aware what I am doing, just maybe I misrepresented, so I just want to know, let say we have 32 GB SD card and I want to root partition have 8 GB area, then other files have different size (configs 3GB etc.) Can we set .img file like this before writing the SD card?

aBUGSworstnightmare
Posts: 1673
Joined: Tue Jun 30, 2015 1:35 pm

Re: Resize Root partition in .img file

Tue Oct 30, 2018 9:00 am

How often do you need to write this 'custom' image file?
Why not make a standard installation, then use another Liinux PC for making the required partitions/resizing.

laquica
Posts: 4
Joined: Mon Oct 29, 2018 11:23 am

Re: Resize Root partition in .img file

Tue Oct 30, 2018 9:14 am

aBUGSworstnightmare wrote:
Tue Oct 30, 2018 9:00 am
How often do you need to write this 'custom' image file?
Why not make a standard installation, then use another Liinux PC for making the required partitions/resizing.
If we could make this custom image, this provide us huge save time.
Last edited by laquica on Sat Nov 03, 2018 10:14 am, edited 1 time in total.

aBUGSworstnightmare
Posts: 1673
Joined: Tue Jun 30, 2015 1:35 pm

Re: Resize Root partition in .img file

Tue Oct 30, 2018 9:49 am

laquica wrote:
aBUGSworstnightmare wrote:
Tue Oct 30, 2018 9:00 am
How often do you need to write this 'custom' image file?
Why not make a standard installation, then use another Liinux PC for making the required partitions/resizing.
I am working for IOT company, I cant tell the details but If we could make this custom image, this provide us huge save time.
No need to disclose any details! Sounds like you need some more, hence do as described by me (standard install, resize, etc) and then take an image of your SD card.
This will be your master image from now.

Note: Keep in mind that uSD card size can differ from brand to brand, batch to batch. Means, not every 32GB card will have exactly the same size.
so better make your image a few MB smaller than the total availale space.

User avatar
procount
Posts: 2035
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Resize Root partition in .img file

Tue Oct 30, 2018 11:20 am

Without disclosing specific details, I feel you would benefit from better responses if you provided a little more information, because I'm reading a lot of assumptions into your request. Maybe considering the following questions would help clarify what you want to do, because I'm a little confused ;)

1. Is this a totally custom image, a plain Raspbian image, or a Raspbian image that you are customising for an IoT project?

2. How many partitions does your image have?

Standard Raspbian has a small FAT32 boot partition plus an ext4 rootfs that is normally expanded on first execution to fill the rest of the card. You mention writing to a 32GB card.
3. Will you always target a 32GB card, or maybe different sized SD cards?
I want to root partition have 8 GB area, then other files have different size (configs 3GB etc.)
4. You mentioned making the root partition a fixed 8GB in size. What will you be doing with the other ~24GB of SD card space? Did you mean to create other partitions (of 3GB etc) for your configs?
Can we set .img file like this before writing the SD card?
5. Yes, But there are several ways you can do this. What is your motivation?
If we could make this custom image, this provide us huge save time.
6. What is taking too long at the moment? Do you mean the expansion of the partition is taking too long?

You could create an SD card with the exact sized partitions you need and then take an image of it (with e.g. DD or win32diskimager). This image will be quite large and will take a long time to write. You could zip it to save space. You can write it back to new SD cards using Etcher (which understands zip files). As others have said, this will restrict you to writing it to an SD card of the same or larger size. Not all 32GB cards are the same size, so you would need to make it a few MB smaller to be more sure it would fit on them all.

OR, you can create an image with minimally sized partitions and use first-boot scripts to expand them to the required sizes (like Raspbian does) so it fits on a wider variety of SD card sizes.

It is not clear to me what your main concerns are that need addressing. Maybe answering these questions will help others provide better suggestions that are more suited to your needs.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

User avatar
HawaiianPi
Posts: 5240
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Resize Root partition in .img file

Tue Oct 30, 2018 1:39 pm

Changing the partitions on the default image is not easy, because that data is not in some configuration file, it's written to the partition table of the SD card when the image is written. You could possibly modify the script that does the resizing to create additional partitions, but then you'd need some way to mount them.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

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

Re: Resize Root partition in .img file

Wed Oct 31, 2018 6:42 am

To prevent the automatic re-partitioning from taking place on first boot, edit cmdline.txt to remove the "quiet init=/usr/lib/raspi-config/init_resize.sh".

Once this is done you can re-partition by hand and save the resulting disk image. Or you can alter /usr/lib/raspi-config/init_resize.sh to do what you want (look for $TARGET_END in the script). The first option is easier, but the second is more flexible.

If you also want to automate resizing of the root file-system you'll need to edit /etc/init.d/resize2fs_once. You won't find it on a running RPi because it deletes itself on first boot, but you can restore it from https://github.com/RPi-Distro/pi-gen/bl ... ze2fs_once

laquica
Posts: 4
Joined: Mon Oct 29, 2018 11:23 am

Re: Resize Root partition in .img file

Mon Nov 05, 2018 12:05 pm

TimG wrote:
Wed Oct 31, 2018 6:42 am
To prevent the automatic re-partitioning from taking place on first boot, edit cmdline.txt to remove the "quiet init=/usr/lib/raspi-config/init_resize.sh".

Once this is done you can re-partition by hand and save the resulting disk image. Or you can alter /usr/lib/raspi-config/init_resize.sh to do what you want (look for $TARGET_END in the script). The first option is easier, but the second is more flexible.

If you also want to automate resizing of the root file-system you'll need to edit /etc/init.d/resize2fs_once. You won't find it on a running RPi because it deletes itself on first boot, but you can restore it from https://github.com/RPi-Distro/pi-gen/bl ... ze2fs_once
thank you, this looks like useful, thanks.

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

Re: Resize Root partition in .img file -request-

Thu Dec 20, 2018 7:59 pm

PLEASE move the init_resize.sh script from the root partition to the boot partition and change the script line:

Code: Select all

sed -i 's| init=/usr/lib/raspi-config/init_resize.sh||' /boot/cmdline.txt
to

Code: Select all

sed --in-place=o 's| init=.*sh||' /boot/cmdline.txt  # once resized do not invoke me again. 


This will allow users running on Operating Systems without linux files system support to modify the script.

Allowing users to decide on how much space to allocate to root and even adding additional partitions like /var with other file systems.

This will NOT change existing operations.

Thank you

User avatar
scruss
Posts: 2877
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Resize Root partition in .img file

Wed Jan 02, 2019 2:49 am

It might be better to raise this as an issue: forum posts carry no weight. But the track record for issues on partition resizing isn't good: Search · org:RPi-Distro resize - all closed, no action.

Editing a shell script on a Windows machine and getting CRLFs everywhere seldom ends as expected.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Return to “General discussion”