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


2.5.2 Example: Resizing an ext2 partition on a crowded disk.

Suppose your disk layout looks like this:

(parted) print
Disk geometry for /dev/hda: 0-8063.5 megabytes
Disk label type: msdos
Minor   Start     End    Type            Filesystem     Flags
1          0.0     23.5  primary         ext2           boot
2         23.5   8056.0  extended
5         23.6   3545.6  logical         ext2
6       3545.6   7067.7  logical         ext2
7       7067.7   7326.5  logical         ext2
8       7326.5   7585.4  logical         ext2
9       7585.4   7844.2  logical         linux-swap

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda8             251M   31M  207M  13% /
/dev/hda1              23M  2.4M   19M  11% /boot
/dev/hda5             3.4G  577M  2.7G  18% /usr
/dev/hda6             3.4G  289M  2.9G   9% /home
/dev/hda7             251M   12M  226M   5% /var

Suppose you wanted to increase the `/var' partition (`/dev/hda7') to 1GB, using some space from `/home' (`/dev/hda6').

To resize a partition with Parted, you use the resize command:

(parted) resize partition_number new start new end

new start must be the same as the old start for ext2 partitions (unfortunately). So this process is going to be rather complicated. It is possible, though. (2)

  1. Shrink the `/home' partition (`/dev/hda6') by 500MB:
    # parted /dev/hda
    (parted) resize 6 3545.6 6200
    
  2. Make a new partition in its place. This is where `/var' will be, eventually. This new partition will be numbered 10.
    (parted) mkpartfs logical ext2 6200 7067.7
    
  3. Copy the old `/var' partition (`/dev/hda7') to the new one (`/dev/hda10').
    (parted) cp 7 10
    
  4. Delete the old `/var'.
    (parted) rm 7
    
    At this point: all logical partitions greater than 7 just changed number. So 8, 9 and 10 become 7, 8 and 9 respectively. This renumbering won't take place while any partitions are mounted on that disk (this will happen when you reboot). That's what that warning message is talking about. So you should never attempt to mount a file system touched by Parted (resized or created by Parted), before rebooting, if you get this message.
  5. Resize the new `/var' partition (now numbered 9), adding the space from the old `/var' partition:
    (parted) resize 9 6200 7326.5
    (parted) quit
    Warning: The kernel was unable to re-read the partition table on
    /dev/hda (Device or resource busy).  This means Linux knows nothing
    about any modifications you made.  You should reboot your computer
    before doing anything with /dev/hda.
    
  6. Since the partition numbers have changed, `/etc/fstab' must be updated. This can be done before rebooting, because the root device wasn't touched by Parted. (If you want to use Parted to do something to the root device, you need to use the boot disk). If the old `/etc/fstab' looks like this:
    /dev/hda8      /            ext2    defaults        1 1
    /dev/hda1      /boot        ext2    defaults        1 2
    /dev/hda6      /home        ext2    grpquota,usrquota  0  2
    /dev/cdrom     /mnt/cdrom   iso9660 noauto,owner,ro 0 0
    /dev/hda5      /usr         ext2    defaults        1 2
    /dev/hda7      /var         ext2    grpquota,usrquota  0  2
    /dev/fd0       /mnt/floppy  auto    noauto,owner    0 0
    none           /proc        proc    defaults        0 0
    none           /dev/pts     devpts  gid=5,mode=620  0 0
    /dev/hda9      swap         swap    defaults        0 0
    
    A few lines need to be changed: The new `/etc/fstab' looks like this:
    /dev/hda7      /            ext2    defaults        1 1
    /dev/hda1      /boot        ext2    defaults        1 2
    /dev/hda6      /home        ext2    grpquota,usrquota  0  2
    /dev/cdrom     /mnt/cdrom   iso9660 noauto,owner,ro 0 0
    /dev/hda5      /usr         ext2    defaults        1 2
    /dev/hda9      /var         ext2    grpquota,usrquota  0  2
    /dev/fd0       /mnt/floppy  auto    noauto,owner    0 0
    none           /proc        proc    defaults        0 0
    none           /dev/pts     devpts  gid=5,mode=620  0 0
    /dev/hda8      swap         swap    defaults        0 0
    
  7. Reboot. That's it!


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