整理此前linux 系统、逻辑卷扩容全过程:新增加的硬盘已经安装到服务器中

用户此前的磁盘容量为600G,由于数据大部分在data目录存放,先需要将新加1T的磁盘全部空间扩容到data目录下

[root@CMS-1 ~]# fdisk -l                         #通过此命令可以查看服务上所有磁盘的容量、分区等详细信息

 

Disk /dev/sda: 599.6 GB, 599550590976 bytes      #红色部分600G是服务器本身的硬盘 

255 heads, 63 sectors/track, 72891cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000c2f

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sda1  *           1          26      204800  83  Linux

Partition 1 does not end on cylinderboundary.

/dev/sda2              26       72892  585292800   8e  Linux LVM

 

Disk /dev/sdb: 999.7 GB, 999653638144 bytes       #这个便是新增加的1T硬盘

255 heads, 63 sectors/track, 121534cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000

  

Disk /dev/mapper/VolGroup-LogVol00: 53.7GB, 53687091200 bytes  

255 heads, 63 sectors/track, 6527 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000

  

Disk /dev/mapper/VolGroup-LogVol02: 34.4GB, 34359738368 bytes

255 heads, 63 sectors/track, 4177 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000 

 

Disk /dev/mapper/VolGroup-LogVol01: 107.4GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000 

 

Disk /dev/mapper/VolGroup-LogVol03: 403.9GB, 403915669504 bytes

255 heads, 63 sectors/track, 49106cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000

#以上是服务器硬盘信息,两块盘1个600G,1个1T;


#这部分开始对新增加磁盘分区、指定分区表示为LVM、保存退出

[root@CMS-1 ~]# fdisk /dev/sdb  #管理新增硬盘

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

Building a new DOS disklabel with diskidentifier 0xfdc6ff07.

Changes will remain in memory only, untilyou decide to write them.

After that, of course, the previous contentwon't be recoverable.

 

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

 

WARNING: DOS-compatible mode is deprecated.It's strongly recommended to

        switch off the mode (command 'c') and change display units to

        sectors (command 'u').

 

Command (m for help): n       #新建分区

Command action

  e   extended

  p   primary partition (1-4)

p                            #建主分区

Partition number (1-4): 1    #分区号1到4之间

First cylinder (1-121534, default 1):

Using default value 1        #磁盘柱面开始位置

Last cylinder, +cylinders or +size{K,M,G}(1-121534, default 121534):    #柱面结束位置、默认全部

Using default value 121534

 

Command (m for help): t      #查看分区代码

Selected partition 1

