ESXI6.5给centos6.6扩容磁盘空间

[root@xxx]# cat /etc/redhat-release 
CentOS release 6.6 (Final)

1.扩展磁盘大小

我们这里把50G扩到70G
ESXI6.5给centos6.6扩容磁盘空间_第1张图片

在这里插入图片描述

2.确认目前状态以及是否扩容成功

发现还是50G大小,并没有达到70G,这是需要reboot下试试

ESXI6.5给centos6.6扩容磁盘空间_第2张图片

重启后发现磁盘已经扩展了

ESXI6.5给centos6.6扩容磁盘空间_第3张图片

3、扩展分区

[root@localHOST ~]# fdisk /dev/sda

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): 3
First cylinder (6528-9137, default 6528): 
Using default value 6528
Last cylinder, +cylinders or +size{K,M,G} (6528-9137, default 9137): 
Using default value 9137

Command (m for help): t
Partition number (1-4): 3
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  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       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-FS data    
 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  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT            
 f  W95 Ext'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 or Sys ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 65  Novell Netware  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): 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  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       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-FS data    
 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  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT            
 f  W95 Ext'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 or Sys ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 65  Novell Netware  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): 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  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       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-FS data    
 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  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT            
 f  W95 Ext'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 or Sys ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 65  Novell Netware  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 ## lvm 文件类型
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): W    ##保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

新增了/dev/sda3,分区扩展成功

Disk /dev/sda: 75.2 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000eb332

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        6528    51915776   8e  Linux LVM
/dev/sda3            6528        9137    20964152+  8e  Linux LVM

4、加载分区表


方法一:(推荐)

[root@localhost ~]# partprobe
1
执行 partprobe命令用于将磁盘分区表变化信息通知内核,并请求操作系统重新加载分区表,此方法可以不用重启系统;

方法二:

[root@localhost ~]# reboot

5、扩展VG,创建VG

[root@localhost ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[root@localhost~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  vg_192   1   3   0 wz--n- 49.51g    0 

6、把sda3加入到lvm中

[root@localhost~]# vgextend vg_192 /dev/sda3 
  Volume group "vg_192" successfully extended

注意:vg_192是vg组名称

6、扩展LV lvextend

[root@192- ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_192-lv_root
                      9.8G  761M  8.5G   9% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/sda1             477M   25M  427M   6% /boot
/dev/mapper/vg_192-LogVol02
                       34G  1.1G   32G   4% /data
[root@192-168-0-226 ~]# lvextend /dev/mapper/vg_192-LogVol02 /dev/s
scd0      sda1      sda3      sg1       snapshot  stderr    stdout    
sda       sda2      sg0       shm/      sr0       stdin     systty    
[root@192-168-0-226 ~]# lvextend /dev/mapper/vg_192-LogVol02 /dev/sda3
  Size of logical volume vg_192/LogVol02 changed from 34.51 GiB (8834 extents) to 54.50 GiB (13951 extents).
  Logical volume LogVol02 successfully resized
[root@192- ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_192-lv_root
                      9.8G  761M  8.5G   9% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/sda1             477M   25M  427M   6% /boot
/dev/mapper/vg_192-LogVol02
                       34G  1.1G   32G   4% /data

通过lvs可以看到已经扩上来了,但是df -h 还是看不到

[root@192 ~]# lvs
  LV       VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  LogVol02 vg_192 -wi-ao---- 54.50g                                                    
  lv_root  vg_192 -wi-ao---- 10.00g                                                    
  lv_swap  vg_192 -wi-ao----  5.00g  

7、刷新下磁盘,扩展就成功了

resize2fs -p
[root@1 ~]# resize2fs -p /dev/mapper/vg_192-LogVol02resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_192-LogVol02 is mounted on /data; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 4
Performing an on-line resize of /dev/mapper/vg_192-LogVol02 to 14285824 (4k) blocks.
The filesystem on /dev/mapper/vg_192-LogVol02 is now 14285824 blocks long.

[root@19 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_192-lv_root
                    9.8G  761M  8.5G   9% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/sda1             477M   25M  427M   6% /boot
/dev/mapper/vg_192-LogVol02
                     54G  1.1G   50G   3% /data

参考文档:
https://blog.csdn.net/weixin_43946523/article/details/84850205

增加磁盘

ESXI6.5给centos6.6扩容磁盘空间_第4张图片


df -h
fdisk -l
cat /proc/scsi/scsi
echo "scsi add-single-device 2 0 1 0" > /proc/scsi/scsi 
echo "scsi add-single-device 2 0 2 0" >/proc/scsi/scsi
cat /proc/scsi/scsi
vgs
fdisk -l
pvcreate /dev/sdb
vgextend VolGroup /dev/sdb
vgs
vgdisplay 
lvextend -l +100%FREE /dev/mapper/VolGroup-LogVol04
lvs
resize2fs -p /dev/mapper/VolGroup-LogVol04
df -h

添加磁盘并且重新添加挂载到新目录

cat /proc/scsi/scsi
fdisk -l
echo "scsi add-single-device 2 0 2 0" >/proc/scsi/scsi
cat /proc/scsi/scsi
fdisk -l
pvcreate /dev/sdc


lvcreate -L 100G -n backup VolGroup
mkfs.ext4 /dev/mapper/VolGroup-backup
mount /dev/mapper/VolGroup-backup /backup

lvextend -L +40G /dev/mapper/VolGroup-LogVol00
lvextend -l +100%FREE /dev/mapper/VolGroup-backup
resize2fs -p /dev/mapper/VolGroup-backup
df -h




[root@jituan-xiaofei-docker01 ~]# resize2fs /dev/centos/root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/centos/root
Couldn't find valid filesystem superblock.



文件解决

由于系统为centos7系统,文件格式为xfs

所以需要使用以下命令刷新lv

xfs_growfs  /dev/centos/root



实现开机自动挂载
实现自动挂载

vi /etc/fstab

添加如下内容:

/dev/vdb /mnt ext4 defaults 0 0


当挂载命令失败后,重启也失败了,且无法更改更目录文件时需要但用户模式
单用户模式下mount -o remount,rw / 有大用途


强制重启
single 
b

当新挂载一个系统目录时,比如/var目录,先创建一个/var1目录,把文件拷贝过来,再删除掉原来/var目录下的文件,再mount,再拷贝/var的文件过来,再加开机自动挂载,再重启

你可能感兴趣的:(运维学习)