Partitions on Local Disks
This page explains how hard disks are partitioned and how filesystems are created on them. It also covers the use of Linux RAID and Logical Volume Management (LVM) to combine multiple partitions into one large filesystem.
Introduction to hard disk partitions
All hard disks used by Linux and other operating systems on PC hardware are divided into one or more non-overlapping regions called partitions. Sometimes an entire hard disk will be taken up by one partition, but usually your system will have at least two partitions on the primary disk - one for the root filesystem, and one for virtual memory (also known an swap space). As explained in chapter 5, each partition can be used for either a single filesystem or for virtual memory.
Every partition has a type which identifies the kind of data that it stores. There is a type for Linux filesystems, a type for Linux swap space, a type for Windows filesystems and many more. Almost every kind of operating system that runs on PC hardware has its own partition type for its own filesystems. However, when adding new partitions on your system you will very rarely use any types other than those specifically for Linux.
On PC systems, each hard disk can only contain four primary partitions. Because this is often not enough, it is possible for one of those four to be a special extended partition that can contain an unlimited number of logical partitions. If you make use of an extended partition, there is effectively no limited on the number that your hard disk can contain.
Every hard disk is divided into equal sized cylinders, which represent concentric circles on the surface of the disk. Larger hard disks generally have more cylinders, but due to different drive geometries this is not always the case. Each partition has a starting and ending cylinder, and occupies all the space on the disk between them.
Be very careful when changing or re-formatting any existing partitions on your system. Because they contain filesystem data, deleting or modifying one could wipe out all your files or make your system unbootable. Webmin tries to prevent this, but it is still possible to do a lot of damage with only a few mouse clicks! Normally you should only need to create or edit partitions when adding a new hard disk to your system.
The Partitions on Local Disks module
All disk partition management in Webmin is done using the Partitions on Local Disks module, which can be found under the Hardware category. When you enter the module, a page showing all hard disks and partitions found on your system will be displayed, as shown in Figure 8-1.
All IDE and SCSI disks are shown, along with their manufacturers and model numbers. If your system has configured RAID disks, the RAID devices will be shown instead of the actual underlying hard disks that make them up. However, disks and partitions used for software RAID will be shown, but not the logical or virtual drives that they have been combined into.
For each disk, all partitions on it will be listed showing their type, start and end cylinders and current mount point or other use. If the partition contains a filesystem, the amount of free disk space will be displayed as well. If a partition is being used for software RAID, their raid device that it is part of will be shown. Similarly, if a partitions is part of an LVM volume group the group name will be displayed under the Use column.
Adding and formatting a new partition
If you have just added a new hard disk to your system and want to make use of it under Linux, you must first partition it and then format the partition as the filesystem type of your choice. The steps to follow the do this are:
- In the main page of the Partitions on Local Disks module, locate your new hard disk. It will probably not have any partitions on it, but it may have been set up with one large partition by the manufacturer.
- Assuming no partitions exist yet, click the *Add primary partition* link next to your new hard disk. This will take you to the creation form shown in Figure 8-2 for entering the details of the new partition.
- If the new partition is to take up the entire hard disk, the Extent fields can be left unchanged as they are always automatically filled in to cover all the free space left on the disk. However, if you want to create more than one partition, adjust the extent so that it takes up only part of the disk.
- If this partition is to be for an ext2, ext3, ext4, reiserfs or xfs filesystem, set the Type field to Linux. If it is to be for virtual memory, set the Type to Linux swap. If it is for software RAID, set the Type to Linux raid. If it is for LVM, set the Type to Linux LVM. If you are creating the filesystem for some other operating system to use, set the Type field to whatever is appropriate for that OS.
- Click the Create button to add the partition. Assuming no errors were detected, you will be returned to the list of disks and partitions on the main page of the module, which should now include the new partition.
- If the new partition is to have a Linux filesystem created on it, you must follow the steps in the Creating a new filesystem section below. Virtual memory partitions can be added immediately in the Disk and Network Filesystems module. Partitions for use with RAID can be also be used immediately in the Linux RAID module, but you must have created all the partitions that will make up a RAID device before creating it. Partitions that will be part of an LVM volume group can be added immediately using the Logical Volume Management module.
Creating a new filesystem
Before a newly created partition can be used to store files, it must first have a filesystem created on it. Filesystems can also be created on partitions that have been used before, perhaps by another operating system. However, be very careful when formatting a partition with a new filesystem, as any files that it used to contain will be lost forever.
The steps to follow to create a new filesystem are:
- On the main page of the module, click on the number of the partition that you want to re-format. This will take you to the partition editing form, as shown in Figure 8-3.
- Near the bottom of the page is a button labeled Create Filesystem with a menu of supported filesystem types next to it. See the section on A comparison of filesystem types in Disk and Network Filesystems for information on the pluses and minuses of each type. When you have made a selection, click the button which will take you to a form for selecting options for the new filesystem.
- Depending on the type of filesystem chosen, different creation options are available. For ext2 or ext3 filesystems, the only one that you might want to change is Reserved blocks which determines the amount of disk space reserved for the exclusive use of root user. The default is 5%, which I think is rather wasteful.
- Click the Create Filesystem button to format the partition. A page showing the progress of the new filesystem's creation will be displayed, which can take some time for large hard disks.
- Assuming that the formatting is successful, you can now use the Disk and Network Filesystems module to mount the new filesystem.
Labels are a feature of newer versions of Linux that allow a partition to be identified in the /etc/fstab file by a short name, rather than its IDE or SCSI device file such as /dev/hdb3. Device files can change if you change an IDE drive from one controller to another, change the ID of a SCSI drive, or even add a new SCSI drive with an ID lower than an existing drive. Any of these changes could cause a partition to fail to mount at boot time, possibly making your system un-bootable. However, partitions with labels can be referred to by label name, which does not change even if the device file does.
Some newer Linux distributions use labels by default for filesystems that you create at install time. If you use the Disk and Network Filesystems module on such a system, the Location column for these filesystems will be something like 'Partition labeled /home'.
Only partitions with ext2, ext3 or xfs filesystems on them can be labeled, as the label is stored in the filesystem rather than the partition table. To label an existing filesystem, follow these steps:
- On the main page of the module, click on the number of the partition that you want to label. This will take you to the partition editing form, as shown in Figure 8-3.
- Assuming the partition is not currently in use, you will be able to enter the new label into the Partition label field. It must be at most 16 characters long - for example /home or root.
- After you have entered the label, click the Save button. It will be stored in the filesystem, and the browser will return to the module's main page.
- At this point, the Disk and Network Filesystems module can be used to mount the labeled filesystem by label name.
Deleting or changing a partition
Once a partition has been created, its size or position on the hard disk cannot be changed using Webmin. The only things you can do are change its type, or delete it. However, neither are possible if a filesystem on the partition is listed in the Disk and Network Filesystems module - that is, if it is currently mounted or recorded for mounting at boot time.
Changing the type of a partition will not harm the data on it in any way. However, it may make it unusable by some operating systems or for some purposes. The steps to make a change are:
- On the main page of the module, click on the number of the partition that you want to change. This will take you to the partition editing form.
- As long as the partition is not in use, you will be able to select a new type from the Type field and click the Save button.
- Once the change has been made, the browser will return to the list of disks and partitions.
Deleting a partition should be done only if you are sure that you want to lose all the data on it. However, it is the only way to make some changes to the partition table in Webmin, such as replacing two small partitions with one larger one. If you are sure that you want to go ahead with the deletion, the process is as follows:
- On the main page of the module, click on the number of the partition that you want to delete, which will take you to the partition editing form.
- Click the Delete button, which will only appear if the partition is not in use. This will take you to a page for confirming the deletion.
- If you are really sure you want to go ahead, click the *Delete Now* button. One the job is done, you will be returned to the main page of the module.
Theoretically, it is possible to restore a deleted partition by creating a new one with the exact same size and extents.
Module access control
Surprisingly, it is possible to limit the access that a Webmin user has to certain disks in the Partitions on Local Disks module. This could be useful if your system has a removable drive (like a Zip or Jaz drive) that you want users to be allowed to partition with Webmin, while preventing them from re-formatting the primary hard disk.
Once a user has been granted access to the module, to restrict the disks that he can access, the steps to follow are:
- In the Webmin Users module, click on Partitions on Local Disks next to his username. This will bring up the module access control form.
- Change the Disks this user can partition and format field to Selected, and choose the disks that the user should be allowed to partition and create filesystems on from the list below.
- To stop the user seeing disks on the main page that he cannot manage, change the Can view non-editable disks? option to No.
- Finally, click the Save button to activate the access control restrictions.
Just being able to partition and format a disk is not particularly useful, unless it can be mounted as well. The Disk and Network Filesystems module has no support for access control restrictions, because giving a user the rights to mount a filesystem would open up several security holes. A better solution is to set up an automounter filesystem so that removable devices can be mounted by just entering a special mount-point directory.
Other operating systems
Solaris is the only other operating system that has a module for managing disks and partitions. However, there are several differences between the two:
Every Solaris disk has exactly 8 partitions, some of which may have no extent if they are not being used. Partitions never need to be created or deleted, and there are no extended or logical partitions.
- When editing a Solaris partition, its extents can be changed without needing to delete and re-create it. However, this will almost certainly result in the loss of data on the partition.
- Every partition has a type that indicates what it is used for. The root type is usually for the root directory filesystem, the swap type is for virtual memory, the usr type is for other filesystems and the unassigned type is for empty partitions.
- Each partition has two flags - Mountable and Writable, which indicate whether it can be mounted or written to respectively.
- The only filesystem supported on Solaris partitions is ufs, the native Unix filesystem type.
- Partition labeling is not supported on Solaris.
- When editing the module access control, there is no *Can view non-editable disks?* option.
The RAID and LVM modules explained below are not available on Solaris or any other operating system.