This should work for most cases. You know you cannot use a MBR when you have partitions larger than 2TB, or for more than 15 partitions.
- Use parted to check partition's sizes (i.e. are all smaller than 2TB?),
parted /dev/sdX p
- In case there are larger partitions, shrink the filesystem in question and everything else that needs to be done. (More on this at the end of this posting.)
- Dump all the exact partition sizes,
parted /dev/sdX u B p (show sizes in bytes), so you know how you could eventually recreate the partition layout. Use your phone to make a photo from both
- Remember you can only have four primary partitions with a MBR due to its internal structure. So if you have more partitions, you need free space somewhere on your disk (ofc you need to know where this could be!), to create a logical partition where a VBR can be put onto so you can 'allocate' the other 4th/5th/6th partition that previously existed.
gdisk to zap the GPT.
- Create a new MBR.
- Recreate your partitions, the 1st/2nd/3rd as primary partitions, then on some free space (WHERE NO DATA WAS LOCATED PRIOR!!!) create a logical partition, then create the others.
- Save, quit.
You should use a livedisk like
grml for all this. In case you did something wrong, reboot and retry.
As long as you do not write any data onto the disk, nothing is lost. Remember you still have all your partition layout on your phone, so you can recreate the original GPT if really need be.
In case your really fuck something up and did not take photos, try
testdisk for discerning the partition boundaries. But don't bet any money on it as soon as your layout was anything extraordinary.
On the resizing stuff for making partitions smaller, birds eye perspective:
- First you always have to shrink the filesystem. Easy for ext4 (
resize2fs -M dev/sdX), but impossible for XFS as it cannot be shrunk. Know what you are using and google before attempting such stunts.
- If you have LVM, shrink the logical volume next. (
lvreduce -L 20G /dev/mapper/<VG>-<LV>)
- Next LVM step is downsizing the physical volume.
pvresize --setphysicalvolumesize 25G /dev/sdX is the way to go.
- Afterwards use the partitioning tool of choice, delete the partition where your lvm is put on, and recreate it smaller.
Sizes for all mentioned elements mentioned here are like: Filesystem < LV < PV < partition, if this is not the case after the next reboot you will see you have to do a FS check. Don't do it, just reboot into the livedisk again, and make your adjustments. If you fix things there, your system will boot again, I promise.
To be able to do all this, in case you have PARTITION + LUKS + LVM + FILESYSTEM, here are some hints on how to do this from the shell:
df -h is your friend for showing the filesystem size when you mounted the partition
lsblk -f are your friends for showing partitions
- If you use LUKS, open the crypto container via
cryptsetup open /dev/sdX asdf, enter your password and it should become available unter
/dev/mapper/asdf. Cryptocontainers do not need to be resized. (Skip this if you don't have an encrypted partition, of course.)
vgchange -aay to activate all logical volumes so you can work with them.
mkdir asdf; mount /dev/mapper<VG>-<LV> asdf and then
df -h to check the size of your filesystem prior to resizing.
umount asdf so it is unmounted again.
resize2fs -M /dev/mapper/<VG>-<LV>.
mount /dev/mapper/<VG>-<LV> asdf; df -h to check how big your filesystem still is.
- Make the LV 1GB bigger than the file system. Chances are, this will not be sufficient. Make it even bigger than that if you can affort it, else linux will tell you after the reboot that it won't work. DONT do the FS check when prompted, reboot into the livedisk and start again, no data is lost if that was the case.
- Make the PV 1GB bigger than the LV.
- Make the partition 1GB bigger then the PV. 100M should easily be sufficient, too, as LVM creates extents in size of 4M (that's somewhat like blocks on the harddisk directly, but for LVM), and you only want it to not omit the last extent by making the partition too small. But as I said, should. Don't calculate everything, just adjust things and fix them if they break. It's linux after all, it let's you do this.
Make things bigger than they need to be, so you don't have to reboot as often.
To easily discern what is what with LVM, always use your hostname as name for the VG and the mountpoint (
var, ...) for the LV when creating your LVM setup, if you didn't already do it. This is general hint, not something you are required to do for anything of the above steps.