Monday, January 21, 2013

PARTITION Red_Hat_Enterprise_Linux


https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/5/html/Deployment_Guide/ch-disk-storage.html#s2-disk-storage-parted-remove-part


.1. Standard Partitions using parted

The utility parted allows users to:View the existing partition tableChange the size of existing partitionsAdd partitions from free space or additional hard drivesIf you want to view the system's disk space usage or monitor the disk space usage, refer to Section 41.3, "File Systems".By default, the parted package is included when installing Red Hat Enterprise Linux. To start parted, log in as root and type the command parted /dev/sda at a shell prompt (where /dev/sda is the device name for the drive you want to configure).If you want to remove or resize a partition, the device on which that partition resides must not be in use. Creating a new partition on a device which is in use—while possible—is not recommended.For a device to not be in use, none of the partitions on the device can be mounted, and any swap space on the device must not be enabled.As well, the partition table should not be modified while it is in use because the kernel may not properly recognize the changes. If the partition table does not match the actual state of the mounted partitions, information could be written to the wrong partition, resulting in lost and overwritten data.The easiest way to achieve this is to boot your system in rescue mode. When prompted to mount the file system, select Skip.Alternately, if the drive does not contain any partitions in use (system processes that use or lock the file system from being unmounted), you can unmount them with the umount command and turn off all the swap space on the hard drive with the swapoffcommand.Table 8.1, "parted  commands" contains a list of commonly used parted commands. The sections that follow explain some of these commands and arguments in more detail.

Table 8.1. parted  commands

CommandDescriptioncheck minor-numPerform a simple check of the file systemcp from toCopy file system from one partition to another; from and to are the minor numbers of the partitionshelpDisplay list of available commandsmklabel labelCreate a disk label for the partition tablemkfs minor-num file-system-typeCreate a file system of type file-system-typemkpart part-type fs-type start-mb end-mbMake a partition without creating a new file systemmkpartfs part-type fs-type start-mb end-mbMake a partition and create the specified file systemmove minor-num start-mb end-mbMove the partitionname minor-num nameName the partition for Mac and PC98 disklabels onlyprintDisplay the partition tablequitQuit partedrescue start-mb end-mbRescue a lost partition from start-mb to end-mbresize minor-num start-mb end-mbResize the partition from start-mb to end-mbrm minor-numRemove the partitionselect deviceSelect a different device to configureset minor-num flag stateSet the flag on a partition; state is either on or offtoggle [NUMBER [FLAG]Toggle the state of FLAG on partition NUMBERunit UNITSet the default unit to UNIT

8.1.1. Viewing the Partition Table

After starting parted, use the command print to view the partition table. A table similar to the following appears:Model: ATA ST3160812AS (scsi) Disk /dev/sda: 160GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 32.3kB 107MB 107MB primary ext3 boot 2 107MB 105GB 105GB primary ext3 3 105GB 107GB 2147MB primary linux-swap 4 107GB 160GB 52.9GB extended root 5 107GB 133GB 26.2GB logical ext3 6 133GB 133GB 107MB logical ext3 7 133GB 160GB 26.6GB logical lvmThe first line contains the disk type, manufacturer, model number and interface, and the second line displays the disk label type. The remaining output below the fourth line shows the partition table.In the partition table, the Minor number is the partition number. For example, the partition with minor number 1 corresponds to /dev/sda1. The Start and End values are in megabytes. Valid Type are metadata, free, primary, extended, or logical. The Filesystem is the file system type, which can be any of the following:ext2ext3fat16fat32hfsjfslinux-swapntfsreiserfshp-ufssun-ufsxfsIf a Filesystem of a device shows no value, this means that its file system type is unknown.The Flags column lists the flags set for the partition. Available flags are boot, root, swap, hidden, raid, lvm, or lba.

Tip

To select a different device without having to restart parted, use the select command followed by the device name (for example, /dev/sda). Doing so allows you to view or configure the partition table of a device.

8.1.2. Creating a Partition

Warning

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).Start parted, where /dev/sda is the device on which to create the partition:parted /dev/sdaView the current partition table to determine if there is enough free space:printIf there is not enough free space, you can resize an existing partition. Refer to Section 8.1.4, "Resizing a Partition" for details.

8.1.2.1. Making the 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 Enterprise 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

Tip

If you use the mkpartfs command instead, the file system is 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 mkfscommand as described later.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 ofcat /proc/partitionsto make sure the kernel recognizes the new partition.

8.1.2.2. Formatting the Partition

The partition still does not have a file system. Create the file system:mkfs -t ext3 /dev/sda6

Warning

Formatting the partition permanently destroys any data that currently exists on the partition.

8.1.2.3. Labeling the Partition

Next, give the partition a label. For example, if the new partition is /dev/sda6 and you want to label it /work:e2label /dev/sda6 /workBy default, the 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.

8.1.2.4. Creating the Mount Point

As root, create the mount point:mkdir /work

8.1.2.5. 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 2The 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 is mounted at boot time. To mount the partition without rebooting, as root, type the command:mount /work

8.1.3. Removing a Partition

Warning

Do not attempt to remove a partition on a device that is in use.Before removing a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device).Start parted, where /dev/sda is the device on which to remove the partition:parted /dev/sdaView the current partition table to determine the minor number of the partition to remove:printRemove the partition with the command rm. For example, to remove the partition with minor number 3:rm 3The changes start taking place as soon as you press Enter, so review the command before committing to it.After removing the partition, use the print command to confirm that it is removed from the partition table. You should also view the output ofcat /proc/partitionsto make sure the kernel knows the partition is removed.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.

8.1.4. Resizing a Partition

Warning

Do not attempt to resize a partition on a device that is in use.Before resizing a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device).Start parted, where /dev/sda is the device on which to resize the partition:parted /dev/sdaView 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:printTo 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

Warning

A partition cannot be made larger than the space available on the deviceAfter 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.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.

No comments:

Post a Comment