Ubuntu – Resizing fat32 partition in command line without losing data

partedpartitioning

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?

Best Answer

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.