# [SOLVED] Merging partitions

## salmonix

Hi there, apologies if this is a common subject, but I've got lost a bit.

Now, I have a root partition and a partition with /usr. This scheme does not really work now, I would like to merge the two partitions safely, almost 1GB would be my reward. Can I have some hint?

Thanx a lot in advance.

----------

## NeddySeagoon

salmonix,

You will need to back up both partitions, destroy them both and recreate one large partition in their place.

However, its not always possible. Please post your 

```
fdisk -l /dev/... 
```

and explain what each partition is used for.

----------

## salmonix

Here it is:

darkstar salmonix # fdisk -l /dev/hda

Disk /dev/hda: 160.0 GB, 160041885696 bytes

255 heads, 63 sectors/track, 19457 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: 0x3607d289

   Device Boot      Start         End      Blocks   Id  System

/dev/hda1   *           1         486     3903763+  83  Linux

/dev/hda2             487         972     3903795    5  Extended

/dev/hda3             973        1094      979965   82  Linux swap / Solaris

/dev/hda4            1095       19457   147500797+  83  Linux

/dev/hda5             487         608      979933+  83  Linux

/dev/hda6             609         972     2923798+  83  Linux

hda1 = /

hda2 = extended

hda3 = swap

hda4 = /home

hda6 = /usr

Now, I would like to merge hda1 and hda6. even at the price of removing swap - using a swapfile instead put into /home. My system shows very low - max.20Mb - swap usage, anyway.

Thanx for you concern.

----------

## fangorn

I'm afraid with your setup you cannot redo much of the partitioning. 

Fastest way is to make backup of everything and start from scratch with a new scheme. Something sensible like 

Primary 100 MB for /boot    # not necessary any more, but I like it that way

Primary 4 GB for swap        # if you have swap at all make it big enough

Primary 10 GB for /             # This is enough for a quite extensive gentoo desktop installation

Extended Rest

logical 2 GB for /usr/portage # this hurts / if parked there

logical 5 GB for /home          # I only store config and customized program data in there

logical Rest for /data             # or however you wanna call it

For security reasons you might consider making /tmp a tmpfs in RAM and encrypting swap, /home and /data.

If you are unsure of what sizes you need, better read into how to use lvm2. Then you can easily change sizes later on if you spared some free space in the beginning. 

How ever you implement the new scheme, when done just mount / to /mnt/gentoo in your livecd environment and the other partitions according to that and untar the backup you made. Then edit fstab and menu.lst and reinstall grub and your done.

Edit: 

OK, excuse me, this is quite an uncommon scheme of yours. Took me a third glance to reallize   :Rolling Eyes: 

You could delete the extended partition hda2 (and therfore loose the hda5 and hda6) and (theoretically) increase hda1 to take up the space of all of them. This way you would loose /usr and from the size I would say it is /boot and would have to backup them and install them to the new hda1 afterwards. If you don't forget to activate hda1 and don't mind your options are "limited" later on, this would be an option.

----------

## NeddySeagoon

salmonix,

The partitions to be merged must occupy contiguious blocks on the drive, so that when you delete them both, you hav all your free space in one piece. That is not your case.

What is getting full ?

You can try 

```
eclean distfiles 
```

to get rid of distfiles for packages you no longer have installed.

You can also do 

```
eclean packages
```

to do the same thing for any binary packages you may have saved.

```
rm -r /var/tmp/portage/*
```

gets rid of the debries of broken builds. Don't do that if emerge is running.

You can also move things like your portage tree, and portions of it from the default /usr/portage location by setting some variables in /etc/make.conf.

You may yet regain your space or move things around to achieve the same effect as a partition merge.

----------

## salmonix

Well, removing the partitions hda1, hda2, hda6, hda3 I have a 8998Mb cont.partition, that would do it. (The rest is a big /home with all distfiles and portage tree, actually.)

Now, I need a little help with backing the partition hda1 and putting back to its new place. I know dd, but then what when I write the smaller image to a bigger partition? 

fangorn: yes, it is, because originally there was a "spare" partition for playing with ArchLinux, and it was ment to be a small home server/router. But things changed.

----------

## fangorn

for backup purposes tar is more suited. dd makes a perfect copy. You could use that and resize later, but its a waste of time.

in your running linux use the following

```
mkdir /mnt/backup

mount -o bind / /mnt/backup

cd /mnt/backup

tar cvjpf /home/<username>/backup_root.tar.bz2 * 

cd /

umount /mnt/backup 

cd /boot

tar cvjpf /home/<username>/backup_boot.tar.bz2 *

cd /usr

tar cvjpf /home/<username>/backup_usr.tar.bz2 *

```

then reboot the machine with a livecd, repartition format and mount the new partition to /mnt/gentoo. Mount your /home somewhere and unpack the backups with 

```
tar xvjpf <filename>

```

----------

## NeddySeagoon

salmonix,

hda2 is a fake. It is a logical container for hda5 and hda6. To remove hda2 you must first remove hda5 and hda6.

Removing hda1, hda3 and hda6 will only leave 3 lots of empty space that are not joined up.

Worse, hda6 is actually inside hda2 and cannot be moved outside.

Maybe this diagram of the physical lay out of your drive helps ...

```
hda1

hda2 - container for:-

    hda5

    hda6

hda3

hda4
```

----------

## salmonix

That is OK., I need hda4 kept up, so all the rest may be erased. I normally put home part. as highest primary - this is  data usually. The rest I can safely remove so I gain space. Now, I should do the proper backup for root (hda1) and the rest goes fine. 

(I would not mind a new install, but a. it would take time /this is my workhorse PIII 600 /, and 2. no time now.)

Thanx for the help.

----------

## fangorn

Dont forget to backup /usr and /boot. 

Without them a new installation is unavoidable!!

----------

## salmonix

Ok. Only a hint more:

shall I use a bootcd and dd / into a file -  is it possible to dd it into the new place - a bigger partition?

----------

## fangorn

 *fangorn wrote:*   

> dd makes a perfect copy. You could use that and resize later, but its a waste of time.
> 
> 

 

As said before, use tar for a backup, it only copies actual data, not each and every sector of the partition. This is usually much faster.

----------

## NeddySeagoon

salmonix,

dd does a low level block copy. It copies whatever is in the disk space, including the free space, which is wasteful and filesystem metadata. That makes it difficult to restore to a space that is a different size.

tar, cp -a, or rsync are all better than dd for your purpose.

----------

## salmonix

Thanx for both of You!

----------

