Rather than manually editing the partition tables you could just recreate your old partition table using gparted and either use
cp -p or
dd to copy the old partitions into the new ones.
External storage requirements
How you do so depends on your external storage capabilities. If you have another drive that you can copy the partitions you should copy the primary partition(s) to an image (for
dd) or directory (for
cp) on the external drive, then create an empty logical partition and and copy the image into this new empty partition. This would be the best way to go about things.
To back partitions up as images somewhere (sda1 being the first partition on your first hard drive):
sudo dd if=/dev/sda1 of=[path to where you want to store the image] bs=1M noerror
To copy partitions to a directory (preserving permissions) first mount them then:
sudo mkdir /[path to where you want to store them]/partition-backup1
sudo cp -pr /media/mounted-partition-to-be-copied /[path to where you want to store them]/partition-backup1
See below for more information on
If you don't have external storage
However, if you don't have enough space/time to copy to partitions to external storage first, you could potentially use creative resizing/copying to do the entire move on the same drive. In other words, you could resize partitions with a lot of free space down to a smaller size give you the room to create new duplicate logical partitions and then delete the old one and resize back up after the copy. You would also need to temporarily store one partition as an image inside of another one so you could create the extended partition.
However, be careful if any of the partitions (/home, swap, etc) are encrypted. If so it would be very, very dangerous to resize them. There is a guide for resizing encrypted partitions here but I wouldn't recommend doing so unless you really cannot find any external storage to avoid this step.
Copying the old primary partitions into new logical partitions
First make sure you have a liveCD/USB handy, you will probably need to reinstall GRUB later.
I'm assuming here that you have assessed the method best for you and have now created an empty new logical partition and have access to either the old primary partition or an image of the partition stored externally.
You can either use
cp which copies file by file or
dd which copies blocks of raw data. For any encrypted partitions you will have to use
dd. I personally feel that when used correctly
dd is safer because you don't have to worry about permissions/ownership/symlinks/etc. However if you make a mistake using
dd you will break something.
cp: (for non-encrypted partitions) first mount both the old primary version of the partition and the new empty logical partition. The copy the files from the old partition to the new ones. The
-p option preserves the permissions and owners of the files so you don't mess up your permissions,
-r just copies recursively. However it cannot create files with owners above the permissions of whoever is running the command so you shoul run this command as root.
sudo cp -pr /media/[mounted-old-primary]/ /media/[mounted-empty-logical]/
This might take awhile.
dd: You need to be absolutely sure of the partition names of your old and new partitions. You should also be cloning partitions that are exactly the same size (or to a partition that is larger--at your own risk). Do not try cloning to a partition that is smaller than the original.
dd will overwrite any device it is ordered to copy to. Either use the gparted GUI to get these right or you can run
sudo fdisk -l to see the partition table. Once you are sure of your names run the
dd command (must be run as root to write directory to devices)
People googling in: DO NOT run the following commands unless you understand what they do and have changed the partition names to the partitions your want to copy/overwrite
sudo dd if=/dev/sda2 of=/dev/sda6 bs=1M noerror
In this example
sda2 is the original primary partition and
sda6 is the new, empty logical partition. Be sure to check that you've changed the pathes correctly before each operations.
If you are copying from an image you backed up, run a command like this:
sudo dd if=/path/to/image.img of=/dev/sda6 bs=1M noerror
Either of these will also take awhile. You can make sure they are still running by checking
top and noting various related processes chugging along.
Do not delete anything until you are sure that it has copied correctly and that you will not need the backup anymore. That said once you've successfully copied everything onto the new logical partitions you will want to remove the old primary partitions and resize all the partitions to how you want them.
You haven't touched the MBR at all but if you've moved the partition with
/boot on it, you will need to reinstall/upgrade GRUB so it points to the new partition.
Reinstall GRUB from a liveCD by mounting your
/ directory (replace sda3 with whatever partition it is for you)
sudo mount /dev/sda3 /mnt
At this point you could run
sudo grub-install --root-directory=/mnt /dev/sda to reinstall grub but you would still need to run
update-grub from the native installtion (meaning a rescue boot from the GRUB command line) to update the config files. We can combine both these steps and use
chroot to make the
/ partition the liveCD's
(This part heavily based on https://help.ubuntu.com/community/Grub2/Installing)
Mount the critical virtual filesystems. Run the following as a single
for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
Chroot into your normal system device:
sudo chroot /mnt
Reinstall GRUB 2:
Recreate the GRUB 2 menu file (grub.cfg)
Exit chroot: CTRL+D