VMware虚拟机linux扩容

VMware虚拟机linux扩容,参考,谢谢

https://www.jb51.net/article/144291.htm

centos7扩展磁盘空间 - 李老客儿 - 博客园

[root@localhost /]# fdisk -l 

磁盘 /dev/sda:85.9 GB, 85899345920 字节,167772160 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b4ea4

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@localhost /]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
分区号 (3,4,默认 3):3
起始 扇区 (41943040-167772159,默认为 41943040):3
值超出范围。
起始 扇区 (41943040-167772159,默认为 41943040):
将使用默认值 41943040
Last 扇区, +扇区 or +size{K,M,G} (41943040-167772159,默认为 167772159):30G
值超出范围。
Last 扇区, +扇区 or +size{K,M,G} (41943040-167772159,默认为 167772159):
将使用默认值 167772159
分区 3 已设置为 Linux 类型,大小设为 60 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sda:85.9 GB, 85899345920 字节,167772160 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b4ea4

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040   167772159    62914560   83  Linux

命令(输入 m 获取帮助):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)
正在同步磁盘。
[root@localhost /]# 
[root@localhost /]# 
[root@localhost /]# 
[root@localhost /]# 
[root@localhost /]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   17G   14G  3.7G   79% /
devtmpfs                 1.9G     0  1.9G    0% /dev
tmpfs                    1.9G     0  1.9G    0% /dev/shm
tmpfs                    1.9G   12M  1.9G    1% /run
tmpfs                    1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1               1014M  146M  869M   15% /boot
tmpfs                    378M     0  378M    0% /run/user/0
[root@localhost /]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):^Z
[2]+  已停止               fdisk /dev/sda
[root@localhost /]# fdisk -l 

磁盘 /dev/sda:85.9 GB, 85899345920 字节,167772160 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b4ea4

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040   167772159    62914560   83  Linux

磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@localhost /]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   17G   14G  3.7G   79% /
devtmpfs                 1.9G     0  1.9G    0% /dev
tmpfs                    1.9G     0  1.9G    0% /dev/shm
tmpfs                    1.9G   12M  1.9G    1% /run
tmpfs                    1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1               1014M  146M  869M   15% /boot
tmpfs                    378M     0  378M    0% /run/user/0
[root@localhost /]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   80G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sr0              11:0    1 1024M  0 rom  
[root@localhost /]# partprobe
[root@localhost /]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   80G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   19G  0 part 
│ ├─centos-root 253:0    0   17G  0 lvm  /
│ └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
└─sda3            8:3    0   60G  0 part 
sr0              11:0    1 1024M  0 rom  
[root@localhost /]# ----vgdisplay -v
-bash: ----vgdisplay: 未找到命令
[root@localhost /]# vgdisplay -v
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <19.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               fm8pp2-ojG5-O4ZL-oftG-pVKc-53Ex-c7sqCK
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                sQwpgC-UAoI-eHmf-9VFT-H1QD-9u9C-xCfV3f
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-06-16 12:52:06 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                akuBnq-WZMa-bFkW-ihOO-6aJS-8xzp-E9vAeo
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-06-16 12:52:06 +0800
  LV Status              available
  # open                 1
  LV Size                <17.00 GiB
  Current LE             4351
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               1wYReA-R0N9-rhRU-W23A-kWxK-srtA-NOVspR
  PV Status             allocatable
  Total PE / Free PE    4863 / 0
   
[root@localhost /]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
[root@localhost /]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               1wYReA-R0N9-rhRU-W23A-kWxK-srtA-NOVspR
   
  "/dev/sda3" is a new physical volume of "60.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               60.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Q1WXgb-YNjq-Ol1y-Y4dQ-Eu68-1JcN-jSlyOI
   
[root@localhost /]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended
[root@localhost /]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                sQwpgC-UAoI-eHmf-9VFT-H1QD-9u9C-xCfV3f
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-06-16 12:52:06 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                akuBnq-WZMa-bFkW-ihOO-6aJS-8xzp-E9vAeo
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-06-16 12:52:06 +0800
  LV Status              available
  # open                 1
  LV Size                <17.00 GiB
  Current LE             4351
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
[root@localhost /]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               1wYReA-R0N9-rhRU-W23A-kWxK-srtA-NOVspR
   
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               60.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              15359
  Free PE               15359
  Allocated PE          0
  PV UUID               Q1WXgb-YNjq-Ol1y-Y4dQ-Eu68-1JcN-jSlyOI
   
[root@localhost /]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   80G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   19G  0 part 
│ ├─centos-root 253:0    0   17G  0 lvm  /
│ └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
└─sda3            8:3    0   60G  0 part 
sr0              11:0    1 1024M  0 rom  
[root@localhost /]# lvextend -L +59G /dev/centos/root
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <76.00 GiB (19455 extents).
  Logical volume centos/root successfully resized.
[root@localhost /]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   80G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   19G  0 part 
│ ├─centos-root 253:0    0   76G  0 lvm  /
│ └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
└─sda3            8:3    0   60G  0 part 
  └─centos-root 253:0    0   76G  0 lvm  /
sr0              11:0    1 1024M  0 rom  
[root@localhost /]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4455424 to 19921920
[root@localhost /]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   76G   14G   63G   18% /
devtmpfs                 1.9G     0  1.9G    0% /dev
tmpfs                    1.9G     0  1.9G    0% /dev/shm
tmpfs                    1.9G   12M  1.9G    1% /run
tmpfs                    1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1               1014M  146M  869M   15% /boot
tmpfs                    378M     0  378M    0% /run/user/0

一、使用背景

Linux根目录磁盘空间不够用了,当修改了虚拟机模版增加磁盘大小或者插入了一块新硬盘,但是发现系统里的大小还是没改变。

产生的原因是没有给磁盘格式化,没有增加分区。

二、操作方法

1. 查看磁盘空间大小,使用df -h 命令,发现挂载根目录节点的/dev/mapper/ubuntu14--vg-root 只有28G容量。

1

2

3

4

5

6

7

8

9

10

root@ubuntu14:/opt# df -h

文件系统            容量 已用 可用 已用% 挂载点

/dev/mapper/ubuntu14--vg-root  28G  23G 3.3G  88% /

none              4.0K   0 4.0K  0% /sys/fs/cgroup

udev              3.9G 4.0K 3.9G  1% /dev

tmpfs             799M 384K 799M  1% /run

none              5.0M   0 5.0M  0% /run/lock

none              3.9G   0 3.9G  0% /run/shm

none              100M   0 100M  0% /run/user

/dev/vda1           236M  37M 188M  17% /boot

2. 增加磁盘空间,例如下图使用VM虚拟机增加的方式。

3.使用fdisk -l命令查看磁盘信息。当看到第一行Disk /dev/vda: 161.1 GB与实际df -h显示内容不符时,说明增加磁盘成功了。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

root@ubuntu14:/opt# fdisk -l

Disk /dev/vda: 161.1 GB, 161061273600 bytes

16 heads, 63 sectors/track, 312076 cylinders, total 314572800 sectors

Units = 扇区 of 1 * 512 = 512 bytes

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

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

Disk identifier: 0x0001a023

  设备 启动   起点     终点   块数  Id 系统

/dev/vda1  *    2048   499711   248832  83 Linux

/dev/vda2     501758  62912511  31205377  5 扩展

/dev/vda5     501760  62912511  31205376  8e Linux LVM

Disk /dev/mapper/ubuntu14--vg-root: 29.8 GB, 29804724224 bytes

255 heads, 63 sectors/track, 3623 cylinders, total 58212352 sectors

Units = 扇区 of 1 * 512 = 512 bytes

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

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

Disk identifier: 0x00000000

Disk /dev/mapper/ubuntu14--vg-root doesn't contain a valid partition table

Disk /dev/mapper/ubuntu14--vg-swap_1: 2147 MB, 2147483648 bytes

255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors

Units = 扇区 of 1 * 512 = 512 bytes

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

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

Disk identifier: 0x00000000

Disk /dev/mapper/ubuntu14--vg-swap_1 doesn't contain a valid partition table

4.使用fdisk /dev/vda, 创建新分区。

注意:不同操作系统的磁盘命名方式不同,有些是/dev/sda。具体使用方式参考第三步中fdisk -l首行显示Disk。如笔者在该系统中首行显示为Disk /dev/vda: 161.1 GB, 161061273600 bytes ,故使用命令fdisk /dev/vda)

按照下面Linux操作进行分区。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

root@ubuntu14:/opt# fdisk /dev/vda

命令(输入 m 获取帮助): m

命令操作

  a  toggle a bootable flag

  b  edit bsd disklabel

  c  toggle the dos compatibility flag

  d  delete a partition

  l  list known partition types

  m  print this menu

  n  add a new partition

  o  create a new empty DOS partition table

  p  print the partition table

  q  quit without saving changes

  s  create a new empty Sun disklabel

  t  change a partition's system id

  u  change display/entry units

  v  verify the partition table

  w  write table to disk and exit

  x  extra functionality (experts only)

命令(输入 m 获取帮助): n #new 新分区

Partition type:

  p  primary (1 primary, 1 extended, 2 free)

  l  logical (numbered from 5)

Select (default p): p  #选择主分区

分区号 (1-4,默认为 3): 3 #分区序号

起始 sector (499712-314572799,默认为 499712): #分区开始回车默认

将使用默认值 499712

Last sector, +扇区 or +size{K,M,G} (499712-501757,默认为 501757):

将使用默认值 501757

命令(输入 m 获取帮助): n #new 新分区

Partition type:

  p  primary (2 primary, 1 extended, 1 free)

  l  logical (numbered from 5)

Select (default p): p #选择主分区

Selected partition 4  #分区序号

起始 sector (62912512-314572799,默认为 62912512): #分区开始回车默认

将使用默认值 62912512

Last sector, +扇区 or +size{K,M,G} (62912512-314572799,默认为 314572799):

将使用默认值 314572799

命令(输入 m 获取帮助): t  #修改分区格式

分区号 (1-5): 4  #修改分区号

Hex code (type L to list codes): 8e #格式选择8e  linux LVM

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

命令(输入 m 获取帮助): p #显示分区信息

Disk /dev/vda: 161.1 GB, 161061273600 bytes

16 heads, 63 sectors/track, 312076 cylinders, total 314572800 sectors

Units = 扇区 of 1 * 512 = 512 bytes

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

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

Disk identifier: 0x0001a023

  设备 启动   起点     终点   块数  Id 系统

/dev/vda1  *    2048   499711   248832  83 Linux

/dev/vda2     501758  62912511  31205377  5 扩展

/dev/vda3     499712   501757    1023  83 Linux

/dev/vda4    62912512  314572799  125830144  8e Linux LVM

/dev/vda5     501760  62912511  31205376  8e Linux LVM

Partition table entries are not in disk order

命令(输入 m 获取帮助): 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.

5. 重启Linux操作系统,使用reboot命令。

6. 创建物理卷,使用pvcreate /dev/vda4命令。

1

2

root@ubuntu14:~# pvcreate /dev/vda4

 Physical volume "/dev/vda4" successfully created

7.查看新建的物理卷和大小,使用pvdisplay命令。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

root@ubuntu14:~# pvdisplay

 --- Physical volume ---

 PV Name        ubuntu14-vg

 PV Size        29.76 GiB / not usable 2.00 MiB

 Allocatable      yes (but full)

 PE Size        4.00 MiB

 Total PE       7618

 Free PE        0

 Allocated PE     7618

 PV UUID        XR32TY-aRQC-IQC6-oCx7-aa9X-KdJe-bHmaBd

 "/dev/vda4"        /dev/vda5

 VG Name is a new physical volume of "120.00 GiB"

 --- NEW Physical volume ---

 PV Name        /dev/vda4

 VG Name       

 PV Size        120.00 GiB

 Allocatable      NO

 PE Size        0 

 Total PE       0

 Free PE        0

 Allocated PE     0

 PV UUID        MVK0IT-LDgP-eWwZ-fzQM-tdyY-kRQ-nbk122

