You've installed Linux on a computer and everything's coming up roses -- X is working, your servers are running, and so on. Suddenly, you run into a problem! When writing a new file, you receive an ominous error message: "No space left on device." Your disk -- or at least one of your partitions -- is full.
You’ve installed Linux on a computer and everything’s coming up roses — X is working, your servers are running, and so on. Suddenly, you run into a problem! When writing a new file, you receive an ominous error message: “No space left on device.” Your disk — or at least one of your partitions — is full.
One way to deal with this problem, of course, is to delete unnecessary files. Depending upon the partition that’s affected, you might search for and delete core files, remove unused but large packages, delete temporary files, delete large but unnecessary user files, or otherwise remove data you don’t need. This approach can be effective, but sometimes it’s not enough. Another approach is to add disk space by purchasing and installing a new hard disk. And sometimes, what’s needed is a wholesale restructuring of the layout of your disk. Perhaps you gave too much space to /home and not enough space to /usr. Perhaps you’ve created too many partitions and need to consolidate them. Whatever the case, you need to deal with the problem by using tools that can repartition your hard disk.
Unfortunately, the simplest disk partitioning tools tend to be destructive: to create a new partition layout you must destroy the old one, including any data on the disk. The standard Linux fdisk utility, like the DOS/Windows tool of the same name, is an example of such a program. Another class of tools is less destructive, though. These tools are known generically as dynamic partition resizers. They enable you to change partition sizes without destroying the data they contain.
One of the earliest and simplest of these tools is the First Nondestructive Interactive Partition Sizer (FIPS), which can split a single File Allocation Table (FAT) primary partition in two. FIPS comes with many Linux distrubitions, but because it works only on primary FAT partitions, it’s not very helpful if you need to resize a Linux partition.
A frequently-cited example of a flexible partition resizer is the commercial PartitionMagic from PowerQuest (http://www.powerquest.com). This tool provides an easy-to-use GUI and can resize FAT, NTFS, ext2fs, ext3fs, and Linux swap partitions. (Older versions could also handle OS/2 HPFS partitions.) PartitionMagic, though, is a commercial program that costs more than a new mid-sized hard disk, so buying it may not be worthwhile for a single-use operation.
But there is a program that fills the middle ground: GNU Parted (available from http://www.gnu.org/software/parted/parted.html). This program is an open source tool that aims to do more-or-less what PartitionMagic does. GNU Parted features a simpler, text-based user interface, though, and it’s not nearly as polished. Nonetheless, GNU Parted is extremely useful in helping to manage partitions as your needs for disk storage space change.
Before proceeding with any partition resizing tool, be aware that dynamic partition resizing is inherently dangerous! A power outage, bug, or other problem during dynamic partition resizing can wreak havoc with your partitions — possibly even with partitions you’re not modifying. You should always back up your data before using one of these tools!
Principles of Partition Management
The most common partitioning schemes on x86 computers today use three types of partitions:
Primary partitions. The original x86 partitioning scheme supports just four partitions, which today are known by the name primary partition. DOS and Windows must boot from a primary partition, but Linux doesn’t suffer from this limit. Most disks have at least one primary partition.
Extended partitions. In order to extend the original x86 partitioning system to support more than four partitions, one primary partition can be set aside as an extended partition. This partition serves as a placeholder for additional logical partitions.
Logical partitions. A disk can support an arbitrary number of logical partitions, which in some sense reside within a single extended partition. If you use more than one or two Linux partitions, chances are most of them are logical partitions.
Other platforms support different partitioning schemes, which usually don’t have the primary/extended/logical distinction. GNU Parted supports the x86 partitioning scheme as well as several others, such as those used by Macintoshes and the BSD partitioning scheme.
No matter what the partition type, a partition is defined by its start and end point on the disk. On x86 systems, these points are usually specified in terms of the cylinder, head, and sector of the endpoints — that is, in terms of the CHS geometry. Many partitioning tools, including GNU Parted, try to present partition data in terms that are more meaningful to humans, such as the partition size in megabytes or gigabytes. Other programs, such as Linux’s fdisk, use cylinder numbers for partition management.
To resize a partition, GNU Parted must resize not just the partition (that part’s easy), but also the data structures on the partition — that is, the filesystem on the partition. Unfortunately, resizing a filesystem is a tricky proposition. If a filesystem is shrunk, data stored beyond the new end point of the partition must be moved. If a filesystem is expanded, fixed data structures may need to be expanded, necessitating the movement of files or other data structures. Overall, expanding a filesystem is usually easier than shrinking one. It’s also usually easier to change the filesystem’s end point than to change its starting point. In fact, GNU Parted supports resizing ext2fs, ext3fs, and ReiserFS partitions only by changing the end point.
When you use GNU Parted, you should remember that you may need to change your partition entries in /etc/fstab. Although you may be able to use GNU Parted to change non-vital filesystems from your main Linux system, changes to critical partitions such as the root filesystem may necessitate booting an emergency Linux system.
Linux Magazine /
July 2003 / GURU GUIDANCE
Partition Resizing with GNU Parted