概念:据说默认centos都是基于LVM的

LVM:LVM是逻辑盘卷管理(Logical Volume Manager)的简称,它是Linux环境下对磁盘分区进行管理的一种机制.

LVM 更加详细的说明可点这里:http://www.cnblogs.com/mchina/p/linux-centos-logical-volume-manager-lvm.html

fdisk 命令用法http://blog.sina.com.cn/s/blog_66b448620100ibay.html

查看磁盘空间,根目录太小了,希望增加磁盘

在vsphere上修改磁盘的大小,重启进来。

[root@ucx-auto ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 30G 23G 7.1G 76% /
devtmpfs 5.8G 0 5.8G 0% /dev
tmpfs 5.8G 0 5.8G 0% /dev/shm
tmpfs 5.8G 8.9M 5.8G 1% /run
tmpfs 5.8G 0 5.8G 0% /sys/fs/cgroup
/dev/sda1 497M 155M 343M 32% /boot
tmpfs 1.2G 0 1.2G 0% /run/user/0

一、查看下LV

[root@ucx-auto ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID trGefC-4mxg-BkS6-sywT-ie3O-deA3-WC0EDQ
LV Write Access read/write
LV Creation host, time localhost, 2016-07-26 17:38:31 +0800
LV Status available
# open 2
LV Size 2.02 GiB
Current LE 516
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0 --- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID MRmrQV-MDKZ-ZJbQ-cvDP-nMEY-hWJk-xFCceo
LV Write Access read/write
LV Creation host, time localhost, 2016-07-26 17:38:31 +0800
LV Status available
# open 1
LV Size 66.49 GiB
Current LE 17022
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

二:查看机器所挂硬盘个数及分区情况

[root@ucx-auto ~]# fdisk -l

Disk /dev/sda: 75.2 GB, 75161927680 bytes, 146800640 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000cfb48 Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 67108863 33041408 8e Linux LVM Disk /dev/mapper/centos-swap: 2164 MB, 2164260864 bytes, 4227072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-root: 31.7 GB, 31666995200 bytes, 61849600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

如上 有一块磁盘/dev/sda 有两个分区。就用了33G,说明还有未分区的

三:/dev/sda进行分区,做这个时候忘记截图了 ,大概是下面这样,如果让你输入分区号,顺延下去即可。

esxi上为基于LVM的centos7的根目录扩容-LMLPHP

[root@ucx-auto ~]$fdisk /dev/sda
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: Device or resource busy.
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.

最后一步出现这样的提示。
 
这个时候[root@ucx-auto ~]# fdisk -l  可以看到多了个分区
/dev/sda3        67108864   146800639    39845888   83  Linux
 
但是是ls /dev|grep sda3 是还看不到的,因为还没格式化
 
四:格式化分区
[root@fz02 ~]# partprobe
 
注意看下根目录到磁盘类型,选择合适的type
esxi上为基于LVM的centos7的根目录扩容-LMLPHP

[root@ucx-auto dev]# mkfs -t ext3 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2490368 inodes, 9961472 blocks
498073 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
304 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done

 
[root@ucx-auto dev]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 29.49g                                                 
  swap centos -wi-ao----  2.02g   
 
五,创建物理卷
[root@ucx-auto dev]# pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: ^C  Interrupted...

Aborted wiping of ext3.
  1 existing signature left on the device.
  Aborting pvcreate on /dev/sda3.
[root@ucx-auto dev]# pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]:
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  Wiping ext3 signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created

 
六。
  1. 查看下名字
[root@ucx-auto dev]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   30G   23G  7.1G  76% /
devtmpfs                 5.8G     0  5.8G   0% /dev
tmpfs                    5.8G     0  5.8G   0% /dev/shm
tmpfs                    5.8G  8.9M  5.8G   1% /run
tmpfs                    5.8G     0  5.8G   0% /sys/fs/cgroup
/dev/sda1                497M  155M  343M  32% /boot
tmpfs                    1.2G     0  1.2G   0% /run/user/0
 
 2.增加卷组的空间
[root@ucx-auto dev]# vgextend /dev/mapper/centos-root /dev/sda3  【注意这里哦,卷组的名字是-前的】
  Invalid volume group name centos/root.
  Run `vgextend --help' for more information.
[root@ucx-auto dev]# vgextend /dev/mapper/centos /dev/sda3
  Volume group "centos" successfully extended
好了,卷组扩好了。
 
3,查看下卷组
[root@ucx-auto dev]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               69.50 GiB
  PE Size               4.00 MiB
  Total PE              17793
  Alloc PE / Size       8066 / 31.51 GiB  分配的
  Free  PE / Size       9727 / 38.00 GiB   空闲的
  VG UUID               8iYw2C-aqVR-C0eb-nRF4-v9q7-ZEyh-pxrRQB
 
可看到有个free pe可以供LV 分配
 
 
七, 六中扩容完毕VG ,就可以用VG中的Free空间来扩容LV ,
 
[root@ucx-auto dev]# sudo lvextend  -L +37G /dev/mapper/centos-root /dev/sda3  【注意下名字哦,现在是有LV 了,centos是LG名】
  Size of logical volume centos/root changed from 29.49 GiB (7550 extents) to 66.49 GiB (17022 extents).
  Logical volume root successfully resized.
 
1.检查下文件系统的正确性
[root@ucx-auto dev]# e2fsck -f /dev/mapper/centos-root
e2fsck 1.42.9 (28-Dec-2013)
/dev/mapper/centos-root is mounted.
e2fsck: Cannot continue, aborting.
 
2.重新定义大小,不懂为毛一直错
[root@ucx-auto dev]# resize2fs /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.

3.换个姿势再来一次

[root@ucx-auto dev]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=1932800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=7731200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=3775, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 7731200 to 17430528

4.看到根目录已经扩大了

[root@ucx-auto dev]# df -lh
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   67G   23G   45G  34% /
devtmpfs                 5.8G     0  5.8G   0% /dev
tmpfs                    5.8G     0  5.8G   0% /dev/shm
tmpfs                    5.8G  8.9M  5.8G   1% /run
tmpfs                    5.8G     0  5.8G   0% /sys/fs/cgroup
/dev/sda1                497M  155M  343M  32% /boot
tmpfs                    1.2G     0  1.2G   0% /run/user/0

参考:https://www.cnblogs.com/zwj-linux/p/11653478.html

05-11 15:09