Go to the first, previous, next, last section, table of contents.


2.5.1 Example: Growing a partition into unused space

Suppose your disk layout looks like this:

(parted) print
Disk geometry for /dev/hda: 0.000-1000.000 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags
1          0.063    500.000  primary   ext2
2        500.000    625.000  primary   linux-swap

There is 375 Mb of free space at the end of the disk (after partition 2). Partition 1 has an ext2 file system, which is the root device. Partition 2 is a swap device.

Suppose you wanted to use the free space at the end of the disk for the file system on partition 1. You could do the following:

  1. These steps will modify both the root file system on partition 1, and the swap device on partition 2. Therefore, you shouldn't be using either partitions. You should probably use a Parted boot disk. See section 1.6 Using a Parted Boot Disk. From the boot disk, run Parted:
    # parted /dev/hda
    
  2. Remove partition 2 (the swap partition). Normally, you wouldn't want to delete a partition with data on it. However, a swap partition doesn't contain data when it isn't "swapped on" (mounted), so you can remove it, and create a replacement swap partition later.
    (parted) rm 2
    
  3. Create the new swap partition at the end of the disk:
    (parted) mkpartfs primary linux-swap 875 999.9
    (parted) print
    Disk geometry for /dev/hda: 0.000-1000.000 megabytes
    Disk label type: msdos
    Minor    Start       End     Type      Filesystem  Flags
    1          0.063    500.000  primary   ext2
    2        875.000   1000.000  primary   linux-swap
    
  4. Grow partition 1, into the adjacent free space:
    (parted) resize 1 0.063 874.9
    
    All done!
    (parted) print
    Disk geometry for /dev/hda: 0.000-1000.000 megabytes
    Disk label type: msdos
    Minor    Start       End     Type      Filesystem  Flags
    1          0.063    874.999  primary   ext2
    2        875.000   1000.000  primary   linux-swap
    


Go to the first, previous, next, last section, table of contents.