Thursday 13 December 2012

DISK STORAGE MANAGEMENT IN LINUX USING PARTED UTILITY


STANDARD PARTITIONS USING PARTED UTILITY 

The utility parted allows users to:

  1.  View the existing partition table
  2.  Change the size of existing partitions
  3. Add partitions from free space or additional hard drives

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).
A device containing a partition must not be in use if said partition is to be removed or resized. Similarly, when creating a new partition on a device, said device must not be in use. 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 swapoff command.Below some commonly used parted commands.

check minor-num :-   Perform a simple check of the file system.
cp fromto :-               Copy file system from one partition to another; from and to are the minor numbers of     
                                   the partitions.                 
Help:-                       Display list of available commands.
mktable label;-        Create a disk label for the partition table.
mkfs minor-numfile-system-type;-                  Create a file system of type, file-system-type.
mkpart part-typefs-typestart-mbend-mb:-      Make a partition without creating a new file system.
Mkpartfs part-typefs-typestart-mbend-mb:-  Make a partition and create the specified file system.

Print:-      Display the partition table.
Quit:-       Quit parted.
rescuestart-mbend-mb;-    Rescue a lost partition from start-mb to end-mb.
resize minor-numstart-mbend-mb;-    Resize the partition from start-mb to endmb.
rm minor-num:-     Remove the partition.
select device:-       Select a different device to configure.
set minor-numflagstate:-      Set the flag on a partition; state is either on or off.
toggle [NUMBER [FLAG]:-    Toggle the state of FLAG on partition NUMBER.
unit UNIT:-    Set the default unit to UNIT.


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 ST3270912BC (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                                     lvm

The 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 Types are metadata, free, primary, extended, or logical.

Creating a Partition

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/sdais the device on which to create the partition:
  •  parted /dev/sda
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.

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 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
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.

Formating the Partition

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

  • /sbin/mkfs -t ext3 /dev/sda6

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 /work

Creating the Mount Point

As root, create the mount point:
  • mkdir /work

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

Resizing a Partition

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/sdais the device on which to resize the partition:
parted /dev/sda 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
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
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. 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.

LVM Partition Management

The following commands can be found by issuing lvm help at a command prompt.

COMMAND                      :          What command do(Description)?


dumpconfig                           :       Dump the active configuration
formats                                 :        List the available metadata formats
help                                      :        Display the help commands
lvchange                               ;        Change the attributes of logical volume(s)
lvcreate                                 :       Create a logical volume
lvdisplay                               :        Display information about a logical volume
lvextend                                ;       Add space to a logical volume
lvmchange                             :       Due to use of the device mapper,this command has been deprecated
lvmdiskscan                          :       List devices that may be used as physical volumes
lvmsadc                               :        Collect activity data
lvmsar                                   :      Create activity report
lvreduce                              :        Reduce the size of a logical volume
lvremove                             :        Remove logical volume(s) from the system
lvrename                             :        Rename a logical volume
lvresize                                ;        Resize a logical volume
lvs                                       :       Display information about logical volumes
lvscan                                 :        List all logical volumes in all volume groups
pvchange                             :       Change attributes of physical volume(s)
pvcreate                               ;      Initialize physical volume(s) for use by LVM
pvdata                                :        Display the on-disk metadata for physical volume(s)
pvdisplay                          :         Display various attributes of physical volume(s)
pvmove                              :       Move extents from one physical volume to another
pvremove                           :        Remove LVM label(s) from physical volume(s)
pvresize                             :         Resize a physical volume in use by a volume group
 pvs                                     :      Display information about physical volumes
pvscan                              :        List all physical volumes
segtypes                             :       List available segment types
vgcfgbackup                      ;       Backup volume group configuration
vgcfgrestore                       :       Restore volume group configuration
vgchange                            :      Change volume group attributes
vgck                                   :     Check the consistency of a volume group
vgconvert                           :      Change volume group metadata format
vgcreate                            :       Create a volume group
vgdisplay                            :      Display volume group information
vgexport                            ;       Unregister a volume group from the system
vgextend                           :       Add physical volumes to a volume group
vgimport                           :       Register exported volume group with system
vgmerge                           :       Merge volume groups
vgmknodes                       :       Create the special files for volume group devices in /dev/
vgreduce                           :      Remove a physical volume from a volume group
vgremove                          :      Remove a volume group
vgs                                    :     Display information about volume groups
vgscan                             :      Search for all volume groups
vgsplit                               :     Move physical volumes into a new volume group
version                              :     Display software and driver version information


















No comments:

Post a Comment