Re: Resize home and root partitions
Posted: 13. Feb 2012, 14:06
Disclaimer! The commands listed below here irrecoverably overwrite small parts of your harddisk. If used properly and with care no date should be harmed in the process. But be warned and better have a backup of at least your important data in place. There's always a chance of human error.
You need to remove the gpt structure at the beginning of the disk like this.
This command should generally work on any disk to erase the main gpt structure. Be sure to use the right disk (i.e. replace /dev/sda)! Before running it you should make sure that no partition starts at sector 1 as that one is overwritten with zeroes. (For bobferrel's disk this command and all followings should work as is.)
There's another backup of that structure at the end of the disk. Delete that one like this:
WARNING! This command only works for this one disk. For other disks it likely causes data corruption.
You need another number after seek=. Consult the output of fdisk -l. The number you need to put after the seek= is the total of sectors MINUS ONE. In this case 1953525168 - 1 = 1953525167.
To backup the beginning of the disk do this:
For the end do this :
Again the value might differ for other disks. You need to calculate it as previously described from the total of sectors minus one.
Note that it's skip instead of seek here because we switched input/output. This creates files named first64.img and last.img which you should copy in a safe location. To restore them you would replace the /dev/zero in the commands used to overwrite the gpt structures like this:
The same notes regarding device, seek value etc apply here too.
You need to remove the gpt structure at the beginning of the disk like this.
Code: Select all
dd if=/dev/zero of=/dev/sda bs=512 count=1 seek=1 conv=notruncThere's another backup of that structure at the end of the disk. Delete that one like this:
Code: Select all
dd if=/dev/zero of=/dev/sda bs=512 count=1 seek=1953525167 conv=notruncYou need another number after seek=. Consult the output of fdisk -l. The number you need to put after the seek= is the total of sectors MINUS ONE. In this case 1953525168 - 1 = 1953525167.
Before you run those commands I recommend you backup the areas of the disk we are going to overwrite. Put those backups onto an external media as they are useless otherwise. Also be sure to unplug that device before you continue for additional safety.bobferrell wrote:255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
To backup the beginning of the disk do this:
Code: Select all
dd if=/dev/sda of=first64.img bs=512 count=64Code: Select all
dd if=/dev/sda of=last.img bs=512 count=1 skip=1953525167Note that it's skip instead of seek here because we switched input/output. This creates files named first64.img and last.img which you should copy in a safe location. To restore them you would replace the /dev/zero in the commands used to overwrite the gpt structures like this:
Code: Select all
dd if=first64.img of=/dev/sda bs=512 count=1 seek=1 conv=notrunc
dd if=last.img of=/dev/sda bs=512 count=1 seek=1953525167 conv=notrunc