LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-06-2023, 12:52 AM   #1
cloudzerovii
LQ Newbie
 
Registered: Dec 2023
Posts: 5

Rep: Reputation: 0
Question Linux Mint (Virtual Box) How do I shrink a Batocera.img file? Please read


I have a virtual machine setup with linux mint. I have a .img file called Batocera.img and it is 994gb, it has over 100 gb of free space. I need to shrink it to 989gb as my micro sd card is 990gb. I copied the entire .img file to the desktop inside a folder.
I have used this guide below please read -->
https://softwarebakery.com/shrinking-images-on-linux

Under creating a loopback device, the 4th command is "sudo partprobe /dev/loop0"
When I run this command I get an error that says this -->
Error: Invalid argument during seek for read on /dev/loop0

What can I do to fix this? Is there a better or different way to shrink a .img file, I am open to trying anything at this point.
Thankyou to who ever would like to help me.

Last edited by cloudzerovii; 12-06-2023 at 01:33 AM.
 
Old 12-06-2023, 12:35 PM   #2
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Was the device name created in step 2 actually shown as /dev/loop0?
If not then the command in step 3 and 4 must be modified to use the actual device created.
Step 3 must use the actual loopback device name and the actual file name.
Step 4 must use the actual loopback device name.

Remember that commands shown in tutorials are examples only and must be modified to suit the users actual system.

You might reboot, then post the actual sequence of commands and results given [in a code block] as you follow the steps of that tutorial.
With that info we may have suggestions about what was done and the results.
 
Old 12-06-2023, 02:57 PM   #3
cloudzerovii
LQ Newbie
 
Registered: Dec 2023
Posts: 5

Original Poster
Rep: Reputation: 0
Yes command 1,2, and 3 all worked without issue.
Yes it was shown in step 2 as /dev/loop0. I will
restart the VM and rerun everything and postit inside
a message on here so you can see what's going on. I will post
In 6 hours as I am at work at the moment.

Here is another reference I was using. I got the same error
I followed his instructions to the exact. But get an error on
The partprobe command.
https://youtu.be/6cRkEQ3fWEU?si=bBGCzk31sIvf-Gv2

Thanks again
 
Old 12-06-2023, 04:04 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,715

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
I would try using kpartx. It might have to be installed.

kpartx -av Batocera.img

You should see a loop for each partition. If the desired partition to resize is p1 then:

sudo parted /dev/mapper/loop3p1

Make sure you have a backup image because if something goes wrong you may not be able to recover your data. Hopefully it is the last partition you are trying to resize?
 
Old 12-06-2023, 04:10 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
I see no evidence it's actually a (partitioned) disk image.
Code:
sudo file -s /dev/loop?
 
Old 12-06-2023, 11:47 PM   #6
cloudzerovii
LQ Newbie
 
Registered: Dec 2023
Posts: 5

Original Poster
Rep: Reputation: 0
Post Here is the Linux Kernal code with the error I get.

Code:
cloud@LinuxMint:~/Desktop/BGD Super Clean PC$ sudo modprobe loop
[sudo] password for cloud:     
cloud@LinuxMint:~/Desktop/BGD Super Clean PC$ sudo losetup -f
/dev/loop0
cloud@LinuxMint:~/Desktop/BGD Super Clean PC$ sudo losetup /dev/loop0 SuperCleanPC1TB.img
cloud@LinuxMint:~/Desktop/BGD Super Clean PC$ sudo partprobe /dev/loop0
Error: Invalid argument during seek for read on /dev/loop0
cloud@LinuxMint:~/Desktop/BGD Super Clean PC$
Here is what it says when i run this command sudo file -s /dev/loop0
Code:
cloud@LinuxMint:~/Desktop/BGD Super Clean PC$ sudo file -s /dev/loop0
/dev/loop0: DOS/MBR boot sector; partition 1 : ID=0xee, start-CHS (0x0,0,2), end-CHS (0x3ff,255,63), startsector 1, 1953525167 sectors
cloud@LinuxMint:~/Desktop/BGD Super Clean PC$

Last edited by cloudzerovii; 12-07-2023 at 12:06 AM.
 
