从零开始的Linux运维屌丝之路,资源免费分享平台   运维人员首选:简单、易用、高效、安全、稳定、社区活跃的开源软件

已经建立好的-LVM磁盘扩容

发布:蔺要红09-19分类: 基础

# 查看
[root@elk3 ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/vda1                   50G  8.6G   38G  19% /
devtmpfs                   7.8G     0  7.8G   0% /dev
tmpfs                      7.8G   24K  7.8G   1% /dev/shm
tmpfs                      7.8G  636K  7.8G   1% /run
tmpfs                      7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/data--vg-data  2.0T  1.9T  5.1G 100% /data
tmpfs                      1.6G     0  1.6G   0% /run/user/0

# 查看当前状态
[root@elk ~]# lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                11:0    1  4.4M  0 rom
vda               253:0    0   50G  0 disk
└─vda1            253:1    0   50G  0 part /
vdb               253:16   0 1000G  0 disk
├─vdb1            253:17   0  500G  0 part
│ └─data--vg-data 252:0    0    2T  0 lvm  /data  
└─vdb2            253:18   0  500G  0 part
  └─data--vg-data 252:0    0    2T  0 lvm  /data
vdc               253:32   0 1000G  0 disk /elasticsearch_disk/disk_1
vdd               253:48   0 1000G  0 disk
└─data--vg-data   252:0    0    2T  0 lvm  /data
vde               253:64   0    2T  0 disk  # 新购买/待扩容到已有LVM

# 对vde新磁盘进行初始化
[root@elk ~]# fdisk /dev/vde
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xf00525ec.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-4194303999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303999, default 4194303999):
Using default value 4194303999
Partition 1 of type Linux and of size 2 TiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 Ext'd '(LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@elk ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

# 创建PV
[root@elk ~]# pvcreate /dev/vde1
  Physical volume "/dev/vde1" successfully created.

# 查看pv详细信息
[root@elk ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vdb1
  VG Name               data-vg
  PV Size               <500.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              127999
  Free PE               0
  Allocated PE          127999
  PV UUID               U5jAta-w2eg-y4pg-Segl-xl8g-3IWE-yDrihB

  --- Physical volume ---
  PV Name               /dev/vdb2
  VG Name               data-vg
  PV Size               500.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              127999
  Free PE               0
  Allocated PE          127999
  PV UUID               ZU2XqC-wwcf-SUuI-PjVN-J16V-dWKv-v2weta

  --- Physical volume ---
  PV Name               /dev/vdd
  VG Name               data-vg
  PV Size               1000.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              255999
  Free PE               0
  Allocated PE          255999
  PV UUID               mSlmIj-49dF-lXUT-0kCL-YCbi-qF3o-qphWlZ

# 可以看出这个是新的pv
  "/dev/vde1" is a new physical volume of "1.95 TiB"
  --- NEW Physical volume ---
  PV Name               /dev/vde1
  VG Name
  PV Size               1.95 TiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               QfmG0h-aj7A-uA7g-74KZ-VKyh-0Gkl-rZ9drI

# 查看 vg (就是需要待扩容的lvm)
[root@elk ~]# vgdisplay
  --- Volume group ---
  VG Name               data-vg # 需要扩容的vg
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               1.95 TiB
  PE Size               4.00 MiB
  Total PE              511997
  Alloc PE / Size       511997 / 1.95 TiB
  Free  PE / Size       0 / 0
  VG UUID               gldNch-N3jN-DRf2-4lS1-Atba-6QsU-izPTXU

# 再将pv添加到vg
[root@elk ~]# vgextend data-vg /dev/vde1
  Volume group "data-vg" successfully extended


# 再次查看 vg 
[root@elk ~]# vgdisplay
  --- Volume group ---
  VG Name               data-vg
  System ID
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               <3.91 TiB
  PE Size               4.00 MiB
  Total PE              1023996
  Alloc PE / Size       511997 / 1.95 TiB
  Free  PE / Size       511999 / 1.95 TiB   # 多的/有可用的
  VG UUID               gldNch-N3jN-DRf2-4lS1-Atba-6QsU-izPTXU

# 充分利用vg剩余空间
[root@elk ~]# lvextend -l +100%FREE  /dev/mapper/data--vg-data
  Size of logical volume data-vg/data changed from 1.95 TiB (511997 extents) to <3.91 TiB (1023996 extents).
  Logical volume data-vg/data successfully resized.

#调整文件系统大小

[root@elk ~]# lvextend -l +100%FREE  /dev/mapper/data--vg-data
  Size of logical volume data-vg/data changed from 1.95 TiB (511997 extents) to <3.91 TiB (1023996 extents).
  Logical volume data-vg/data successfully resized.

# 调整LVM
[root@elk ~]# resize2fs /dev/mapper/data--vg-data
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/data--vg-data is mounted on /data; on-line resizing required
old_desc_blocks = 250, new_desc_blocks = 500
The filesystem on /dev/mapper/data--vg-data is now 1048571904 blocks long.
温馨提示如有转载或引用以上内容之必要,敬请将本文链接作为出处标注,如有侵权我会在24小时之内删除!

欢迎使用手机扫描访问本站