Hack 56 Resize Linux Partitions

 < Day Day Up > 

figs/moderate.gif figs/hack56.gif

Use utilities, such as qtparted and parted, to resize ext2, ext3, linux-swap, ReiserFS, and XFS partitions .

Despite even the best planning, files sometimes fill up a partition. In the case of a drive with multiple partitions, you might end up moving one of the partitions to a second drive, back up the first drive, increase the size of the first partition, and restore. Of course, to back up and restore, you must have a spare drive large enough to store your important files, which may not always be the case. If you have a Knoppix CD handy, you can quickly and easily resize partitions without having to back up and restore.

While resizing partitions does not require a backup and restore, resizing partitions is always a potentially dangerous activity that could result in data loss. Back up any important data on a partition, if possible, before you attempt to resize it.

Use the QTParted utility to resize partitions easily. This graphical tool lets you add, delete, move, and resize partitions with many filesystems, including ext2, ext3, ReiserFS, XFS, FAT, FAT32, and NTFS. To start QTParted , click K Menu System QTParted. The QTParted window that appears has two main sections: a left panel, which contains all the disks on the system, and a right panel, which displays partitions from the disk that you have selected on the left.

First, select the disk that has the partitions to be resized from the left panel. QTParted scans all of the partitions on that drive and displays them graphically along the top of the right panel. Below the graphical display is a table that lists all the drive's partitions with information, such as the partition's filesystem type, size, and used space. If you need to delete a different partition to make room to resize this partition, you must first delete the partition. To delete a partition, right-click on the partition in the right panel (either on the graphical representation or in the table) and choose the Delete option. The partition is not actually deleted until you commit your changes by clicking File Commit.

To resize a partition, right-click on the partition you want to resize and select Resize. The window that appears allows you to drag the corners of the partition to increase its size, or you can enter the new size manually in a lower text box (see Figure 6-1). Once the partition is resized to your liking, click OK and then commit your changes. Once you commit your changes, the filesystem is officially resized. You might want to reboot your machine to make sure that the changes to the partition table have been applied universally .

Figure 6-1. QTParted resize window

6.6.1 Resize Without X

QTParted is an easy and useful program, but what if you don't have access to X? Parted is the command-line backend for QTParted . Start parted from a terminal by running:

 knoppix@ttyp0[knoppix]$  sudo parted  /dev/hda   GNU Parted 1.6.9 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This program is free software, covered by the GNU General Public License. This program is distributed in the hope that it will be useful, but  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License  for more details. Using /dev/hda Information: The operating system thinks the geometry on /dev/hda is 4865/255/63.  Therefore, cylinder 1024 ends at 8032.499M. (parted) 

Replace /dev/hda with the drive containing partitions you wish to resize. To see a full list of parted commands and their syntax, type:

 (parted)  help  

If you want help on a specific command, type:

 (parted)  help  command   

To list your drives partition table, type:

 (parted)  print  Disk geometry for /dev/hda: 0.000-38166.679 megabytes Disk label type: msdos Minor    Start       End     Type      Filesystem  Flags 1          0.031  38162.219  primary   fat32       boot, lba (parted) 

The partition table that parted outputs shows you the minor number, the start, the end, the partition type, the filesystem, and any flags the partition has. Reference this information as you use the resize command.

Once you have found the partition you want to resize, note its minor number, where it starts, and then where you want it to end. Parted displays the start and end values in megabytes, so if you want to grow a partition by 500 MB, add 500 to the end value. If you want to shrink the partition by 500 MB, simply subtract 500 from the end value. Once you are ready to resize, type:

 (parted)  resize  1 0.031 2000.000   

where 1 is the minor number for your partition, 0.031 is the starting point in megabytes, and 2000.000 is the ending point in megabytes. Of course, replace these values with the actual values of your partition. Once you are finished, exit by typing:

 (parted)  quit  

There are many other filesystem-specific tools on Knoppix that can resize partitions, such as resize2fs , resize_reiserfs , and xfs_growfs , but QTParted and parted take much of the work and risk out of resizing your partitions, and, if possible, I recommend trying these utilities before using filesystem-specific utilities.

 < Day Day Up > 

Knoppix Hacks. 100 Tips and Tricks
Knoppix Hacks. 100 Tips and Tricks
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net