網頁

2013年5月11日 星期六

CentOS 6.3 --- Add a New Disk into the existing Volume Group by LVM Command Line Interface

For increasing (or reducing) the size of the file system, we can use its flexible advantage to mange disk resource if the system deploys LVM.
At first, we have to realize whether can use all available space on the Logical Volume.
               If have, we can directly grow the file system from the free space of Volume Group.
               If no, we have to expand the Volume Group by adding the additional disk.

In the following lab, it will show you how to grow file system after add new disk because its operation also includes directly expand the space on LV.

Prerequisite
To check the size of the file system to realize whether the space then needs to be extend by using df –h commandScreenHunter_02                  In the moment, the available space is 41MB and all space use 96% on the filesystem /dev/mapper/drbdVG00-drbdLV0

By using lvdisplay /dev/mapper/drbdVG00-drbdLV0 command, we can find out which Volume Group Name drbdVG00 contain this Logical Volume.ScreenHunter_03
By using vgdisplay drbdVG00 command, we can find out whether the volume group drbdVG00 has available free space to allocate to the logical volume.ScreenHunter_04           In the moment, there is no free physical extents so that need to add new disk as adding physical volume to this volume group.

After add new disk online (# 1), we need to confirm whether the system can probe this new disk by using ls /dev/sd* commandScreenHunter_10or realize what is the status of the partition of the disk by using df –h commandScreenHunter_11ScreenHunter_12
Create Physical Volume

Due to the new disk never is partitioned, we will create the whole disk as a physical volume so that will convert this disk into a physical volume by using pvcreate /dev/sdc command.ScreenHunter_13By using pvscan or pvscan –n command, we can know whether the physical volume is created successfully and are sure this new physical volume never belongs to any volume group now.ScreenHunter_14
Add Physical Volume into the existing Volume GroupAfter the physical volume is created, we need to add it to the existing volume group by using vgextend drbdVG00 /dev/sdc command.ScreenHunter_15In volume group, there is free physical content that is ready to be allocated to logical volume now by using vgdisplay drbdVG00 command.ScreenHunter_16Extend Logical Volume SizeBy using lvextend –L +1020M /dev/drbdVG00/drbdLV0 command, we will extend the size of Logical Volume about 1020 MB.ScreenHunter_17             The “AS-IS” of using lvextend commandScreenHunter_18             The “TO-BE” of using lvextend commandScreenHunter_19
Resize Filesystem
By using resize2fs /dev/drbdVG00/drbdLV0 command, we can resize filesystem so that logical volume will have additional space to be used now.ScreenHunter_20Until now, we can use the additional space that provided by the new disk if the above process completes successfully.

Reference :
(# 1)
In Hyper-V 3.0 manager, we can add the SCSI virtual disk onlineScreenHunter_07
       and choose a location value to avoid the conflict with the existing disk.ScreenHunter_08

2013年5月8日 星期三

CentOS 6.3 --- Configure disk resource by LVM (Logical Volume Management) Command Line Interface

If the Linux Kernel version is 2.4 or above, we can use LVM tool to manage disk resource. When the running system need to add new disk, the general steps is to shutdown the system, add new disk, and restart so that the system will see the new disk. Sometimes, the disk can be added without shutdown the machine when use a hot-swappable system in real or virtual environment.
In the following lab, I have already installed CentOS minimal Guest in Hyper-V 3.0 so that it doesn’t need to reboot after add any SCSI virtual disk.

Partition the New Disk
For adding new disk, I will use LVM and its advantage for managing disk so that first running fdisk –l to realize whether the new disk has been detected.
Before add “one” new 1GB Disk (as /dev/sdb)ScreenHunter_11After add “one” new 1GB Disk (as /dev/sdb)ScreenHunter_12By running ls /dev/sd* command, it also has told us that the new drive /dev/sdb doesn't contain a valid partition table.ScreenHunter_13The first thing is to create a partition by using fdisk /dev/sdb command and the whole disk is defined one partition.ScreenHunter_02So does that the partition /dev/sdb1 will be created but its partition ID is “83”.ScreenHunter_03
The second step is to change the partition’s system id from 83(Linux) to 8e(Linux LVM) by using fdisk /dev/sdb command again.ScreenHunter_04So does that the partition’s system id will be “8e” now.ScreenHunter_02
By running partprobe /dev/sdb1 command, it will inform the OS kernel of partition table change so that the running system doesn’t be rebooted.ScreenHunter_05
Create Physical VolumeFirst, we begin to use pvcreate to initialize a block device or partition /dev/sdb1 to be used as a physical volume.ScreenHunter_09The “AS-IS” of executing the pvcreate commandBy pvscan command, it scans all supported LVM block devices in the system for physical volumes.ScreenHunter_07By pvdisplay command, it displays the properties of each physical volume as size, extents, volume group,etc.ScreenHunter_08The “TO-BE” of executing the pvcreate command
By pvscan command, it finds out a new physical volume /dev/sdb1 as follows:ScreenHunter_10By pvdisplay command, we know this new physical volume /dev/sdb1 never assign to any volume group now.ScreenHunter_11
Create Volume Group
Second, we will make a volume group drbdVG00 on the physical volume /dev/sdb1 by using vgcreate command.ScreenHunter_14
The “AS-IS” of executing the vgcreate command

By vgscan command, it scans all supported disk devices in the system looking for LVM physical volumes and volume groups.ScreenHunter_13By vgdisplay command, it displays volume group properties (such as size, extents, number of physical volumes, etc.) in a fixed form.ScreenHunter_12The “TO-BE” of executing the vgcreate command
By vgscan command, it finds out a new volume group drbdVG00ScreenHunter_15By vgdisplay command, it show the properties of the volume group drbdVG00 and free PE (physical Extents) never is used.ScreenHunter_16ScreenHunter_17By using pvscan command, the physical volume /dev/sdb1 has already assigned to the volume group drbdVG00ScreenHunter_19By using pvdisplay command, we can know what size of the physical volume /dev/sdb1 is assigned to the volume group drbdVG00ScreenHunter_18
Create Logical Volume
Third, we can create a logical volume that name is drbdLV0 and size is the entire partition in volume group drbdVG00 by using lvcreate command with the syntax –n for a name and –l for the size in extents or percentage (or –L for the size in GB/MB)
syntax –l for the size in extentsScreenHunter_34syntax –l for the size in percentageScreenHunter_23syntax –L for the size in GB/MBScreenHunter_35
The “AS-IS” of executing the lvcreate command

By lvscan command, it scans all known volume groups or all supported LVM block devices in the system for defined logical volumesScreenHunter_21By lvdisplay command, it displays logical volume properties (such as size, layout, and mapping) in a fixed format. ScreenHunter_22The “TO-BE” of executing the lvcreate command
By lvscan command, we can find out a new logical volume /dev/drbdVG00/drbdLV0ScreenHunter_24By lvdisplay command, it show the properties of the new logical volume’s /dev/drbdVG00/drbdLV0ScreenHunter_25ScreenHunter_26 By vgdisplay command, we can find out the all extents have already been allocated.ScreenHunter_27ScreenHunter_28
By using ls –l command, we can see the entry /dev/drbdVG00/drbdLV0 will make a symbolic link to /dev/mapper/drbdVG00-drbdLV0ScreenHunter_36
Create filesystem on Logical Volume
Finally, we have to create the filesystem as ext3, ext4 etc for the logical volume because only the file system can be saved anything. In the moment, we will create an ext4 filesystem on this new logical volume by using mkfs.ext4 /dev/drbdVG00/drbdLV0 commandScreenHunter_46Mount filesystemWhen we are ready to mount the logical volume, we have to firstly create a mount point as /var/share0 by using mkdir commandScreenHunter_38next to mount the logical volume by using mount /dev/drbdVG00/drbdLV0 /var/share0 commandScreenHunter_39By using df –h command, we can get total disk usage on all filesystems and know the new logical volume have already been mounted.ScreenHunter_40
Until now, we have completed to set up the first LVM system now. (# 1)
Reference:
(# 1)
If we want to the logical volume is mounted automatically when the system boots, we have to modify /etc/fstab for /var/share0 as follows:ScreenHunter_01       By using mount –a command or reboot the system, we can verify the syntax in the /etc/fstab file is right.ScreenHunter_02

Since 2010 Design by Davidwa
©Copyright Davidwa Inc. All rights reserved.