0

Simple enough: I have an LVM partition (e.g. /dev/mapper/foo-fat) that contains a Fat32 file system. Prior to reducing the size of this LVM partition (which I'll do with lvmreduce), I want to reduce the size of the Fat32 filesystem it contains.

It looks like parted should be able to do it, but I can't find the magic invocation to make it work.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Edward Falk
  • 9,991
  • 11
  • 77
  • 112

3 Answers3

3

Use fatresize (manpage) and then proceed with lvresize.

To avoid truncating the FS, you should first shrink the VFAT volume a few hundreds (to be safe) megabytes more than wanted, then resize the LVM container and finally grow the volume to fill the LVM partition.

Besides, this question does not belong to StackOverflow but to ServerFault.

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
3

No answers + deadline to meet = write it myself.

For future reference, it was only a few lines of code, using libparted. For readability, I've omitted error checking, etc. Caller is responsible for ensuring there's enough space in the partition for the new filesystem size.

#include <parted/parted.h>

int
resize_filesystem(const char *device, PedSector newsize)
{
        PedDevice *dev = NULL;
        PedGeometry *geom = NULL;
        PedGeometry *new_geom = NULL;
        PedFileSystem *fs = NULL;
        int rc = 0;

        dev = ped_device_get(device);
        ped_device_open(dev);

        geom = ped_geometry_new(dev, 0LL, dev->length);

        fs = ped_file_system_open(geom);

        new_geom = ped_geometry_new(dev, 0LL, newsize / dev->sector_size);

        ped_file_system_resize(fs, new_geom, NULL);

        ped_file_system_close(fs);
        ped_geometry_destroy(geom);
        ped_geometry_destroy(new_geom);
        ped_device_close(dev);

        return rc;
}
Edward Falk
  • 9,991
  • 11
  • 77
  • 112
0

This appears to be what you want, http://www.gnu.org/software/parted/manual/html_chapter/parted_2.html#SEC25

jcopenha
  • 3,935
  • 1
  • 17
  • 15
  • Yes, that was the first thing I tried, but it wants to have access to the device's partition table so it can resize the partition as well as the filesystem. But I'm running under LVM and there *is* no partition table and I'll be using LVM to resize the actual partition. I only wanted to resize the filesystem without mucking about with the underlying partition. The parted command-line program apparently doesn't support this. – Edward Falk Dec 25 '10 at 18:19