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)
After add “one” new 1GB Disk (as /dev/sdb)

By running
ls /dev/sd* command, it also has told us that the new drive
/dev/sdb doesn't contain a valid partition table.

The first thing is to create a partition by using
fdisk /dev/sdb command and the whole disk is defined one partition.

So does that the partition
/dev/sdb1 will be created but its partition ID is “
83”.

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.

So does that the partition’s system id will be “
8e” now.

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.
Create Physical VolumeFirst, we begin to use
pvcreate to initialize a block device or partition
/dev/sdb1 to be used as a physical volume.
The “AS-IS” of executing the pvcreate commandBy
pvscan command, it scans all supported LVM block devices in the system for physical volumes.

By
pvdisplay command, it displays the properties of each physical volume as size, extents, volume group,etc.
The “TO-BE” of executing the pvcreate command
By
pvscan command, it finds out a new physical volume
/dev/sdb1 as follows:

By
pvdisplay command, we know this new physical volume
/dev/sdb1 never assign to any volume group now.
Create Volume Group
Second, we will make a volume group
drbdVG00 on the physical volume
/dev/sdb1 by using
vgcreate command.

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.

By
vgdisplay command, it displays volume group properties (such as size, extents, number of physical volumes, etc.) in a fixed form.
The “TO-BE” of executing the vgcreate command
By
vgscan command, it finds out a new volume group
drbdVG00
By
vgdisplay command, it show the properties of the volume group
drbdVG00 and free PE (physical Extents) never is used.


By using
pvscan command, the physical volume
/dev/sdb1 has already assigned to the volume group
drbdVG00
By using
pvdisplay command, we can know what size of the physical volume
/dev/sdb1 is assigned to the volume group
drbdVG00
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 extents

syntax
–l for the size in percentage

syntax
–L for the size in GB/MB

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 volumes

By
lvdisplay command, it displays logical volume properties (such as size, layout, and mapping) in a fixed format.
The “TO-BE” of executing the lvcreate command
By
lvscan command, we can find out a new logical volume
/dev/drbdVG00/drbdLV0
By
lvdisplay command, it show the properties of the new logical volume’s
/dev/drbdVG00/drbdLV0

By
vgdisplay command, we can find out the all extents have already been allocated.


By using
ls –l command, we can see the entry
/dev/drbdVG00/drbdLV0 will make a symbolic link to
/dev/mapper/drbdVG00-drbdLV0
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 command
Mount filesystemWhen we are ready to mount the logical volume, we have to firstly create a mount point as
/var/share0 by using
mkdir command

next to mount the logical volume by using
mount /dev/drbdVG00/drbdLV0 /var/share0 command

By using
df –h command, we can get total disk usage on all filesystems and know the new logical volume have already been mounted.

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:

By using
mount –a command or reboot the system, we can verify the syntax in the
/etc/fstab file is right.
沒有留言:
張貼留言