LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Resize FAT32 filesystem image (https://www.linuxquestions.org/questions/linux-newbie-8/resize-fat32-filesystem-image-797104/)

joenew 03-22-2010 02:20 PM

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...
why?
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!

PS:
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.

PPS:
Sorry for my english...
anyway hope it is enought clear.

frieza 03-22-2010 02:51 PM

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?

onebuck 03-22-2010 04:16 PM

Hi,

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
LinuxSelfHelp
Getting Started with Linux

The above links and others can be found at 'Slackware-Links' .
More than just SlackwareŽ links!

joenew 03-22-2010 06:17 PM

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. :)

PS.
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".


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