Old 12-07-2023, 11:47 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,715

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Quote:
partition 1 : ID=0xee
This indicates a GPT partition table which could be causing the error. On my debian 12 system partprobe runs successfully but gparted will not allow you to resize a partition image anymore. I have not investigated if it is possible yet. You can do it by manually resizing the filesystem for the desired partition and then shrinking the partition via just plain old parted. However, a backup gpt exists at the very end of the disk which is lost when the file is truncated per the web page. You can use gdisk to rebuild the backup table but you need to allow extra space when truncating the file. See the comments at the bottom of the page for more information. Again make sure you have a back up of the image in case something happens.
 
Old 12-08-2023, 12:44 AM   #8
cloudzerovii
LQ Newbie
 
Registered: Dec 2023
Posts: 5

Original Poster
Rep: Reputation: 0
I tried this on another .img file with batocera on it. This one was for steamdeck. It worked perfectly no errors I was able to shrink it without issue. I'm new to this but I have a idea of putting the .img file onto a spare hard drive. I did this and it fit with no issues. Im going to see if I can load it up into gparted and try to shrink it. Then I will make a new img file out of the smaller image. I have 2 backups so its no issue if something happens. Just curious does anyone know how much total space is on a sandisk ultra 1tb card. The sd card I have is only a total of 990GB. I believe the sandisk ultra and/or sandisk extreme has a little more space than that. I could just get one of those and I wouldn't need to shrink it at all. If anyone has any more info or help please let me know thanks again for your time.

Last edited by cloudzerovii; 12-08-2023 at 12:51 AM.
 
Old 12-08-2023, 02:20 AM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
The marketing droids will lie through their teeth. For some entertainment search on "gigabyte versus gibibyte" for disk sizing.

No point nickel-and-dime'ing - if you need to shrink it, make it a size that'll fit anywhere without all the angst; say 950G. Much easier to enlarge it later in need on another device.
Run this on the disk you uploaded it to (or the loop).
Code:
sudo parted /dev/sd? "print,free"
 
Old 12-08-2023, 03:38 AM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,715

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Typically a labeled 1 TB disk has 931 GiB which typically linux tools use for reference. Actual usable space depends on filesystem used and its overhead.
 
Old 12-09-2023, 07:53 AM   #11
cloudzerovii
LQ Newbie
 
Registered: Dec 2023
Posts: 5

Original Poster
Rep: Reputation: 0
I know that if you load up any sd card, hard drive, or ssd into a windows program called Balena Etcher. It will show its true unformatted size. I have 1 sd card that says 990GB and another sd card that says 992GB. Try it out you will see what I'm talking about. Pretty nifty if u need to see the size of a drive.
 
Old 12-09-2023, 08:23 AM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,715

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
There are several linux utilities that report the same information as well but the reference is in GiB instead of GB. However I don't know of a way to determine that information before purchasing. No flash disk is perfect.

Last edited by michaelk; 12-09-2023 at 09:04 AM.
 
Old 12-09-2023, 10:51 AM   #13
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Marketing speak uses GB --> 1 TB == 1 x 10^12 == 1,000,000,000,000 bytes
Most linux apps use GiB (powers of 2) --> 1 TB == .9095 TiB ~= 1.65*2^39 bytes

Because of the units difference the market speak (powers of 10) makes the device seem larger than it seems when using powers of 2 for measurement although they are exactly the same actual size.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Turn Any PC Into a Retro Gaming Machine With Batocera Linux LXer Syndicated Linux News 0 09-03-2022 04:00 AM
Compile linux with Buildroot [odroidXU4 batocera gamming station + some packages] ciroreed Linux - Distributions 0 01-22-2020 11:44 AM
How to shrink .img file? NoDiskNoFun Linux - General 3 08-24-2012 03:41 PM
[SOLVED] Mounting .img file (chromiumos.img); can't mount it?? Help please? linus72 Linux - General 2 11-27-2009 08:11 PM
How do I pack stage2.img into initrd.img for a PXE linux rescue? real1elmo Red Hat 12 10-14-2009 06:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration