LVM逻辑卷管理

LVM是逻辑盘卷管理(Logical Volume Manager)的简称,LVM将多个物理分区/磁盘从逻辑上组合成一个更大的整体,从其中划分出不同的逻辑分区,逻辑分区的大小可以根据需求扩大和缩减。相比普通的磁盘存储LVM具有灵活的容量、可伸缩的存储空间的优点。

1,公司想把四块20G的磁盘利用起来,单独使用容量太小,所以要做成LVM逻辑卷。(实际运用中企业硬盘容量不止20G,此处只是拿来举例参考)

[root@localhost ~]# fdisk -l


Disk /dev/sda: 85.8 GB, 85899345920 bytes

255 heads, 63 sectors/track, 10443 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes


  DeviceBoot      Start         End      Blocks  Id  System

/dev/sda1  *           1          13      104391  83  Linux

/dev/sda2             14        2624    20972857+ 83  Linux

/dev/sda3           2625        2885     2096482+ 82  Linux swap / Solaris

/dev/sda4           2886       10443    60709635   5  Extended

/dev/sda5            2886        4102    9775521   83  Linux

/dev/sda6           4103        5319     9775521   7  HPFS/NTFS


Disk/dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table


Disk/dev/sdc: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table


Disk/dev/sdd: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdd doesn't contain a valid partition table


Disk/dev/sde: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sde doesn't contain a valid partition table

2,创建物理卷

[root@localhost~]# pvcreate /dev/{sdb,sdc,sdd,sde}

 Writing physical volume data to disk"/dev/sdb"

 Physical volume "/dev/sdb" successfullycreated

 Writing physical volume data to disk"/dev/sdc"

 Physical volume "/dev/sdc"successfully created

 Writing physical volume data to disk"/dev/sdd"

 Physical volume "/dev/sdd"successfully created

 Writing physical volume data to disk"/dev/sde"

 Physical volume "/dev/sde"successfully created

3,查看是否创建成功

[root@localhost~]# pvscan

 PV /dev/sdb                      lvm2 [20.00 GB]

 PV /dev/sdc                      lvm2 [20.00 GB]

 PV /dev/sdd                      lvm2 [20.00 GB]

 PV /dev/sde                      lvm2 [20.00 GB]

 Total: 4 [80.00 GB] / in use: 0 [0   ] / in no VG: 4 [80.00 GB]……容量为80G

4,创建卷组并指定PE大小为8M,并查看是否创建成功

[root@localhost~]# vgcreate-s 8M vg_data /dev/{sdb,sdc,sdd,sde}

 Volume group "vg_data" successfullycreated

[root@localhost~]# vgdisplay

 --- Volume group ---

 VG Name               vg_data

 System ID            

 Format                lvm2

 Metadata Areas        4

 Metadata Sequence No  1

 VG Access             read/write

 VG Status             resizable

 MAX LV                0

 Cur LV                0

 Open LV               0

 Max PV                0

 Cur PV                4

 Act PV                4

 VG Size               79.97 GB……大小约为80G

 PE Size               8.00 M……PE大小为8M

 Total PE              10236

 Alloc PE / Size       0 / 0  

 Free PE / Size       10236 / 79.97 GB

 VG UUID              nr2ozz-SdLK-GaJc-kwIQ-elbT-HPD1-nWOVCH

5,激活卷组

[root@localhost~]# vgchange �Cay……-ay表示active yes,即激活;如果-an则表示关闭激活

 0 logical volume(s) in volume group"vg_data" now active

6,创建逻辑卷大小为50G,并验证是否创建成功

[root@localhost~]# lvcreate -L 50G -n lv_data vg_data

 Logical volume "lv_data" created

[root@localhost~]# lvdisplay

 --- Logical volume ---

 LV Name                /dev/vg_data/lv_data

 VG Name                vg_data

 LV UUID               nYhCyl-MOB1-lcBc-NVJx-Zv6n-Yf2P-svS4U2

 LV Write Access        read/write

 LV Status              available

 # open                 0

 LV Size                50.00 GB……创建成功,大小50G

 Current LE             6400

 Segments               3

 Allocation             inherit

 Read ahead sectors     auto

 - currently set to     256

 Block device           253:0

7,格式化逻辑卷

[root@localhost~]# mkfs.ext3 /dev/vg_data/lv_data

mke2fs 1.39(29-May-2006)

Filesystemlabel=

OS type: Linux

Block size=4096(log=2)

Fragmentsize=4096 (log=2)

6553600 inodes,13107200 blocks

655360 blocks(5.00%) reserved for the super user

First datablock=0

Maximumfilesystem blocks=4294967296

400 block groups

32768 blocks pergroup, 32768 fragments per group

16384 inodes pergroup

Superblockbackups stored on blocks:

        32768, 98304, 163840, 229376, 294912,819200, 884736, 1605632, 2654208,

        4096000, 7962624, 11239424


Writing inodetables: done                            

Creating journal(32768 blocks): done

Writingsuperblocks and filesystem accounting information: done


This filesystemwill be automatically checked every 24 mounts or

180 days,whichever comes first.  Use tune2fs -c or-i to override.

8,把逻辑卷挂载到/data/LVM

[root@localhost~]# vim /etc/fstab ……设置开机自动挂载


LABEL=/                 /                       ext3    defaults        1 1

LABEL=/boot             /boot                   ext3    defaults        1 2

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

LABEL=SWAP-sda3         swap                   swap   defaults        0 0

/dev/sda6      /NTFS     ntfs-3g   defaults  0 0 UUID="171d2c3c-2b2a-4a59-8a04-6a6a047ce531"/data/LVM ext3 defaults        00  

~                                                                              

~                                                                              

                                                            9,75          All

[root@localhost~]# mount�Ca……加载fstab中的配置

9,查看挂载情况

[root@localhost ~]# df -lT

Filesystem   Type   1K-blocks      Used Available Use% Mounted on

/dev/sda2    ext3    20315844   2715924 16551280  15% /

/dev/sda1    ext3      101086     12200    83667  13% /boot

tmpfs       tmpfs      511920         0   511920   0% /dev/shm

/dev/sda6 fuseblk     9775520     49624  9725896   1% /NTFS

/dev/mapper/vg_data-lv_data

            ext3    51606140    184272 48800428   1% /data/LVM……挂载成功

10,现在逻辑卷需要扩展到99G,再添加一块20G磁盘,扩展逻辑卷步骤如下:

[root@localhost ~]#pvcreate /dev/sdf

……


root@localhost ~]#vgextend vg_data /dev/sdf

Volume group "vg_data" successfully extended

[root@localhost ~]#vgdisplay vg_data

 ---Volume group ---

 VGName               vg_data

System ID            

Format                lvm2

Metadata Areas        5

Metadata Sequence No  3

 VGAccess             read/write

 VGStatus             resizable

 MAXLV                0

 CurLV                1

Open LV               1

 MaxPV                0

 CurPV                5

 ActPV                5

VG Size               99.96 GB

 PESize               8.00 MB

……


[root@localhost ~]# lvextend -L 99G /dev/vg_data/lv_data

Extending logical volume lv_data to 99.00 GB

 Logicalvolume lv_data successfully resized

11,查看容量的扩展情况

[root@localhost ~]# resize2fs/dev/vg_data/lv_data……resize2fs/dev/卷组名/逻辑卷名----更新文件系统,解决df -l查看时lvm扩展后容量没有改变的情况.

resize2fs 1.39 (29-May-2006)

Filesystem at /dev/vg_data/lv_data is mounted on/LVM; on-line resizing required

Performing an on-line resize of /dev/vg_data/lv_datato 25952256 (4k) blocks.

The filesystem on /dev/vg_data/lv_data is now25952256 blocks long.


[root@localhost ~]# df -lT

Filesystem   Type   1K-blocks      Used Available Use% Mounted on

/dev/sda2    ext3    20315844   2718436 16548768  15% /

/dev/sda1    ext3      101086     12200    83667  13% /boot

tmpfs       tmpfs      511920         0   511920   0% /dev/shm

/dev/sda6 fuseblk     9775520     49624  9725896   1% /NTFS

/dev/mapper/vg_data-lv_data

            ext3   102180192    192252 96798116  1% /data/LVM

12,扩展:移除LVM的方法(以以上为例)

(1)umount /data/LVM

(2)pvremove /dev/vg_data/lv_data

(3)vgremove vg_data

(4)lvremove /dev/sd[b-f]


你可能感兴趣的:(lvm,逻辑卷,vgcreat,pvcreat)