Linux Mint (Virtual Box) How do I shrink a Batocera.img file? Please read
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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?
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.
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.
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).
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.