Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-22-2010, 02:20 PM   #1
Registered: Mar 2010
Distribution: slackware 14.2 64bit
Posts: 89

Rep: Reputation: 20
Resize FAT32 filesystem image

Hi all, I'd like to share with you an experiment.
look at following steps:

- create an empty file with a low level tool like "dd"

# dd if=/dev/zero of=fatimage bs=512 count=200K

we now have an about 100MB zeroed file.

- format it with mkdosfs (FAT16)

# mkdosfs fatimage

ok, now we have a 100MB fat filesystem. We could check it with dosfsck.

- Mount it on loop, and copy saome data in it, so that it have a percentage of used space of about 30% (I've tried to copy on it a 30MB data directory). Then umount it.

# mount -o loop -t auto fatimage mountpoint
# cp -a $data mountpoint
# umount mountpoint

- check filesystem with dosfscheck. We can notice used clusters and verify bytes used on that filesystem. And we could evalutate a space amuont to shrink the filesystem...
Just for a didactical test.
Ok, we could decide to shrink our 100MB filesystem to 50 MB: we have about 30 MB of data cpied on it, so there wil be anout 70 MB of free space.

And now the last step: the topic question! :-)

How to resize 100MB fat filesystem to shrink it from 100MB to 50 MB?
If I had used an ext2/3 (or ext4 too but I don't know it) or a ntfs filesystem, I would easly been able to shrink it with resize2fs or ntfsresize.
But as regards Fat filesystem I don't know any tool that work just on the filesystem.
I've tried, fatresize, but It return a strange error... searching for I suspect it is deeply based on parted and it expects to work on a partition not only on a filesystem like that described above.

So is there anyone who knows, which tool I could use to shrink that filesystem?
If you wolud like to make the test following above steps and tring to use fatresize program I will be grateful if you report your results there.

Bye and thanks in advance!

Hope this session is right for this topic. It's my first topic in this forum so If there was a better session please, make me know.

Sorry for my english...
anyway hope it is enought clear.
Old 03-22-2010, 02:51 PM   #2
Senior Member
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,225

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
just a question and forgive me if i seem rude, but considering how trivial it would be to simply create a 50 meg fat image, mount and copy, wouldn't that be easier then trying to shrink an existing image?
Old 03-22-2010, 04:16 PM   #3
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,822
Blog Entries: 27

Rep: Reputation: 2122Reputation: 2122Reputation: 2122Reputation: 2122Reputation: 2122Reputation: 2122Reputation: 2122Reputation: 2122Reputation: 2122Reputation: 2122Reputation: 2122

Welcome to LQ!

I think the 'OP' is just experimenting.

I would use 'parted' to re-size or move. Be sure to defrag the filesystem first. Then perform the operation. You can get the LiveCD 'SystemRescueCd' which has 'parted' and many other useful tools.

Just a few more useful links to expand your understanding;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Newbie Admin Guide
Getting Started with Linux

The above links and others can be found at 'Slackware-Links' .
More than just SlackwareŽ links!
Old 03-22-2010, 06:17 PM   #4
Registered: Mar 2010
Distribution: slackware 14.2 64bit
Posts: 89

Original Poster
Rep: Reputation: 20
First o all, thanks for replies.
I'm just experimeting... this test has no scope itself, I'm interest in a way to just resize a fat filesystem, without data loss. It seems that parted work well in manipulating a partitioned disk, but I'm serarching something more specific to only work with filesystem, not involving a device, partions and partition table.

I've reported above two examples: resize2fs that works for EXT* filesystems and ntfsresize for NTFS filesystem. Also for reiserfs ther is its own tool to resize it. But I've not found any tool to manipulate a FAT filesystem.
It sounds strange in my view cause Fat is a very popular filesystem (despite of all its limitations).

I've searched in the net but without any working result.
I've found two way to shrink a FAT filesystem:
1- using parted
2- unsing a tool called "fatresize" (but based in someway on parted)

I'd like to use some other tool instead.
Yes... I'm not clear on this sentence, but before explain which are problems I noticed I'd prefer to try an other way if it exists.

Thanks a lot for replies.

If you are interested in testing the above steps and founding a tool that works well to resize fat formatted file "fatimage", probably you will notice some error reported by parted or fatresize.
Try if you can, and then verify filesystem with "dosfsck -v".


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
Resize fat32 filesystem to fill partition using parted jjhunt Linux - Hardware 4 02-14-2008 08:51 AM
lost fat32 partition during resize. Is it possible to recover some files? gkiagia Linux - Hardware 3 07-23-2006 09:15 AM
How to resize filesystem (image file)? how to truncate the image? nikov3 Linux - General 4 06-27-2006 03:02 AM
can fdisk or cfdisk resize a fat32 partition? toastermaker Linux - Software 6 01-29-2004 06:42 AM
need to resize ext3 filesystem clsonnt Linux - Newbie 2 07-09-2003 10:59 AM > Forums > Linux Forums > Linux - Newbie

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

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