Extend linux partition size without losing any data / techniques
Solution 1:
Removing or creating a partition doesn't remove a data or a filesystem on a disk. It will only update the MBR or GPT information where partition lies and its size.
Also, if the filesystem finds itself on the device which is larger than that is stored in its superblock, it will just work as if that was small device.
Based on this knowledge, you can deduce the extension process. It is as follows:
- On a running system, run
fdisk
and carefully observe where the partition starts (p
). Then remove it (d
), and create (n
) larger one on its place. Modern fdisk could ask about wiping signatures, if it will, say "no" (this is essential)! Pay special attention on its start, it must begin at exact same sector, but could have larger size. Exit fdisk writing changes (w
).
Filesystem could be left mounted. That will not broke access to data. In fact, kernel will refuse to reload partition table, because the old parition was in use, and it will use old parition mapping. To update a partition mapping in the kernel, you can simply reboot, or use kpartx
or partprobe
program in case service interruption is infeasible.
Of course, you could have unmount filesystem in beforehand and remount after partition recreation, then kernel would not be blocked and partition mapping will be updated right after exit from fdisk.
- Resize a file system. Ext4 can be resized online (just
resize2fs /dev/sdb1
, it will detect mounted filesystem and run online resize). Or you can again do this while it is unmounted, if you wish.
Of course, this is still dangerous process. Have backups somewhere.