[SOLVED] Resize home and root partitions

You have a problem with Salix? Post here and we'll do what we can to help.
Shador
Posts: 1295
Joined: 11. Jun 2009, 14:04
Location: Bavaria

Re: Resize home and root partitions

Post by Shador »

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.

Code: Select all

dd if=/dev/zero of=/dev/sda bs=512 count=1 seek=1 conv=notrunc
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:

Code: Select all

dd if=/dev/zero of=/dev/sda bs=512 count=1 seek=1953525167 conv=notrunc
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.
bobferrell wrote:255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
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.
To backup the beginning of the disk do this:

Code: Select all

dd if=/dev/sda of=first64.img bs=512 count=64
For the end do this :

Code: Select all

dd if=/dev/sda of=last.img bs=512 count=1 skip=1953525167
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:

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
The same notes regarding device, seek value etc apply here too.
Image
bobferrell
Posts: 17
Joined: 11. Feb 2012, 20:04

Re: Resize home and root partitions

Post by bobferrell »

Okay, that looks like it worked I was able to run the parted -l command without the previous message coming up.

# parted -l
Model: ATA ST1000DL002-9TT1 (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 32.3kB 6292MB 6292MB primary ext4 boot
2 6292MB 7345MB 1053MB primary linux-swap(v1)
3 7345MB 1000GB 993GB primary ext4


However, I still have the issue where my primary (root) partition is too small. I did some googling for resizing an lvm partition and found lvresize command. I'm assuming I should use this. Do I need to unmount the partitions before doing this?

Thank you...
User avatar
mimosa
Salix Warrior
Posts: 3311
Joined: 25. May 2010, 17:02
Contact:

Re: Resize home and root partitions

Post by mimosa »

I'm not sure about LVM. But try just having a look now with Gparted - you may see your / and /home, which I'm still guessing are logical partitions within an extended partition, sda3.

EDIT

I'm talking nonsense - sda1 looks like / (6GB or so) :oops:

In this case you need to shrink sda3, move swap to the right (sda2) and lastly expand sda1. I don't know about the lvm aspect (wiser heads ... ;) ) but it is generally preferable if at all possible to avoid using manual tools like the one you mention, because there are no safeguards and it's easy to break something. My guess is Gparted can cope now. It's just a front end for lots of little partition and filesystem manipulation tools.
Last edited by mimosa on 13. Feb 2012, 17:44, edited 1 time in total.
Shador
Posts: 1295
Joined: 11. Jun 2009, 14:04
Location: Bavaria

Re: Resize home and root partitions

Post by Shador »

You don't have a LVM setup. There's no way the autmatic partition option sets that up and it's also clearly not indicated by fdisk -l. Just use gparted to resize your partitions.
Image
bobferrell
Posts: 17
Joined: 11. Feb 2012, 20:04

Re: Resize home and root partitions

Post by bobferrell »

Okay, I think I finally got it now. The presence of the GPT table made gparted think I had an LVM setup. Is this correct? Sorry for my stupidity. :oops:

I am in GParted and I successfully shrunk the home partition to 500 GB. Now GParted will not allow me to add the unallocated data to the root partition. Does the partition have to be continuous?
Shador
Posts: 1295
Joined: 11. Jun 2009, 14:04
Location: Bavaria

Re: Resize home and root partitions

Post by Shador »

bobferrell wrote: Okay, I think I finally got it now. The presence of the GPT table made gparted think I had an LVM setup. Is this correct? Sorry for my stupidity. :oops:
You're previous setup was LVM with GPT as partmap. As GPT was not removed when the installer setup a msdos partition table the old GPT partition table for the LVM setup was still there and visible to gparted, although that setup was not actually existent anymore. Going back to books again.

You had a book with a index on the second and the very last page (GPT) and another index on the first page just referring to the one on the second page. The content of the book was some chitchat about LVM. ;) That's what you had before installing Salix.
Then you installed Salix and only the index on the first page (MBR) was replaced. The other one on the second and last page (GPT) stayed untouched. The content of the book was also exchanged. No more LVM anywhere now. Instead Salix chitchat is now in there. ;) But the index on the second and last page (GPT) still was referring to all that LVM chitchat which is not actually there anymore. After deleting that unnecessary index you just have a plain, old mbr now which is perfectly fine for Salix and desktop use. Actually I think Slackware would still choke on GPT and EFI and require quite some fiddling. So you're safe with mbr.

Anyway regarding the different tools:
fdisk/cfdisk/... only know how to read MBR. They just plainly ignore it or spit out a small warning that gpt is there. For the book that means they just don't care what the second and last page contains. They're only interested in the index on the very first page.
(g)parted knows MBR and GPT among many others. So it started to wonder what kind of book this is with two indexes referring to different content. It did not think you have a LVM setup, it just saw the old index referring to it, while actually the mbr was saying something different. So it was confused and asked for help
bobferrell wrote: I am in GParted and I successfully shrunk the home partition to 500 GB. Now GParted will not allow me to add the unallocated data to the root partition. Does the partition have to be continuous?
Yes, partitions must be continous. You need an abstraction on top like raid or LVM, which simulates continous partitions transparently when actually the disk space is split. But that adds unnecessary complexity and thus chance for failure for desktop systems imo.
You just need to move the swap space to the right as mimosa pointed out. Just press the Change size button for the swap partition and drag it to the very right. Then you should be able to extend your root.

BTW usually you shouldn't need much more than 10GB for root. Definitely not more than 15-20.
Image
bobferrell
Posts: 17
Joined: 11. Feb 2012, 20:04

Re: Resize home and root partitions

Post by bobferrell »

Hello,
I was able to modify the partitions to my liking now. Thnk you for all of your help...

Now how do I mark this topic as solved?
Shador
Posts: 1295
Joined: 11. Jun 2009, 14:04
Location: Bavaria

Re: [SOLVED] Resize home and root partitions

Post by Shador »

Just edit the first post. But I already did it for you this time.
Image
User avatar
SoleSoul
Posts: 49
Joined: 2. Oct 2009, 01:53
Location: Israel

Re: [SOLVED] Resize home and root partitions

Post by SoleSoul »

Excellent thread.
Thank you Shador for the explanation.
(and thanks for the question also ;) )
Post Reply