Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top