Check free space on the SD Card?

Kernel, Main, Utilities & Applications, Miscellaneous Devices.
grizzly
Top Contributor
Posts: 381
Joined: Tue Jun 16, 2020 12:22 pm
Has thanked: 58 times
Been thanked: 77 times

Check free space on the SD Card?

Unread post by grizzly »

I was wondering how much space i have used since i have deleted some cd based games i will never play and added more then i deleted.
And sat there for a while and scratched the smoldering sawdust collector :oops: and wonder how?
I did not remember seeing any info in the mister gui or a script and took a look and nope!
And i do not want to plug the sd card into a computer just to check the space!

Some Linux command would probably do it but do not like the terminal and want something "gui like" and for this i would have to look up any linux command for checking hd space for probably the 500 time (yes goes in and goes out in 10seconds :? ).
Started to get really smokey in here by now :mrgreen:

Then i thought hmm midnight commander?
So tried that over ssh but the "gui option" in "misters MC" is disabled/hidden and you need to turn it on in MC ini file.
You can edit the ini file with this in terminal for example putty, or directly on the mister.
And yes it is named only ini no file ending.

Code: Select all

nano ~/.config/mc/ini
Or if you orefer vi
vi ~/.config/mc/ini
Then edit the ini file scroll down halfway to.

Code: Select all

[Layout]
message_visible=true
keybar_visible=true
xterm_title=true
output_lines=0
command_prompt=true
menubar_visible=true
free_space=true
And change keybar_visible and menubar_visible to true.
I can´t remember (did i say, yes goes in and goes out in 10seconds :? ) if i did change free_space to true or not but if it is set to false change that too!

Then you can start up MC=midnight commander, change left or right panel to "info" by clicking the Left or Right text on the top then choose info.
Browse to a folder.
There are as far as i know two partitions "linux" and "mister", for me it is linux=355M, mister=238G.
Mister is where all games/cores/mister ini files and so on is so in MC you have to go back one time them /media/fat and you see the mister partition.
login to ssh with.
Name root
pass 1

Then if/when you want to go back to a dual file listing again, just click the same left/right text and choose file listing instead of info.


Now this is not user friendly at all to set up for a newbie or a half moron like myself ;) , and a bit annoying to do after MC is setup.
So IS there any other way to easily check the free space on the sd card?
Preferably it should show both partitions just in case someone sometime happen to get a full linux partition.
Or why not a (i assume) simple script?
Flandango
Core Developer
Posts: 459
Joined: Wed May 26, 2021 9:35 pm
Has thanked: 59 times
Been thanked: 383 times

Re: Check free space on the SD Card?

Unread post by Flandango »

I have a simple little script that I saved in the Scripts folder that I can run from the OSD. It's nothing fancy just prints a one liner with how many free MEGS for each storage device (SD card /media/fat and any attached usb devices /media/usb*)
Also attached below. Put the file (can call it anything you want) and just make sure it's executable (from command prompt chmod +x filename)

Code: Select all

#!/bin/bash
df -hBM /media/fat | grep -v Filesystem | awk '{print "\033[32mSD Storage Space\033[0m:\t"$5" used with \033[7;36m"$4"\033[0m available"}'
for a in {0..7}
do
        USB=`mount | grep -c usb$a`
        if [ $USB -ne 0 ]; then
                df -hBM /media/usb$a | grep -v Filesystem | awk -v drive=$a '{print "\033[32mUSB"drive" Storage Space\033[0m:\t"$5" used with \033[7;36m"$4"\033[0m available"}'
        fi
done
read -p "Press any key to exit..." -n1 -s

should get something like this:

Code: Select all

SD Storage Space:       86% used with 17336M available
USB0 Storage Space:     89% used with 210808M available
Attachments
freespace.zip
(408 Bytes) Downloaded 183 times
bbond007
Top Contributor
Posts: 531
Joined: Tue May 26, 2020 5:06 am
Has thanked: 87 times
Been thanked: 211 times

Re: Check free space on the SD Card?

Unread post by bbond007 »

How about this? (put in scripts)

CheckSpace.sh

Code: Select all

#!/bin/bash
df
Flandango
Core Developer
Posts: 459
Joined: Wed May 26, 2021 9:35 pm
Has thanked: 59 times
Been thanked: 383 times

Re: Check free space on the SD Card?

Unread post by Flandango »

That should work too, except for pause, bash for some reason didn't want to include pause.
I added a little color to mine because I can't see very well and it pops it out a bit for me.
bbond007
Top Contributor
Posts: 531
Joined: Tue May 26, 2020 5:06 am
Has thanked: 87 times
Been thanked: 211 times

