您现在的位置是:首页 >技术交流 ><Linux>《Linux 扩容 LVM操作大全》网站首页技术交流

<Linux>《Linux 扩容 LVM操作大全》

Ealser 2024-07-23 06:01:02
简介<Linux>《Linux 扩容 LVM操作大全》

1 谨记

1、对有数据的盘操作时,一定要慎重。
2、慎重起见,扩容前能对数据进行备份或对磁盘进行克隆最好。
3、不要怕大神在身边护佑显得你能力弱,要知道关键时候能救命。

2 创建目录

2.1 fdisk -l 查看磁盘情况

命令含义:查看磁盘情况。

linux-n199:~ # fdisk -l 

Disk /dev/sda: 59.0 GB, 59055800320 bytes
255 heads, 63 sectors/track, 7179 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          96      771088+  82  Linux swap / Solaris
/dev/sda2   *          97        6626    52452225   83  Linux
/dev/sda3            6627        7179     4441972+  82  Linux swap / Solaris

Disk /dev/sdb: 161.0 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       19581   157284351   83  Linux

Disk /dev/sdc: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

Disk /dev/sdd: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

Disk /dev/dm-0: 107.2 GB, 107269324800 bytes
255 heads, 63 sectors/track, 13041 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-0 doesn't contain a valid partition table


2.2 df -T 查看文件系统类型

linux141:/etc/ssh # df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda2     ext3    82573140  28105508  50273064  36% /
devtmpfs  devtmpfs    24711768       168  24711600   1% /dev
tmpfs        tmpfs    32875716         4  32875712   1% /dev/shm
/dev/sda6     ext3   103216920  76046560  21927148  78% /home
/dev/sda5     ext3    61931268   6028264  52757080  11% /opt
shm          tmpfs    32875716         4  32875712   1% /dev/shm

2.3 fdisk /dev/sba 操作

2.3.1 修改设备,并查看帮助

fdisk /dev/sba  -->   m

2.3.2 创建分区

命令:fdisk /dev/sba   -->   n  
命令:-->   p  
命令:-->   1    主分区1
命令:-->   1    柱面区从1开始
命令:-->   13054    柱面区从13054止
查看:-->   p
保存:-->   w

2.3.3 格式化创建的分区

命令:fdisk /dev/sba   -->  t
输入:-->  8e
查看:-->  p
保存:-->   w

2.4 创建pv物理卷

创建:pvcreate /dev/sdb1
查看:pvdisplay

2.5 创建vg

创建:vgcreate datavg /dev/sdb1
查看:vgdispaly

2.6 创建lv

创建:lvcreate -L 50G -n apache_lv datavg
查看:lvdisplay

2.7 当前文件系统的类型

命令:cat /etc/fstab
或:df -T

2.8 格式化lv,格式为ext3

命令:mkfs.ext3 -c /dev/datavg/apache_lv
说明:格式化要用数秒时间

2.9 挂载目录

命令:mount /dev/datavg/apache_lv /apache

3 扩容目录

前面参考步骤2相同。

3.1 创建物理卷

linux-qony:/ # pvcreate /dev/sdb3
  Physical volume "/dev/sdb3" successfully created

3.2 将创建的物理卷/添加到卷组

linux-qony:/ # vgextend vgoradata  /dev/sdb3
  Volume group "vgoradata" successfully extended

3.3 给逻辑卷添加空间

//增加100G
命令:lvextend +L +100G /dev/vgoradata/datalv
//增加到100G
命令:lvextend -L +100G /dev/vgoradata/datalv

3.4 查看物理卷方法

linux-qony:/ # lvdisplay
  --- Logical volume ---
  LV Name                /dev/vgoradata/datalv
  VG Name                vgoradata
  LV UUID                pbvGjL-EtTQ-ZMaX-H529-jERA-Zc6c-evkQKm
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                4.00 GB
  Current LE             1024
  Segments               2
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0

3.5 刷新文件系统使扩容生效

resize2fs
e2fsck
xfs

// 卸载目录
linux-n199:~ # umount /databak

//执行resize2fs针对文件系统ext2 ext3 ext4;xfs_growfs 针对文件系统xfs
linux-n199:~ # resize2fs /dev/mapper/backupvg-lv_bakup
resize2fs 1.38 (30-Jun-2005)
Please run 'e2fsck -f /dev/mapper/backupvg-lv_bakup' first.

//出现以上提示需先执行e2fsck用来刷新磁盘
linux-n199:~ # e2fsck -f /dev/mapper/backupvg-lv_bakup
e2fsck 1.38 (30-Jun-2005)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/backupvg-lv_bakup: 15/13107200 files (13.3% non-contiguous), 12976104/26188800 blocks

//重新执行resize2fs 
linux-n199:~ # resize2fs /dev/mapper/backupvg-lv_bakup
resize2fs 1.38 (30-Jun-2005)
Resizing the filesystem on /dev/mapper/backupvg-lv_bakup to 52141056 (4k) blocks.
The filesystem on /dev/mapper/backupvg-lv_bakup is now 52141056 blocks long.

//执行挂盘
linux-n199:~ # mount /databak
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。