Linux – Using resize2fs with file system offset

filesystemslinuxresize2fs

Mount has the option offset to specify that a file system does not start at the beginning of a device but some specific amount of bytes after.
How can I use resize2fs, which does not have that option, to resize such a file system which does not start at the device's beginning?

Best Answer

The offset option of mount does not get passed to mount directly, but to losetup which sets up a loop device which refers to the offsetted location of the underlaying block device. Mount then performs its operations on that loop device rather than the raw block device itself.

You can also use losetup to make resize2fs play which such file systems:

# losetup --offset=<offset> --find --show /dev/<device>
/dev/loop0
# resize2fs /dev/loop0 <newsize>
# losetup --detach /dev/loop0

(Example may not be complete in means of resize2fs operations)

losetup searchs for the first free loop device (in that example /dev/loop0) as --find was passed. --show outputs that loop device to STDOUT.

Related Question