Moving a Linux Partition

This article describes how I managed to move my linux partition, on a harddisk with WindowsMe, then Linux, and last Windows2000.

Big problem: I had to repartition my harddisk because the Windows2000 partition were too small. I had the following layout:

8GB WindowsMe
8GB Linux RedHat 7.2
1GB Linux swap
2GB Windows 2000

Booting is thus: Lilo with Linux and Dos choice. The Dos choice starts the Windows2000 boot loader, which gives the choices of windows2000 and WindowsMe.

First, I got PartEd from GNU. Be careful to use a functioning floppy. I used this to resize WindowsMe, which stopped working, but its files were still there. Then I made a WindowsMe boot disk made on a functioning WindowsMe machine. To make a boot disk, use "add/remove programs" in the "Control Panel".

After starting the boot disk, i wrote:

"sys c:"
and reeboted. WindowsMe started in safe mode, and then in normal mode, and then worked properly. Windows2000 disappeared from the boot meny, but thats O.K. because I wanted to reinstall it anyway.

Then I had to move the Linux partition down 5.5GB, but PartEd couldn't do that, because the partition overlapped its old boundaries. So I got "Fips". Fips didn't work, so I had to go to manual.

I booted the PC from a linux rescue CD. Running "fdisk /dev/hda" i got something like this:

Disk /dev/hda: 255 heads, 63 sectors, 2432 cylinders
Units = culinders of 16065 * 512 bytes

   Device Boot  Start    End    Blocks   Id  System
/dev/hda1   *       1    446   3582463+   c  FAT32 (LBA)
/dev/hda2        1021   2040   8193150   83  Linux
/dev/hda3        2041   2168   1028160   82  Linux swap
/dev/hda4        2169   2432   2120580    f  Win95 Ext (LBA)
/dev/hda5        2169   2432   2120548+   7  NT

First, notice that there are unused cylinders between /dev/hda1 and /dev/hda2. This is because of the successful shrinkage of WindowsMe, which is registered as "FAT32 (LBA)". Other things to notice, is that the blocksize is a nice 1024B even though Units is given as a multiple of 512 bytes, thus giving a "+" when the number of 512B blocks is odd, and that the size of a partition in tracks is given as End-Start+1 because the End block is a part of the partition. I want to move the Linux partition and its contents down to fill the gap above WindowsMe. This move overlaps itself. First I deleted all partitions except /dev/hda1, and created 3 Linux partitions:

   Device Boot  Start    End    Blocks   Id  System
/dev/hda1   *       1    446   3582463+   c  FAT32 (LBA)
/dev/hda2         447   1020   4610655   83  Linux
/dev/hda3        1021   1594   4610655   83  Linux
/dev/hda4        1595   2041   3590527+  83  Linux

I have filled the partition gap with /dev/hda2, and split the old linux partition into 2, of which /dev/hda3 is the first, with the same size as /dev/hda2.

What I want to do now, is to first move hda3 to hda2, and the hda4 to hda3, thus moving without overlap by splitting the overlapping move in two.

dd bs=1024 count=4610655 if=/dev/hda3 of=/dev/hda2
dd bs=1024 count=3590528 if=/dev/hda4 of=/dev/hda3

Note that the last "count" is 1 more than the count of /dev/hda4, because of the "+". The time it took was less than an hour for the first, and 40 minutes for the second "dd". It would probably go much faster if the blocksize "bs" had the size of an entire track, but it easier to get right when it is 1KB. (Seems I lost tha last 512B block with this method. I take the chance that this does not matter.)

Then I repartitioned, so that /dev/hda2 contains the moved linux data from the previous /dev/hda2 partition:

   Device Boot  Start    End    Blocks   Id  System
/dev/hda1   *       1    446   3582463+   c  FAT32 (LBA)
/dev/hda2         447   1466   8193150   83  Linux
/dev/hda3        1467   1594   1028160   82  Linux swap
/dev/hda4        1595   2432   6731235    7  HPFS/NTFS

Then I rebooted on the rescue-cd, and mounted the new partition, and LILO'ed it:

chroot /mnt/sysimage

And then I rebooted it normally! Yeeeha!

After that, I installed Windows2000 again, from WindowsMe, and installed the bootloader of Windows2000 to choose between thos 2 M$ oses.

Email me if you want to comment or ask questions: