LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-08-2006, 09:16 AM   #1
jgombos
Member
 
Registered: Jul 2003
Posts: 256

Rep: Reputation: 32
Need a tool to tell me the last *used* sector of a filesystem


I'd like to find a tool that will tell me the last sector that contains meaningful content for a given partition.

The scenario is that I have an NTFS partition that has been defragged a few times to get the unused space shifted toward the end of the partition. I want to create a minimal image that excludes the trailing unused space. I would first like to find a filesystem agnostic tool that can tell me this for any partition type. If that doesn't exist, then I would be interested in getting a tool for each of these types: NTFS, FAT16/32, ext2/3.
 
Old 11-11-2006, 07:33 AM   #2
letitgo
Member
 
Registered: Jul 2003
Location: New Orleans
Distribution: Slackware 13.0
Posts: 111
Blog Entries: 1

Rep: Reputation: 15
You could look into qtparted
http://qtparted.sourceforge.net/
(which invokes ntfresize) or ntfresize itself
http://man.linux-ntfs.org/ntfsresize.8.html
for just the NTFS partion... but be prepared
to do some careful reading and planning if you
use ntfsresize as a stand alone...
 
Old 11-11-2006, 08:24 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
I'm not sure it's possible. I think in most filesystems timestamps are kept on a per-file basis, not at the disk block/cluster level. What you could do is write a program to scan a filesystem for the last used files, and then get the blocks used from that maybe, although I don't know what mechanism you'd use to get the blocklist.

*edit* just as I hit post I realised you're not talking about last as in time, but last as in physical position on the disk... Ignore what I said.

Last edited by matthewg42; 11-11-2006 at 08:26 AM.
 
Old 11-11-2006, 09:17 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
It seems that--unless you have total knowledge of how a filesystem works--it would be very iffy trying to image only part of a partition. I have successfully re-sized NTFS partitions with QTParted--why not go that way?

OR:
Can you not make a full partition image and then compress it?
 
Old 11-11-2006, 10:04 AM   #5
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
Quote:
I want to create a minimal image that excludes the trailing unused space.
ntfsclone can do this, see the above link for linux-ntfs.org.
 
Old 11-11-2006, 12:06 PM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
If you have a partition with the unused blocks filled with 0's then you will be able to compress the image file well.
 
Old 11-11-2006, 02:45 PM   #7
letitgo
Member
 
Registered: Jul 2003
Location: New Orleans
Distribution: Slackware 13.0
Posts: 111
Blog Entries: 1

Rep: Reputation: 15
Oops, I notice that you're not a new user...
Perhaps the system tool debugfs
I.E.,
usr@host:~$ man 8 debugfs
might be of use for examining the ext2/ext3 filesystems.
IIRC GNU parted:
http://www.gnu.org/software/parted/index.shtml
should be able to resize these and the fat partions
 
Old 11-11-2006, 10:20 PM   #8
jgombos
Member
 
Registered: Jul 2003
Posts: 256

Original Poster
Rep: Reputation: 32
Thanks for the help folks.

Quote:
Originally Posted by letitgo
You could look into qtparted ... or ntfresize
So you're essentially saying shrink it to be as small as possible, image it, then expand it back prior to using it? It appears that the union of GNU Parted and QTParted will shrink anything (excluding Fat12 and HFS). So that may indeed be the answer, but I'd prefer not to tamper with the original partition more than I must.

Quote:
Originally Posted by pixellany
It seems that--unless you have total knowledge of how a filesystem works--it would be very iffy trying to image only part of a partition.
I was curious how the Smart Boot Manager floppy might have been created. It's a floppy image that is much smaller than 1440k - which is unusual. Compression was not used. Someone has figured out how to use dd in a way that excludes the unused space. Someone could write that SBM floppy to a 720k disk if they wanted. Noticing this is what set me on this mission.

Quote:
Originally Posted by pixellany
Can you not make a full partition image and then compress it?
I don't have a specific need for what I'm asking at the moment, but I would like to know how to avoid compression for a couple reasons. Uncompressed images are directly mountable. The other disadvantage to simply compressing the thing is that it must be restored onto a partition of equal or larger size to the original parition. What if the target partition is smaller than the image, but larger than the content?

Quote:
Originally Posted by matthewg42
If you have a partition with the unused blocks filled with 0's then you will be able to compress the image file well.
Even better, if I zeroize the unused space then I might not even have to use compression, because when 'conv=notrunc' is not passed to dd, "multiple blocks of zeros get abbreviated with a string of asterisks, saving a lot of space," according to the dd tutorial. But the issue would still remain that the target partition must not be smaller than the original.
 
Old 11-11-2006, 10:33 PM   #9
jgombos
Member
 
Registered: Jul 2003
Posts: 256

Original Poster
Rep: Reputation: 32
It just occured to me that perhaps I could fill the unused portions with zeros, then pipe a dd partition reading through a tool that reverses everything (so the output stream begins with the end of the device, and moves forward). Then it would just be a matter of counting zeros until the first non-zero is reached, and subtracting that number from the actual ending. Does that sound practical?

It could be problematic if the last piece of content contains meaningful zeros, but the workaround for that may be just to allow for a sufficient buffer of zeros at the end.
 
Old 11-11-2006, 10:39 PM   #10
jgombos
Member
 
Registered: Jul 2003
Posts: 256

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by soggycornflake
ntfsclone can do this, see the above link for linux-ntfs.org.
I just took a look at it. I will probably use that for NTFS partitions from now on.

The problem remains unsolved for non-ntfs filesystems.
 
  


Reply

Tags
ntfsclone, qtparted


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Grey Sector suavecu Linux - Software 1 01-18-2006 07:19 PM
Boot Sector phoenix7 Linux - General 1 11-25-2004 10:22 AM
DISCUSSION: Virtual Filesystem: Building a Linux Filesystem from an Ordinary File mchirico LinuxAnswers Discussion 0 10-28-2004 10:35 PM
Encrypted Root Filesystem HOWTO and /dev filesystem tmillard Linux From Scratch 0 10-18-2004 03:58 PM
URLSCAN tool MS = Linux tool ? OB1 Linux - Security 3 10-05-2002 12:58 AM


All times are GMT -5. The time now is 02:54 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration