Linux 邏輯卷管理相關知識(2)

本文承接上文繼續敘述LVM的相關知識。node

二)VG的建立和管理bash

1)VG的建立app

   VG的建立命令是vgcreate,其後接vg的名字跟要添加到此vg的pv。vg默認的PE爲4MB,能夠用-s參數指定PE大小。dom

[root@server ~]# vgcreate myvg /dev/sd[bc][12] #建立VG,名字爲myvg
  Volume group "myvg" successfully created
[root@server ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  myvg   4   0   0 wz--n- 80.03g 80.03g

   vg建立完成後能夠用vgs或者vgdisplay查看。
ide

2)VG的移除oop

   VG的移除命令式vgremove,
ui

[root@server ~]# vgremove myvg
  Volume group "myvg" successfully removed
[root@server ~]# vgs
  No volume groups found

3)VG的擴容
spa

   VG擴容使用vgextend,  orm

[root@server ~]# vgextend myvg /dev/sdb3
  No physical volume label read from /dev/sdb3
  Physical volume "/dev/sdb3" successfully created
  Volume group "myvg" successfully extended

4)將PV從VG中移除
server

   移除VG中的PV使用vgreduce,

[root@server ~]# vgreduce myvg /dev/sdb3
  Removed "/dev/sdb3" from volume group "myvg"


三)LV的建立和管理

1)LV的建立

   LV建立的命令式lvcreate

[root@server ~]# lvcreate -L 20G -n mylv myvg #-L指定大小,-l能夠指定pe的數量,-n指定lv的名字
  Logical volume "mylv" created
[root@server ~]# lvs
  LV   VG   Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  mylv myvg -wi-a---- 20.00g

2)LV的查看

   查看LV的命令有:lvs,lvdisplay,lvscan

[root@server ~]# lvscan
  ACTIVE            '/dev/myvg/mylv' [20.00 GiB] inherit
[root@server ~]# lvs
  LV   VG   Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  mylv myvg -wi-a---- 20.00g                                          
[root@server ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/myvg/mylv
  LV Name                mylv
  VG Name                myvg
  LV UUID                tEAyGV-0trG-fqIb-SiVl-3KVj-9w9D-ivIXlR
  LV Write Access        read/write
  LV Creation host, time server.domain2.example.com, 2014-01-12 19:32:30 -0800
  LV Status              available
  # open                 0
  LV Size                20.00 GiB
  Current LE             10240
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

3)格式化LV

   格式化邏輯卷的命令跟格式化硬盤的徹底同樣,這裏用mkfs介紹

[root@server ~]# mkfs.ext4 /dev/mapper/myvg-mylv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000
Writing inode tables: done                          
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

4)LV掛載

   使用mount命令

[root@server ~]# mount /dev/mapper/myvg-mylv /root/mylv/
[root@server ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sr0 on /mnt/media type iso9660 (ro,loop=/dev/loop0)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/mapper/myvg-mylv on /root/mylv type ext4 (rw)#已掛載

5)增長或減少LV大小

   增長使用lvextend,

[root@server ~]# lvextend -L +10G /dev/mapper/myvg-mylv
  Extending logical volume mylv to 30.00 GiB
  Logical volume mylv successfully resized
[root@server ~]# resize2fs /dev/mapper/myvg-mylv #使其當即生效
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/myvg-mylv is mounted on /root/mylv; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/mapper/myvg-mylv to 7864320 (4k) blocks.
The filesystem on /dev/mapper/myvg-mylv is now 7864320 blocks long.

   減少使用lvreduce命令。縮減LV有風險,慎用。

[root@server ~]# lvreduce -L -20G /dev/mapper/myvg-mylv
  WARNING: Reducing active and open logical volume to 10.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv? [y/n]: y
  Reducing logical volume mylv to 10.00 GiB
  Logical volume mylv successfully resized

6)LV刪除

   LV刪除使用lvremove命令

[root@server ~]# umount mylv/ #刪除以前先從文件系統卸載
[root@server ~]# lvremove /dev/mapper/myvg-mylv
Do you really want to remove active logical volume mylv? [y/n]: y
  Logical volume "mylv" successfully removed
相關文章
相關標籤/搜索