On 24/09/2023 11:00, Bob Latham wrote:
> In article <uejjqn$3j1j$
1...@dont-email.me>,
> The Natural Philosopher <t...@invalid.invalid> wrote:
>> On 21/09/2023 12:26, Bob Latham wrote:
>
>>>> You've truncated the image file, but you've not mentioned
>>>> resizing the partition sizes first. Without that step all you
>>>> will be doing is not writing some of partition to a new card,
>>>> and the last partition will still overlap the end, which things
>>>> do not like.
>>> I'm sure you're correct but once again I've reached the limits of
>>> understanding. # I read back on the whole thread and see if I can
>>> work out how resize a partition, no idea at the moment.
>>>
>
>> Yeah. That image file is now like a half empty bag of sugar with
>> the top cut off. It is not a half sized bag. The partition is in
>> a sense a container, and if you have left the part of it that
>> defines how big it is,but removed half of it, then the computer
>> will try and access parts that no longer exist.
>
> I've spent a few days looking at this trying to understand what
> you're telling me and i just don't get it. Would someone please
> explain to me where i'm going wrong both in procedure and
> understanding.
>
> One of my problems is clearly understanding terminology used.
A very common problem.
>
> Druck talks about resizing the 'partition file'. I thought this was
> the image containing two partitions used to burn onto an SD card. I
> now don't think that's the case, so what is it and where is it?
>
I think that is sloppy semantics. The thing is to resize the partiton
in the *image* file to allow the image file to be shrunk
>
> Is any of the following correct?
>
> My problem is that I end up with an SD card image with two
> partitions, the second one is usually at least half empty. I presume
> there is no point messing with the very small first partition?
>
Not really.
> I need to end the second partition earlier/shorter and change the
> last part of the image file to unallocated.
>
Or delete it entirely
> When I've done that I can chop the end of the image file off.
>
Oh I see. Yes. exactly so
]
> So the bit Druck described the other day using
> "truncate <imagefile> -s <size>"
>
> Is that the bit that chops off the newly unallocated end of the file?
>
Probably
Its a bit like a chainsaw, is truncate
> If so, (and if it isn't I'm really lost), then what I've not done is
> end the second partition earlier creating an unallocated area?
>
Probably. You need 'parted' to do that. Or an equivalent windows program.
And it all gets fairly messy
That's why I am investigating using a file based backup system rather
than imaging the entire card. Sadly its very slow
> I'm dreading asking this but is that the bit Ian described and he and
> TNP patiently talked/coached me through last week?
>
I didnt touch on parted. I am not very good with it anyway, and if the
blind lead the blind, they both shall fall into the ditch...
And parted will only work ON the Pi..or another linux system, but that
does suggest another approach,
1. START with parted to shrink the partition on the PI to a bit more
than it needs to run
2. Then dd the entire card to an image file
3. Then truncate it.
Actually within Linux I found this
"If you wish to shrink an ext2 partition, first use resize2fs to shrink
the size of filesystem. Then you may use fdisk(8) to shrink the size of
the partition. When shrinking the size of the partition, make sure you
do not make it smaller than the new size of the ext2 filesystem! "
This is probably a way to go, to start with a smaller partition before
dd-ing. THEN you can truncate reasonably safely.
But I personally don't find *any* of these methods easy, or quick.
> I build images a lot and I need whatever system I use to be
> reasonably quick to perform. Ian's procedure is very time consuming
> and if that's needed then this isn't really practical for my needs.
>
Remind me again what you are trying to achieve...is it to replicate
safely onto SD cards of varying sizes the exact same image?
If so, time taken to prepare the image is not so serious.
And my system of copying the files over, then creating a smaller
'virtual disk image' which will expand to fill the card on booting, may
serve.
How this would/will work is this:
0/.Probably start by connecting a USB drive to the pi and using that as
a big scratch area
1/. Create an empty disk image on it by copying zeroes from /dev/zero to
a disk image file.
2/. use fdisk or parted to create the small VFAT and the larger ext4
partitions
3/. mount the two partitions as loopback devices
4/. COPY the /boot file system onto the vfat partition
5/. COPY the root filesystem onto the ext4 partition
6/. Label the two file systems identically with what is in /etc/fstab
7/. Optionally add scripts to the first boot to resize the partition to
the full card size.
You will now have a disk image less than the smallest card you ever want
to use, that you can dd at will onto any new SD card.
It will take a long time to prepare this image, but once you have it,
installing it will be very fast..
> It's all been very worth it from a learning POV at the very least.
>
> Thanks.
>
> Cheers,
>
> Bob.
>
--
“It is dangerous to be right in matters on which the established
authorities are wrong.”
― Voltaire, The Age of Louis XIV