Hex code (type L to list codes): L  #显示所有表示代码

 

 0 Empty           24  NEC DOS         81 Minix / old Lin bf  Solaris       

 1 FAT12           39  Plan 9          82 Linux swap / So c1  DRDOS/sec (FAT-

 2  XENIXroot      3c  PartitionMagic  83 Linux           c4  DRDOS/sec (FAT-

 3  XENIXusr       40  Venix 80286     84 OS/2 hidden C:  c6  DRDOS/sec (FAT-

 4  FAT16<32M      41  PPC PReP Boot   85 Linux extended  c7  Syrinx        

 5 Extended        42  SFS             86 NTFS volume set da  Non-FSdata   

 6 FAT16           4d  QNX4.x          87 NTFS volume set db  CP/M / CTOS /.

 7 HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility  

 8 AIX             4f QNX4.x 3rd part 8e  Linux LVM       df BootIt        

 9  AIXbootable    50  OnTrack DM      93 Amoeba          e1  DOS access    

 a  OS/2Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3 DOS R/O       

 b  W95FAT32       52  CP/M           9f  BSD/OS          e4 SpeedStor     

 c  W95FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs       

 e  W95FAT16 (LBA) 54  OnTrackDM6      a5 FreeBSD         ee  GPT           

 f  W95Ext'd (LBA) 55  EZ-Drive        a6 OpenBSD         ef  EFI (FAT-12/16/

10 OPUS            56  Golden Bow      a7 NeXTSTEP        f0  Linux/PA-RISC b

11 Hidden FAT12    5c  Priam Edisk     a8 Darwin UFS      f1  SpeedStor     

12 Compaq diagnost 61  SpeedStor       a9 NetBSD          f4  SpeedStor     

14 Hidden FAT16 <3 63  GNU HURD orSys ab  Darwin boot     f2 DOS secondary 

16 Hidden FAT16    64  Novell Netware  af  HFS/ HFS+      fb  VMware VMFS   

17 Hidden HPFS/NTF 65  NovellNetware  b7  BSDI fs         fc VMware VMKCORE

18 AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd Linux raid auto

1b Hidden W95 FAT3 75  PC/IX           bb Boot Wizard hid fe  LANstep       

1c Hidden W95 FAT3 80  Old Minix       be Solaris boot    ff  BBT           

1e Hidden W95 FAT1

Hex code (type L to list codes): 8e  #输入8eLVM

Changed system type of partition 1 to 8e(Linux LVM)

 

Command (m for help): p        #查看分区信息

 

Disk /dev/sdb: 999.7 GB, 999653638144 bytes

255 heads, 63 sectors/track, 121534cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0xfdc6ff07

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1      121534  976221823+  8e  Linux LVM

 

Command (m for help): w         #保存退出

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

#到这新增磁盘分区已完成


[root@CMS-1 ~]# fdisk -l             #查看分区后的磁盘信息

 

Disk /dev/sda: 599.6 GB, 599550590976 bytes

255 heads, 63 sectors/track, 72891cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000c2f

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sda1  *           1         26      204800   83 Linux

Partition 1 does not end on cylinderboundary.

/dev/sda2              26       72892  585292800   8e  Linux LVM

 

Disk /dev/sdb: 999.7 GB, 999653638144 bytes

255 heads, 63 sectors/track, 121534cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0xfdc6ff07

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1     121534   976221823+  8e Linux LVM

 

Disk /dev/mapper/VolGroup-LogVol00: 53.7GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000

  

Disk /dev/mapper/VolGroup-LogVol02: 34.4GB, 34359738368 bytes

255 heads, 63 sectors/track, 4177 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000

 

Disk /dev/mapper/VolGroup-LogVol01: 107.4GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000

 

Disk /dev/mapper/VolGroup-LogVol03: 403.9GB, 403915669504 bytes

255 heads, 63 sectors/track, 49106 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000


[root@CMS-1 ~]# pvcreate /dev/sdb1           #用此命令建立pv

 Physical volume "/dev/sdb1" successfully created


[root@CMS-1 ~]# df -h                        #查看磁盘使用情况

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-LogVol00

                       50G   12G  35G  26% /

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

/dev/sda1             190M   46M 135M  26% /boot

/dev/mapper/VolGroup-LogVol03

                      371G  322G  30G  92% /data     #此为要扩容的逻辑卷、可用容量为30G

/dev/mapper/VolGroup-LogVol01

                       99G   43G  51G  46% /var


[root@CMS-1 ~]# vgs                                  #查看卷组、总大小为558.18G、可用为0

 VG       #PV #LV #SN Attr   VSize  VFree

 VolGroup   1   4   0wz--n- 558.18g    0


[root@CMS-1 ~]# vgextend VolGroup /dev/sdb1          #将物理卷/dev/sdb1加入卷组

 Volume group "VolGroup" successfully extended


[root@CMS-1 ~]# vgs                                  #再次查看卷组、总大小为1.45T、931G可用

 VG       #PV #LV #SN Attr   VSize VFree 

 VolGroup   2   4   0wz--n- 1.45t 931.00g


[root@CMS-1 ~]# df -h                                #查看磁盘使用情况、没变化

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-LogVol00

                       50G   12G  35G  26% /

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

/dev/sda1             190M   46M 135M  26% /boot

/dev/mapper/VolGroup-LogVol03

                      371G  322G  30G  92% /data

/dev/mapper/VolGroup-LogVol01

                       99G   43G  51G  46% /var


[root@CMS-1 ~]# lvextend -l +100%free  /dev/mapper/VolGroup-LogVol03   #将所有空间扩容到指定指定逻辑卷

 Size of logical volume VolGroup/LogVol03 changed from 376.18 GiB (96301extents) to 1.28 TiB (334636 extents).

 Logical volume LogVol03 successfully resized

[root@CMS-1 ~]# df -h                             #再次查看还变化

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-LogVol00

                       50G   12G  35G  26% /

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

/dev/sda1             190M   46M 135M  26% /boot

/dev/mapper/VolGroup-LogVol03

                      371G  322G  30G  92% /data

/dev/mapper/VolGroup-LogVol01

                       99G   43G  51G  46% /var


[root@CMS-1 ~]# resize2fs   /dev/mapper/VolGroup-LogVol03  #调整分区大小

#centos7命令如下xfs_growfs  /dev/mapper/VolGroup-LogVol03

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/mapper/VolGroup-LogVol03is mounted on /data; on-line resizing required

old desc_blocks = 24, new_desc_blocks = 82

Performing an on-line resize of/dev/mapper/VolGroup-LogVol03 to 342667264 (4k) blocks.

The filesystem on/dev/mapper/VolGroup-LogVol03 is now 342667264 blocks long.


df -h