Systems and Network Management

Repartitioning your hard disk without deleting Windows with the Mighty parted

1 Aim

Often when you buy a computer, Windows XP is installed in one partition, with most of that partition being empty. It’s a shame to waste that space without installing Linux there.

I am asking all of you to install Linux onto your computers at home; if you don’t, you won’t be able to get enough practice to do well in the laboratory workshops. Those who failed this subject all have one thing in common: they never installed Linux at home.

This guide tells you how to repartition your hard disk without losing any of your Windows that you paid for as part of the price of buying the computer. This guide is a guide only, and does not replace the documentation, which you will find at http://www.gnu.org/software/parted/; you get a summary with man parted.

2 Background

There are a number of commercial programs for non-destructive disk partitioning, the most famous being Partition Magic. However, there is at least one well-tested alternative that we look at here, called parted.

There is a section from The Official Red Hat Linux Customization Guide at http://nicku.org/doc/rhl-cg-en-8.0/ch-disk-storage.html which describes how to use parted.

   You can read the user manual for parted at http://www.gnu.org/software/parted/.

2.1 Warning

Note that I have done this a number of times, always successfully. However, I make no guarantee that it will work for you. If your data is important, back it up first.

Note that this will not resize any ntfs partitions, since Microsoft keep the format of this filesystem highly secret; parted can resize fat 16 and fat 32 partitions, and can move the end boundary of ext2 or ext3 partitions. See the documentation. This document only describes reducing a fat partition. If you need to resize an ntfs partition, you will need to buy some proprietary software, such as Partition Magic.

3 Procedure

3.1 An overview of the procedure

1. Boot Windows, and run the disk defragmenter program to move all files to the beginning of your partition.

Repartitioning your hard disk without deleting Windows with the Mighty parted Systems and Network Management

2

This process is very slow, and the Microsoft tools provide no fast data movement option.

2. Note how much space your Windows installation requires, and make a decision about how much space to allocate to Linux (as a rough guide, I have 280 × 2^{20} bytes of disk space, and allocate 280 × 2^{20} bytes to Linux, and 0 × 2^{20} bytes to Windows :-)

3. boot your computer using the first Red Hat 8.0 installation cdrom as a rescue boot disk

4. run parted; it will give you an interactive prompt.

5. display your partition table by typing print.

6. shrink the Windows partition to the size you decided on at step 2 with the resize command

7. create a Linux partition and a swap partition with the mkpart command

8. quit the parted program with the quit command

9. reboot your machine from the cdrom and do an installation into the two partitions you just created.

3.2 The Details

I will not go into details on running the defragmenter. Note that the Parted manual says,

Parted will always warn you before doing something that is potentially dangerous, unless it’s something that’s obviosuly dangerous (i.e. rm, mklabel, mkfs). For example, if you attempt to shrink a partition “too much” (i.e. by more than the free space available), Parted will automatically resize to the minimum it can without losing data.