Re: Check free space on the SD Card?

Unread post by bbond007 »

Flandango wrote: Thu Oct 21, 2021 8:56 pm That should work too, except for pause, bash for some reason didn't want to include pause.
I added a little color to mine because I can't see very well and it pops it out a bit for me.
cool...

Yes, and thanks, I think the pause is because I been messing with DOS .BAT files lately and got a little confused - completely unnecessary and removed :)
Higgy
Posts: 92
Joined: Mon May 25, 2020 9:37 am
Has thanked: 7 times
Been thanked: 30 times

Re: Check free space on the SD Card?

Unread post by Higgy »

Guys am I missing something? The main MiSTer menu shows how much space is available on the card.
No need for scripts or Linux .
N.Master
Posts: 19
Joined: Wed Oct 13, 2021 11:47 am
Has thanked: 6 times
Been thanked: 5 times

Re: Check free space on the SD Card?

Unread post by N.Master »

+1 the main menu have an info with remaining space on SD card
Flandango
Core Developer
Posts: 459
Joined: Wed May 26, 2021 9:35 pm
Has thanked: 59 times
Been thanked: 383 times

Re: Check free space on the SD Card?

Unread post by Flandango »

Yes, the menu does show how much free space is available on the SD Card and should be enough for what the OP needed, but since I link at least one external USB drive, I use the script to report all my drives free space.
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Check free space on the SD Card?

Unread post by jca »

Higgy wrote: Fri Oct 22, 2021 7:07 am Guys am I missing something? The main MiSTer menu shows how much space is available on the card.
No need for scripts or Linux .
It is true after reboot but how do you get to this screen once you have loaded a core?
grizzly
Top Contributor
Posts: 381
Joined: Tue Jun 16, 2020 12:22 pm
Has thanked: 58 times
Been thanked: 77 times

Re: Check free space on the SD Card?

Unread post by grizzly »

I swear the free space info wasn´t there that one time i checked :shock: the mister menu! :o
But now when i look it´s there, anyone got any tips for thiiiiiiiiiiiiick glasses?

I did add the linux partition to Flandango´s script and changed the storage space to show G instead of M (changed -hBM to-H).

Code: Select all

#!/bin/bash
df -H /media/fat | grep -v Filesystem | awk '{print "\033[32mSD Storage Space\033[0m:\t"$>
for a in {0..7}
do
        USB=`mount | grep -c usb$a`
        if [ $USB -ne 0 ]; then
                df -H /media/usb$a | grep -v Filesystem | awk -v drive=$a '{print "\033[3>
        fi
done
df -hBM / | grep -v Filesystem | awk '{print "\033[32mSD Linux\033[0m:\t"$5" used with \0>
read -p "Press any key to exit..." -n1 -s
First tried too add the new linux line at the line under the sd storage line did not work, then tried between {0..7} and do but that did not work so put it last but before press any key to exit and it worked, have no idé if it is the right way or not.
Flandango
Core Developer
Posts: 459
Joined: Wed May 26, 2021 9:35 pm
Has thanked: 59 times
Been thanked: 383 times

Re: Check free space on the SD Card?

Unread post by Flandango »

What linux partition are you trying to get the size on?
The SD card doesn't have a linux partition unless you are talking about the rootfs that is mounted by the kernel during power up, which resets on each reboot.
If you did want to get the rootfs size, then use a line like this:

Code: Select all

df -hBM / | grep -v Filesystem | awk '{print "\033[32mLinux Root FS\033[0m:\t"$5" used with \033[7;36m"$4"\033[0m available"}'
Place it directly under the SD Storage Space line if you want, or at the end just like you did. The block starting with for a in.... and ending in done is just a loop to go through all 8 usb drives that may be mounted.
As for displaying values in Gigs instead of Megs, you can either use -hBG or simply -h. Upper case -H shows values in multiples of 1000 instead of 1024....kind of how drive manufacturers do to make you think you are getting alot of storage.
For instance,-h may show you 17G free, but -H may show you 19G free.
grizzly
Top Contributor
Posts: 381
Joined: Tue Jun 16, 2020 12:22 pm
Has thanked: 58 times
Been thanked: 77 times

Re: Check free space on the SD Card?

Unread post by grizzly »

Ahh!
Yes it was the rootfs i was looking at since i did think it was a separate partition on the sd card (had it in a computer 2-3 times in a year so) so no need for that since it is not a partition.

And thanks for the -hBG/-h i´m pretty suire i did try -h but it did not show in G but now when i tried it did, maybe i did not try it but thought about it???
Post Reply