LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-03-2017, 06:35 AM   #1
sparc86
Member
 
Registered: Jul 2006
Location: Joinville, Brazil
Distribution: Debian, CentOS
Posts: 301

Rep: Reputation: 31
Question Is it possible to find out the USED disk space for an UNMOUNTED file system/disk?


Hi,
I couldn't find an answer for that on Google, but does anybody knows if it's even possible to find the actual USED disk space for a certain file system/Disk WITHOUT having it mounted?

It's easy to find out the TOTAL disk capacity using fdisk, but the USED the disk space?

Thanks.
 
Old 04-03-2017, 06:48 AM   #2
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
Maybe: tune2fs -l /dev/sda1 [?]

Last edited by Jjanel; 04-03-2017 at 06:57 AM.
 
1 members found this post helpful.
Old 04-04-2017, 06:59 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Try gparted(8)
 
Old 04-05-2017, 02:23 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
I think that's just a partition-table editor.

Easiest way to find used space might be to mount it.
 
Old 04-05-2017, 03:53 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,981

Rep: Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625
Try gparted but in reality it may mount the disk for exclusive use to gparted to provide graphical image of area used. In fact, there has to be some access to the drive in order to find any information about it. There is none saved by default in other places.
 
Old 04-05-2017, 04:03 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
As I read the OP, it seemed to want to know how much free space was available on the file-system, as seen by that file-system, but without mounting it.

And, I don't know that you can do that. When mounting, the appropriate filesystem driver is matched-up to the partition and is responsible for knowing how to do things with it – including reporting the amount of free space.
 
Old 04-05-2017, 04:41 PM   #7
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
This seems to work:

Code:
sudo tune2fs -l /dev/dm-2 |grep -E '(^Free blocks|^Block count)'
Block count:              52166656
Free blocks:              45174456
 
Old 04-05-2017, 05:24 PM   #8
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
Maybe {dump,tune}e{2,4}fs here: http://fossies.org/linux/gparted/src/ext2.cc
208 index = output .find( "Free blocks:" ) ; [? Idk]
 
Old 04-07-2017, 04:40 PM   #9
rob.rice
Senior Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 1,076

Rep: Reputation: 205Reputation: 205Reputation: 205
what's the big deal it's easy to mount and unmount a file system
unless your not root in that case anything that could answer your question will not run ether

Last edited by rob.rice; 04-07-2017 at 04:46 PM.
 
Old 04-07-2017, 08:13 PM   #10
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,981

Rep: Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625
Cause the OP asked not to mount it for some reason.
 
Old 04-08-2017, 06:30 PM   #11
rob.rice
Senior Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 1,076

Rep: Reputation: 205Reputation: 205Reputation: 205
then the simple answer would be NO it needs to be mounted
the more complex answer is
the kernel needs to have the block tables loaded in to memory and the kernel modules
that work with that file system loaded and they have to be told things where on the disk the file system starts block size all of this is handled by the mount command
copy,rm,mkdir,du,diff all commands that work with a file system and files depend on kernel calls that in turn depend on info set up by mount

there is almost nothing that can be done with a file system that is unmounted
AFAIK
the only utility that can do any thing with an unmounted file system is dd

like it or not he is going to have to mount that file system to run df on it

Last edited by rob.rice; 04-08-2017 at 06:41 PM.
 
Old 04-08-2017, 06:44 PM   #12
rob.rice
Senior Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 1,076

Rep: Reputation: 205Reputation: 205Reputation: 205
Quote:
Originally Posted by smallpond View Post
This seems to work:

Code:
sudo tune2fs -l /dev/dm-2 |grep -E '(^Free blocks|^Block count)'
Block count:              52166656
Free blocks:              45174456
OK what is the size of the blocks ?
free_space = (45174456*block_size)-indexing_data

Last edited by rob.rice; 04-08-2017 at 06:59 PM.
 
Old 04-08-2017, 08:39 PM   #13
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by rob.rice View Post
then the simple answer would be NO it needs to be mounted
The internals of every Linux filesystem are published and available. The internals for various proprietary filesystems, if not published, have been reverse-engineered, or else the kernel would not be able to parse those filesystems. The header files with all the structure definitions can be used to build programs that simply open() the device containing the filesystem and read data from the headers. For ext2/3/4 filesystems, those headers are in the e2fsprogs-devel package. That's how programs like e2fsck, badblocks, debugfs, resize2fs, tune2fs, etc. (programs that take a device name, not a mount point, as an argument) operate for ext2/3/4 filesystems. There are similar programs for other filesystems. None of the mount the filesystem.
 
Old 04-09-2017, 06:21 PM   #14
rob.rice
Senior Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 1,076

Rep: Reputation: 205Reputation: 205Reputation: 205
Quote:
Originally Posted by rknichols View Post
The internals of every Linux filesystem are published and available. The internals for various proprietary filesystems, if not published, have been reverse-engineered, or else the kernel would not be able to parse those filesystems. The header files with all the structure definitions can be used to build programs that simply open() the device containing the filesystem and read data from the headers. For ext2/3/4 filesystems, those headers are in the e2fsprogs-devel package. That's how programs like e2fsck, badblocks, debugfs, resize2fs, tune2fs, etc. (programs that take a device name, not a mount point, as an argument) operate for ext2/3/4 filesystems. There are similar programs for other filesystems. None of the mount the filesystem.
yes a program can be written to read free space from an unmounted partition
BUT
the OP did not ask how to write such a program
and why write one when it's so easy to mount a file system run df on it and unmount it
then
is there a program that can read the free space from an unmounted partition

the only program that I know of that even comes close to READING from an unmounted file system is dd but you would still have to mount it to do anything with the copy of it

Last edited by rob.rice; 04-09-2017 at 06:44 PM.
 
Old 04-09-2017, 07:28 PM   #15
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by rob.rice View Post
yes a program can be written to read free space from an unmounted partition
BUT
the OP did not ask how to write such a program
and why write one when it's so easy to mount a file system run df on it and unmount it
then
is there a program that can read the free space from an unmounted partition

the only program that I know of that even comes close to READING from an unmounted file system is dd but you would still have to mount it to do anything with the copy of it
"tune2fs -l" will show you the total number of blocks in the filesystem and the number of free blocks, as well as the inode count and the number of free inodes. The output from e2fsck will do the same, though that would be a silly reason to run e2fsck. If the filesystem is directly on a device or partition (i.e., no LVM, encryption, etc.), gparted will also show how much of its space is in use, and it does not mount the filesystem to do so. The OP asked, "Is it possible?" The answer is, "Yes."
 
  


Reply

Tags
disk



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to find disk space in root file system. manoj.linux Solaris / OpenSolaris 2 09-13-2013 06:35 AM
how to free the disk space for root file system in rhel4 bhaskar1967 Linux - Newbie 2 09-01-2013 01:41 PM
How do you locate superblocks in an unmounted disk image file? serutan Linux - General 1 02-07-2010 10:24 PM
File system root low disk space prickee Ubuntu 6 11-20-2009 04:06 AM
Large tar file taking huge disk space in ext3 file system pcwulf Linux - General 2 10-20-2003 07:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:30 PM.

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