parted Utility

 

 

parted Utility

 

 


 

Overview

To view the existing partition table, change the size of the partitions, remove partitions, or add partitions from free space or additional hard drives use the parted utility.

To determine if you have a journaled file system, run:

cat /etc/fstab

You can also run dmesg:

[root@mill]# dmesg | grep EXT
EXT3-fs: INFO: recovery required on readonly filesystem.
EXT3-fs: write access will be enabled during recovery.
EXT3-fs: recovery complete.
EXT3-fs: mounted filesystem with ordered data mode.
EXT3 FS 2.4-0.9.8, 25 Aug 2001 on sd(8,5), internal journal
EXT3 FS 2.4-0.9.8, 25 Aug 2001 on sd(8,2), internal journal
EXT3-fs: mounted filesystem with ordered data mode.
EXT3 FS 2.4-0.9.8, 25 Aug 2001 on sd(8,8), internal journal
EXT3-fs: mounted filesystem with ordered data mode.
EXT3 FS 2.4-0.9.8, 25 Aug 2001 on sd(8,7), internal journal
EXT3-fs: mounted filesystem with ordered data mode.
EXT3 FS 2.4-0.9.8, 25 Aug 2001 on sd(8,3), internal journal
EXT3-fs: mounted filesystem with ordered data mode.
EXT3 FS 2.4-0.9.8, 25 Aug 2001 on sd(8,9), internal journal
EXT3-fs: mounted filesystem with ordered data mode.

To start parted, at a shell prompt, as user "root", run...

parted /dev/hdb
...where /dev/hdb is the device name for the drive you want to configure. You will see a prompt. Type help to view a list of available commands.

If you want to create, remove, or resize a partition, the device can not be in use. Partitions can not be mounted and swap space must be disabled. Unmount partitions with the umount command and turn off all the swap space on the hard drive with the swapoff command.

Another way to achieve this is to boot the system in rescue mode. When prompted, select Skip.

After starting parted, type the following command to view the partition table:

print

A table similar to the following will appear:

Disk geometry for /dev/hda: 0.000-9765.492 megabytes

Disk label type: msdos

Minor    Start       End     Type      Filesystem  Flags
1          0.031    101.975  primary   ext3        boot
2        101.975    611.850  primary   linux-swap  
3        611.851    760.891  primary   ext3        
4        760.891   9758.232  extended              lba
5        760.922   9758.232  logical   ext3        

The first line displays the size of the disk. The second line displays the disk label type. The remaining output shows the partition table.

The Minor number is the partition number, where, for example, the partition with minor number 1 corresponds to /dev/hda1.

The Start and End values are in megabytes.

The Type is one of primary, extended, or logical.

The Filesystem is the file system type, which can be one of:

ext2, ext3, FAT, hfs, jfs, linux-swap, ntfs, reiserfs, hp-ufs, sun-ufs, or xfs

The Flags column lists the flags set for the partition. Available flags are boot, root, swap, hidden, raid, lvm, or lba.

To select a different device without having to restart parted, use the select command followed by the device name such as /dev/hdb. Then, you can view its partition table or configure it.

 


 

Create a Partition

  1. Do not attempt to create a partition on a device that is in use. Before creating a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device).

  2. Start parted, where /dev/hda is the device on which to create the partition:

    parted /dev/hda

  3. View the current partition table to determine if there is enough free space:

    print

    If there is not enough free space, you can resize an existing partition.

    From the partition table, determine the start and end points of the new partition and what partition type it should be. You can only have four primary partitions (with no extended partition) on a device. If you need more than four partitions, you can have three primary partitions, one extended partition, and multiple logical partitions within the extended. For an overview of disk partitions, refer to the appendix An Introduction to Disk Partitions in the Red Hat Linux Installation Guide.

    For example, to create a primary partition with an ext3 file system from 1024 megabytes until 2048 megabytes on a hard drive type the following command:

    mkpart primary ext3 1024 2048

  4. If you use the mkpartfs command instead, the file system will be created after the partition is created. However, parted does not support creating an ext3 file system. Thus, if you wish to create an ext3 file system, use mkpart and create the file system with the mkfs command as described later. mkpartfs works for file system type linux-swap.

    The changes start taking place as soon as you press [Enter], so review the command before executing to it.

    After creating the partition, use the print command to confirm that it is in the partition table with the correct partition type, file system type, and size. Also remember the minor number of the new partition so that you can label it. You should also view the output of...

    cat /proc/partitions

    ...to make sure the kernel recognizes the new partition.

  5. The partition still does not have a file system. Create the file system:

    /sbin/mkfs -t ext3 /dev/hdb3

    Formatting the partition will permanently destroy any data that currently exists on the partition.

  6. Next, give the partition a label. For example, if the new partition is /dev/hda3 and you want to label it /work:

    e2label /dev/hda3 /work

    By default, the Red Hat Linux installation program uses the mount point of the partition as the label to make sure the label is unique. You can use any label you want.

  7. As root, create the mount point:

    mkdir /work

  8. Add to /etc/fstab"

    As root, edit the /etc/fstab file to include the new partition. The new line should look similar to the following:

     LABEL=/work           /work                 ext3    defaults        1 2
    

    The first column should contain LABEL= followed by the label you gave the partition. The second column should contain the mount point for the new partition, and the next column should be the file system type (for example, ext3 or swap). If you need more information about the format, read the man page with the command man fstab.

    If the fourth column is the word defaults, the partition will be mounted at boot time.

  9. To mount the partition without rebooting, as root:

    mount /work

 


 

Remove a Partition

  1. Do not attempt to remove a partition on a device that is in use.

  2. Before removing a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device).

  3. Start parted, where /dev/ hda is the device on which to remove the partition:

    parted /dev/hda

  4. View the current partition table to determine the minor number of the partition to remove:

    print

  5. Remove the partition with the command rm. For example, to remove the partition with minor number 3:

    rm 3

    The changes start taking place as soon as you press [Enter], so review the command before committing to it.

  6. After removing the partition, use the print command to confirm that it is removed from the partition table. You should also view the output of

    cat /proc/partitions
    to make sure the kernel knows the partition is removed.

  7. The last step is to remove it from the /etc/fstab file. Find the line that declares the removed partition, and remove it from the file.

 


 

Resize a Partition

  1. Do not attempt to resize a partition on a device that is in use.

  2. Before resizing a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device).

  3. Start parted, where /dev/ hda is the device on which to resize the partition:

    parted /dev/hda

  4. View the current partition table to determine the minor number of the partition to resize as well as the start and end points for the partition:

    print

    The used space of the partition to resize must not be larger than the new size.

  5. To resize the partition, use the resize command followed by the minor number for the partition, the starting place in megabytes, and the end place in megabytes. For example:

    resize 3 1024 2048

  6. After resizing the partition, use the print command to confirm that the partition has been resized correctly, is the correct partition type, and is the correct file system type.

  7. After rebooting the system into normal mode, use the command df to make sure the partition was mounted and is recognized with the new size.


  Home