I am dumb.. I didnt realise I could use GUI apps like Gparted using the VNC option... Can I fix this mess with Gparted?
Tricky question... Just a quick visualisation of what has gone wrong:
I assume some partition setup like this:
Partition 1 | Partition 2 | Partition 3
XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZ
The above partitions are the ones, which the partition table defines. X Y and Z are the drive spaces that are occupied with data from the filesystem (fat, ext4, btrfs, ZFS, etc.).
By using parted to just shrink the partition, we got the following scenario:
Partition 1 | Partition 2 | Partition 3 | Unused disk space
XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZ
Now the Partition 3 won't work, as part of the data for the filesystem is outside of the partition boundary.
Currently there is no data lost, just the partition table is messed up. This can be fixed by manually adjusting the partition table or using "parted rescue" or testdisk.
But there might be the case, that fsck or something else has corrupted the data (like creating a new partition and formatting it in the unused disk space). This is the bad case, where you probably need some data recovery tool (like photorec).
The correct way of shrinking is the following (which GParted does automatically):
Partition 1 | Partition 2 | Partition 3
XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZ
Shrink the filesystem down first (resize2fs does this):
Partition 1 | Partition 2 | Partition 3
XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZ
Then change the partition table to actually shrink the partition:
Partition 1 | Partition 2 | Partition 3 | Unused disk space
XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZ
Enlarging a partition works the other way around. First the partition table is modified:
Partition 1 | Partition 2 | Partition 3
XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZ
And now the filesystem is resized (again with resize2fs) according to the partition boundaries:
Partition 1 | Partition 2 | Partition 3
XXXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZ
Why is this necessary to know?
Because the resize2fs part changes actual data on the disk. As GParted does this automatically, it might overwrite something (i don't know, maybe it's smart), as usually the partition you expand is in a working state.
Therefore I would suggest the following steps:
- Backup your partition tables before and after every attempt to fix something, as you maybe want to revert back at some point to an old partition table: https://www.cyberciti.biz/faq/…able-with-sfdisk-command/
- Try "parted rescue" or testdisk to automatically recreate a working partition table
- Try gparted
- Recover your files the hard way using photorec or similar tools
Edit: Just for your information: You can use X11 tunneling to use GUIs via SSH: https://wiki.archlinux.org/index.php/OpenSSH#X11_forwarding