OK. If you look into usr/lib/raspberrypi-sys-mods/firstboot there's a line: TARGET_END=$((ROOT_DEV_SIZE - 1))
Change that -1 to whatever you want (e.g. ROOT_DEV_SIZE/2 for a root partition roughly half the SD card size). Remember $ROOT_DEV_SIZE is in 512 byte sectors. See: /sys/block/mmcblk0/size
Didn't find your answer? Ask the community — no account required.
R
R.Wieser
Chris,
[snip]
Teriffic ! Thats the kind of solution I was hoping for. Thanks. :-)
Regards, Rudy Wieser
D
druck
On 18/09/2023 23:46, Computer Nerd Kev wrote: > Resizing the last parition isn't difficult in a program like > GParted (which will need to run on Linux). What might be confusing > then is that your disk imager program will probably still create an > image file that's too big to fit on smaller SD cards. It's quite easy to resize the partition file, do a:-
sudo fdisk -l <imagefile>
You'll get something like
Device Boot Start End Sectors Size Id Type backup.img1 8192 532479 524288 256M c W95 FAT32 (LBA) backup.img2 532480 15597567 15065088 7.2G 83 Linux
Take the end value of the last partition add 1 and multiply by 512 to convert from sectors to bytes, then do the calculation again as this is a destructive action and can't be undone. When you are sure of the number resize the file using:-
truncate <imagefile> <size>
With dd you don't have to worry, if the source image is bigger than the destination SD card, dd will just ignore the extra data. But it's still better to make the file the right size.
---druck
B
Bob Latham
[Snip]
I read this a few times and couldn't decide for sure if it was what I wanted. I decided to have a go at it anyway.
Not got a linux machine only PIs doing little jobs.
I got an SD card and formatted it to fat32. I copied an image file to it that I had created last week and worked.
Put it in a reader and plugged the reader into a PI I use as a spare for pi-hole and my intranet.
Read my notes from Monday and a video on youtube ..
$ sudo -1 sudo: unable to resolve host intranet-pihole2: Name or service not known.
Off to a cracking start. No idea what to do about it so ignored it and pushed on.
# fdisk -l
This gave me a list but mostly ram discs but my usb was there.
From the video I typed...
# mkdir /media/usb-drive # mount /dev/sda1 /media/usb-drive/ # mount | grep sda1 (no idea, it's in the video) # cd /media/usb-drive/ # ls # sudo fdisk -l <imagefile>
Did the sums.
# truncate <imagefile> -s 3896508416
The '-s' caught me out but I got there eventually.
The PI went away for not long maybe 10 seconds and came back.
Thinking I'd done it, I wanted to get it back into a PC to take a look. I needed to dismount the usb, how ?????
# umount /media/usb-drive (best guess) target is busy.
This went on for half an hour or so. Surely it can't still be...
I started to type this post and then I had a brain wobble. Have I got to get off it first?
# cd # umount /media/usb-drive
Yes! No error.
Hope that's enough to dismount.
Moved usb back to PC. No change in file size.
Used win32diskimager and burnt an sd card. At this point I was guessing that I would now see a smaller 2nd partition and an unallocated area that I wouldn't get on these 4GB cards but would on larger cards.
I ran partition wizard.
No change there either that I could see. 2nd partition was still most of the drive and a good third was empty. No unallocated area.
I either don't understand this or I've done (not done) something wrong.
Any ideas?
Cheers,
Bob.
T
The Natural Philosopher
Thats your problem Lady.
cd / THEN umount
You cant unmount a drive you are sitting in
-- “Those who can make you believe absurdities, can make you commit atrocities.”
― Voltaire, Questions sur les Miracles à M. Claparede, Professeur de Théologie à Genève, par un Proposant: Ou Extrait de Diverses Lettres de M. de Voltaire
B
Bob Latham
Are you saying that's why it doesn't seem to have done anything even though I eventually typed # cd before umount. It then appeared to dismount to me?
Or are you just confirming my brain wobble was correct?
Bob.
A
Andy Burns
What is an rPi, other than a Linux machine?
A
Andy Burns
typing "cd" by itself, takes you back to your home directory, so then your shell didn't have the mounted usb disk open.
T
Tauno Voipio
So should all other methods to aquire superuser privileges.
There seems to be around RaspiOS setups with one user permitted in the /etc/sudoers without password.
B
Bob Latham
Yes, that was my thinking.
For me that leads to other questions..
Was it the correct thing to do?
After that did I need to umount?
I understand that being 'on' or 'in' an external drive means you cannot dismount it but was trying what stopped the process from working?
Bob.
T
The Natural Philosopher
That's right. If you are sitting on the mounted mount point, it cant get off! It will say 'busy'
Not sure which wobble that was...
T
The Natural Philosopher
A pi PICO?
-- “I know that most men, including those at ease with problems of the greatest complexity, can seldom accept even the simplest and most obvious truth if it be such as would oblige them to admit the falsity of conclusions which they have delighted in explaining to colleagues, which they have proudly taught to others, and which they have woven, thread by thread, into the fabric of their lives.”
― Leo Tolstoy
T
The Natural Philosopher
Well, being linux, you have the choice. If you want to run the whole shebang as root, you can!
A
Ahem A Rivet's Shot
With sudo it depends entirely on what is in /etc/sudoers.
This is possible sudoers supports a NOPASSWD keyword - this is mostly useful for automation and laziness.
B
Bob Latham
It could be a RISCOS machine, I've got one of those running on a PI4. No linux in site. What I meant was, I don't have a desktop linux PC only headless units.
Bob.
B
Bob Latham
Right but that's not the reason the whole thing did nothing *after* I corrected that ????
Bob.
T
The Natural Philosopher
I thought you said you unmounted it after that
R
Richard Harnden
sudo wants /your/ password, su wants /root's/ password.
You can set up sudo to not need a password. You shouldn't need to know root's password.
M
Martin Gregorie
re point 2: if you want to see what storage is mounted, run 'df' to get a list of all mounted partitions (file systems). This shows names of the file systems, they size in 1K blocks, the space used and available in each file system and the path to the fire system from '/'.
D
druck
Pi's running Linux are a Linux machine!
I think you need to ensure you select email and terminal fonts can distinguish between i, l, and 1. The command is:-
sudo -i
That's a lower case letter i.
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.
If you have a terminal current directory set to the drive being dismounted (or files open on it) this will happen. If you still cant unmount after cd and closing any applications which you think may have files open, you can do:-
umount -l /media/usb-drive
Did you alter the partition table before truncating?
---druck
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.