11

I am trying to resize a fat 32 partition in my linux machine. Following are the specs of the system.

  1. This is not a PC hence UI based tools are not applicable.
  2. This memory partition which I am trying to resize is already having data in the form of files. I can't lose them.
  3. I am trying to shrink the partition to used space alone and move the remaining space to another partition.
  4. Preferably without rebooting of system, unmounting of partition would be fine.

Edit: Backing up data from this partition is not what I am looking for. I am trying to see if there is a way that I can try without losing data. Its more like an analysis rather than task.

What I tried till now: Tried using parted tool as gparted needs an UI. Even though I am able to shrink this partition, it is leading to unnecessary problems due to file fragmentation. For example, after shrinking when I run file system check I am getting errors like chain not found for few files.

I cant use tools like resizee2fs as it supports only ext file systems (correct me if I am wrong here).

I tried using tool fatresize, even though I am able to successfully get it install it in my debian I am not able to get an installable for arm, whatever link I am getting is throwing an error on line 1 statement itself.

Can someone help me with any information they could?

3 Answers3

7

fat32 part resize

NOTE: first of all, backup your data, just in case.

a test of resize sda1 from 28G to 10GB.

0. orig size

//check partition size

ubuntu$ sudo mount /dev/sda1  /media/chen/test

ubuntu$ lsblk /dev/sda NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 28.9G 0 disk └─sda1 8:1 1 28.9G 0 part /media/chen/test

//check fs size

sudo fatresize -i /dev/sdXX

1. change fs: fatresize

ubuntu$ sudo fatresize /dev/sda1 -s 10G -p -v
fatresize 1.0.2 (06/16/18)
.Error: Partition /dev/sda1 is being used.  You must unmount it before you modify it with Parted.

ubuntu$ sudo umount /dev/sda1

ubuntu$ sudo fatresize /dev/sda1 -s 10240M -p -v fatresize 1.0.2 (06/16/18) .FAT: fat32 Size: 30985420800 Min size: 2483422208 Max size: 30989615104

NOTE

// gparted seems not change fs size, without this step, will got a broken fs, says: fs large than volume:

ubuntu$ sudo dosfsck /dev/sda1
fsck.fat 4.1 (2017-01-24)
Seek to 30985420288:Invalid argument

ubuntu$ sudo fatresize /dev/sda1 -s 9G -p -v fatresize 1.0.2 (06/16/18) .Error: The file system is bigger than its volume!

2. change partition: gparted OR partx

resize sda1 part size in gparted GUI // partx cli also can do this.

ubuntu$ lsblk /dev/sda
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    1 28.9G  0 disk 
└─sda1   8:1    1   10G  0 part

ubuntu$ sudo blkid /dev/sda* /dev/sda: PTUUID="d45b4904" PTTYPE="dos" /dev/sda1: UUID="0403-0201" TYPE="vfat" PARTUUID="d45b4904-01"

3. check result

ubuntu$ sudo mount /dev/sda1  /media/chen/test

ubuntu$ df -h /media/chen/test Filesystem Size Used Avail Use% Mounted on /dev/sda1 10G 2.4G 7.7G 24% /media/chen/test

ubuntu$ sudo dosfsck /dev/sda1 ...


update1:

seems gparted will resize fat fs in step 1.
// but if fs mounted, it may fail, but not suspend

here is normal log and result:

gparted_resize_fat.png

yurenchen
  • 471
3

Well, first if you "already having data in the form of files. I can't lose them" your very first step is to back them up before you do anything else.

Resizing and moving partitions does not often result in data loss, and if all else fails you can almost always revover files with photorec - http://www.cgsecurity.org/wiki/PhotoRec - it is a pain to do so.

Second you can not resize or move partitions that are in use. This is the main reason people advise you do these operations from a live usb.

So , no matter what, you can not move or resize your root partition without booting to a live USB (an exception would be adding to LVM).

So long as the partitions in question are not in use, ie unmounted, you can move and resize them :

See How do I resize partitions using command line without using a GUI on a server?

Otherwise your question is likely to be closed due to :

  1. You are running Debian

  2. Lack of information - You did not post your partitioning scheme, tell us what you want to move, what partitions are mounted, and what command and error message you are getting.

Panther
  • 104,528
1

You had better copy the data in the form of files to a safe place (call it backup if you wish), but in this case also a temporary location, because I think you have to accept that you cannot shrink the FAT file system with linux tools. You might be able to do it with Windows tools (FAT32 is a Microsoft file system.)

So after you have copied the data in the form of files to a safe place, you can

  • boot from another drive and unmount all partitions in this drive, that you want to change

  • edit the partition (easiest to remove the FAT32 partition and create a new partition with the size you want.

  • create a FAT32 file system in the new partition

  • do the other modifications to the partition table ...

  • copy the files from the safe place to the new FAT32 partition.

sudodus
  • 47,684