技术小站

linux LVM管理


LVM的好处?

把物理存储设备的差异隐藏在LVM统一的接口之下。接口统一,管理方式统一,还可以进行动态卷扩展。

1、查看系统是否安装LVM

[root@localhost ~]# rpm -qa|grep lvm

lvm2-2.02.56-8.el5

system-config-lvm-1.1.5-4.el5

2、查看新添加的硬盘

[root@localhost ~]# fdisk -l

 

Disk /dev/sda: 322.1 GB, 322122547200 bytes

255 heads, 63 sectors/track, 39162 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          25      200781   83  Linux

/dev/sda2              26       13079   104856255   83  Linux

/dev/sda3           13080       26133   104856255   83  Linux

/dev/sda4           26134       39162   104655442+   5  Extended

/dev/sda5           26134       34488    67111506   82  Linux swap / Solaris

/dev/sda6           34489       39162    37543873+  83  Linux

 

Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes

255 heads, 63 sectors/track, 133674 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

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

 

Disk /dev/sdc: 1924.1 GB, 1924145348608 bytes

255 heads, 63 sectors/track, 233930 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

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

 

 

 

Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes

Disk /dev/sdc: 1924.1 GB, 1924145348608 bytes

这两个为新添加的硬盘

3、用fdisk分区(不创建分区也可以)

[root@localhost ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous

content won't be recoverable.

 

 

The number of cylinders for this disk is set to 133674.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

 

Command (m for help): n   这里输入n

Command action

   e   extended

   p   primary partition (1-4)

p    这里输入p

Partition number (1-4): 4   这里输入4

First cylinder (1-133674, default 1):    回车

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-133674, default 133674):     回车

Using default value 133674

 

Command (m for help): w     这里输入w保存

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

 

 

两块硬盘都要分区   /dev/sdb    /dev/sdc

4、创建PV ( pvcreate )

[root@localhost ~]# pvcreate /dev/sdb4 /dev/sdc4   --或 pvcreate /dev/sdb /dev/sdc

  Physical volume "/dev/sdb4" successfully created

  Physical volume "/dev/sdc4" successfully created

5、查看PV信息

[root@localhost ~]# pvscan

  PV /dev/sdb4                      lvm2 [1023.99 GB]

  PV /dev/sdc4                      lvm2 [1.75 TB]

  Total: 2 [2.75 TB] / in use: 0 [0   ] / in no VG: 2 [2.75 TB]

6、创建VG

[root@localhost ~]# vgcreate mailvg /dev/sdb4 /dev/sdc4  --或 vgcreate mailvg /dev/sdb /dev/sdc

  Volume group "mailvg" successfully created

 

注:VG的名子是 mailvg  这一步是把  /dev/sdb4  /dev/sdc4是把这两个分区都添加到mailvg这个VG里

7、查看VG

[root@localhost ~]# vgdisplay

  --- Volume group ---

  VG Name               mailvg

  System ID            

  Format                lvm2

  Metadata Areas        2

  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                2

  Act PV                2

  VG Size               2.75 TB

  PE Size               4.00 MB

  Total PE              720892

  Alloc PE / Size       0 / 0  

  Free  PE / Size       720892 / 2.75 TB

  VG UUID               aUVOo4-2b75-1nuR-Ppll-G3AT-Rap8-jANOJ3

 

可以看到 两个分区加到一起一共是 2.75TB

8、创建LV

可以创建多个LV本例把所有容量只创建一个大的LV

[root@localhost ~]# lvcreate -L 2.749T -n mailvg01 mailvg

  Rounding up size to full physical extent 2.75 TB

  Logical volume "mailvg01" created

 

2.749T为这个LV的容量  mailvg01是LV的名子 mailvg是VG的名子

9、扫描 lv 逻辑单元

[root@localhost ~]# lvscan

  ACTIVE            '/dev/mailvg/mailvg01' [2.75 TB] inherit

 

10、查看LV信息

[root@localhost ~]# lvdisplay /dev/mailvg/mailvg01

  --- Logical volume ---

  LV Name                /dev/mailvg/mailvg01

  VG Name                mailvg

  LV UUID                ucGT0x-FX0M-OTWM-6UEu-utpE-kjOD-huCSDr

  LV Write Access        read/write

  LV Status              available

  # open                 0

  LV Size                2.75 TB

  Current LE             720634

  Segments               2

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0

 

11、格式化文件系统

[root@localhost ~]# mkfs -t ext3 -c /dev/mailvg/mailvg01

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

362266624 inodes, 724507648 blocks

36225382 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

22111 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

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

         4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,

         102400000, 214990848, 512000000, 550731776, 644972544

 

Checking for bad blocks (read-only test): done                               

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 33 mounts or

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

[root@localhost ~]#

 

因为容量为2.7TB这个格式化过程会很慢,一直等到出现这些信才格式化完成

12、设置开机自动挂载

创建目录

[root@localhost /]# mkdir /data

然后编辑自动挂载文件

 

[root@localhost /]# vi /etc/fstab

 

LABEL=/                 /                       ext3    defaults        1 1

LABEL=/var              /var                    ext3    defaults        1 2

LABEL=/opt              /opt                    ext3    defaults        1 2

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-sda5         swap                    swap    defaults        0 0

/dev/mailvg/mailvg01    /data                   ext3    defaults        0 0

 

 

用VI编辑器  编辑/etc/fstab文件把下面的内容加到最后面,保存退出后重启系统。

/dev/mailvg/mailvg01    /data                   ext3    defaults        0 0

 

13、查看是否挂载成功

[root@localhost ~]# df -hv

文件系统              容量  已用 可用 已用% 挂载点

/dev/sda3              97G  4.4G   88G   5% /

/dev/sda6              35G  248M   33G   1% /var

/dev/sda2              97G  188M   92G   1% /opt

/dev/sda1             190M   12M  169M   7% /boot

tmpfs                  16G     0   16G   0% /dev/shm

/dev/mapper/mailvg-mailvg01

                      2.7T  202M  2.6T   1% /data

 

最下面的就是 已挂载成功

14、常见 LVM 命令

 功能

PV

VG

LV

 搜索

pvscan

vgscan

lvscan

 建立

pvcreate

vgcreate

lvcreate

 列出

pvdisplay

vgdisplay

lvdisplay

 增加


vgextend

lvextend

 减少


vgreduce

lvreduce

 删除


vgremove

lvremove

15、创建PV,扩容VG,LV

a、创建新的PV


pvcreate /dev/sdd

b、查看原VG


vgdisplay #查看当前已经存在的VG信息,以存在VG:vg为例

c、扩展原VG


vgextend vg /dev/sdd    #扩展VolGroup00

d、查看原LV


lvdisplay #查看已经存在的LV信息,以存在LV:vg01为例

e、扩展原LV


[root@clent ~]# lvextend -L +10G /dev/vg/vg01

  /dev/cdrom: open failed: 只读文件系统

  Rounding up size to full physical extent 10 GB

  Extending logical volume vg01 to 59.98 GB

  Logical volume vg01 successfully resized

f、对扩展的LV执行该重设大小


 [root@clent ~]# resize2fs /dev/vg/vg01    # 执行该重设大小,对于当前正在使用的vg01有效

resize2fs 1.39 (29-May-2006)

Filesystem at /dev/vg/vg01 is mounted on /aaa; on-line resizing required

Performing an on-line resize of /dev/vg/vg01 to 15724544 (4k) blocks.

The filesystem on /dev/vg/vg01 is now 15724544 blocks long.

g、查看已经扩容LV所挂载的目录


df –h #查看挂载情况,已经扩容

原创文章请注明转载自技术小站本文地址:http://www.i5i6.net/post/6.html,标题:linux LVM管理

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

【我来说两句】
分享到:

精彩推荐:

相关文章:

CentOS 7 Linux samba 文件共享  (2022-11-5 19:31:25)

Centos 7 下 pure-ftpd搭建ftp服务器  (2022-5-9 9:56:0)

CentOS Linux系统通过串口console口连接配置网络设备  (2022-2-15 8:5:52)

CentOS 7 单用户修改root密码  (2021-5-25 10:37:24)

redhat 6.5 安装oracle 11gR2 完全手册 图文教程  (2017-9-11 15:20:9)

联想ThinkServer服务器安装CentOS7 Redhat7系统 驱动R110i RAID卡  (2017-4-12 17:27:17)

Linux 下 iSCSI存储开机自动挂载  (2017-3-27 13:42:36)

Linux xfs文件系统 格式化超过16T分区  (2016-10-30 19:46:44)

centos7 rhel7安装配置vnc server  (2016-4-19 8:40:22)

CentOS 7 and RedHat 7 时间同步即chrony服务配置  (2016-4-16 16:58:7)

评论 0