8. 将添加新的物理卷,加载到ubuntu14-vg卷组,使用vgextend ubuntu14-vg /dev/vda4命令。

1

2

root@ubuntu14:~# vgextend ubuntu14-vg /dev/vda4

Volume group "ubuntu14-vg" successfully extended

9. 查看卷组信息,使用vgdisplay命令。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

root@ubuntu14:~# vgdisplay        

 --- Volume group ---

 VG Name        ubuntu14-vg

 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        149.76 GiB

 PE Size        4.00 MiB

 Total PE       38338

 Alloc PE / Size    7618 / 29.76 GiB

 Free PE / Size    30720 / 120.00 GiB

 VG UUID        cq2Z6G-P6j1-S2gM-mibz-d63V-NjkS-dHYe7D

10.增加ubuntu14-vg大小,增加120G。使用lvresize -L +120G /dev/mapper/ubuntu14--vg-root命令。

1

2

3

root@ubuntu14:~# lvresize -L +120G /dev/mapper/ubuntu14--vg-root

 Extending logical volume root to 147.76 GiB

 Logical volume root successfully resized

11. 重新识别ubuntu14-vg大小,使用resize2fs /dev/mapper/ubuntu14--vg-root命令。

1

2

3

4

5

root@ubuntu14:~# resize2fs /dev/mapper/ubuntu14--vg-root

resize2fs 1.42.9 (4-Feb-2014)

Filesystem at /dev/mapper/ubuntu14--vg-root is mounted on /; on-line resizing required

old_desc_blocks = 2, new_desc_blocks = 10

The filesystem on /dev/mapper/ubuntu14--vg-root is now 38733824 blocks long.

12.查看扩容后的大小 ,使用df -h命令。

1

2

3

4

5

6

7

8

9

10

root@ubuntu14:~# df -h

文件系统            容量 已用 可用 已用% 挂载点

/dev/mapper/ubuntu14--vg-root 146G  23G 117G  17% /

none              4.0K   0 4.0K  0% /sys/fs/cgroup

udev              3.9G 4.0K 3.9G  1% /dev

tmpfs             799M 388K 799M  1% /run

none              5.0M   0 5.0M  0% /run/lock

none              3.9G   0 3.9G  0% /run/shm

none              100M   0 100M  0% /run/user

/dev/vda1           236M  37M 188M  17% /boot

当看到/dev/mapper/ubuntu14--vg-root 已经更新到新的大小时,则表示增加成功。

--------------------------遇到问题----------------------------------- 

centos7扩展磁盘空间

1.fdisk -l 查看当前分区

 

2.lsblk 命令: 列出所有可用设备块信息

3.进行分区 fdisk /dev/sda

 n:创建新分区

 p:创建主分区

 回车:分区编号

 回车:开始磁盘大小;

 回车:结束的磁盘大小

 w:写入磁盘

 

 

小插曲: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)

解决方法:执行下partprobe 命令

然后查看盘符就有了

4.查看卷分组----vgdisplay -v

 

 

 

 主要看 Free 部分,就是可用空间 

5.创建物理卷----pvcreate /dev/sda3

 

    如果此时直接创建出现错误----Device /dev/sda3 not found,可以reboot机器即可。

6.查看结果---- pvdisplay

 

7.扩展卷分组----vgextend centos /dev/sda3    (centos_admin是vgdisplay查到的分组名)

centos 这个名称是和上面的VG Name 一样的

 

8.查看逻辑卷----lvdisplay

 

 

 9.扩展逻辑卷----lvextend -L +300G /dev/centos_admin/root 

首先df -h 查看要扩展的

 

可以直接查看具体的目录挂载位置,有针对性的扩容

然后 lvextend -L + /dev/mapper/centos-root 挂载(挂载扩容是有限制的,

只能扩充物理内存的最大容量

这里的25600是PE的个数(一个4M大小):总大小为53504*4M/1024 约等于99G。)

 

10.最后一步----xfs_growfs /dev/mapper/centos-root

 

11.查看结果----df -h

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值