網頁

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.