Linux【6】-硬盘管理2-9-Centos增加磁盘(扩容,LVM)

1:使用背景

废话不多说,磁盘空间不足,增加磁盘,然后扩充现有不足空间磁盘。

本次以Vmware进行测验。

2:我们本次要增加的就是这个

3:我们先添加一个磁盘,20G,添加过程不在赘述

4:添加完成后,要重启一下,要不然系统无法识别

5:添加完成后,我们查看是否添加成功

6:添加成功后,我们开始对分区进行操作

[root@localhost /]# fdisk /dev/sdb

如果上述,出现这种情况

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)

则输入:

partprobe

7:创建物理卷

[root@localhost /]# pvcreate /dev/sdb1
WARNING: dos signature detected on /dev/sda4 at offset 510. Wipe it? [y/n]: y

Wiping dos signature on /dev/sda4.

  Physical volume "/dev/sdb1" successfully created.

8:查看新建的物理卷和大小,记住VG name 组名

9:将添加新的物理卷,加载到cl卷组

[root@localhost /]# vgextend cl /dev/sdb1 
  Volume group "cl" successfully extended

10:再次查看物理卷,也可以使用vgdisplay命令

11:增加磁盘空间

[root@localhost /]# lvresize -L +19.99G /dev/mapper/cl-root                      #/dev/mapper/cl-root 是磁盘分区的文件系统名 df -h 的时候可以看到
  Rounding size to boundary between physical extents: 19.99 GiB.
  Size of logical volume cl/root changed from 17.00 GiB (4351 extents) to 36.99 GiB (9469 extents).
  Logical volume cl/root su

12:重新识别分区大小

[root@localhost /]# resize2fs /dev/mapper/cl-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block 当尝试打开 /dev/mapper/cl-root 时
找不到有效的文件系统超级块.

13:如果出现“找不到有效的文件系统超级块”错误,用一下命令即可

[root@localhost /]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-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 9696256

14:查看磁盘空间是否添加成功

二、讨论

2.1 /dev/mapper/centos-root与/dev/sda的区别

你这是用到了 LVM,

  • /dev/sda 是磁盘设备,属于物理卷,使用 pvdisplay 可以查看
  • /dev/mapper/centos-root 这是逻辑卷,使用 lvdisplay 可以查看
  • 另外可以使用 lsblk 查看磁盘/卷的总览情况

具体示例

[root@pp ~]# fdisk -l

Disk /dev/sda: 483.2 GB, 483183820800 bytes, 943718400 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: 0x00077b25

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048        6143        2048   83  Linux
/dev/sda2   *        6144     2103295     1048576   83  Linux
/dev/sda3         2103296   419430399   208663552   8e  Linux LVM
/dev/sda4       419430400   943718399   262144000   83  Linux

Disk /dev/mapper/centos-root: 473.5 GB, 473503367168 bytes, 924811264 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-swap: 8594 MB, 8594128896 bytes, 16785408 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



[root@pp ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  441G  191G  251G  44% /
devtmpfs                  16G     0   16G   0% /dev
tmpfs                     16G     0   16G   0% /dev/shm
tmpfs                     16G  8.7M   16G   1% /run
tmpfs                     16G     0   16G   0% /sys/fs/cgroup
/dev/sda2               1014M  143M  872M  15% /boot
tmpfs                    3.2G     0  3.2G   0% /run/user/0
2.2.2.1:/test             24T   22T  2.0T  92% /mnt/nfs


[root@pp ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               <199.00 GiB / not usable 0
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              50943
  Free PE               0
  Allocated PE          50943
  PV UUID               Gg7VXK-jUJs-OLrB-PcI9-sKoh-RlPp-RN8ZGq

  --- Physical volume ---
  PV Name               /dev/sda4
  VG Name               centos
  PV Size               250.00 GiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              63999
  Free PE               1
  Allocated PE          63998
  PV UUID               YjtscY-fySg-U6Lc-ITbD-GY70-Q3SF-1pPYkc



[root@pp ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                fckJIw-4zZk-yPce-wiaQ-R70h-Yl3B-TBGsON
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-09-25 16:37:45 +0800
  LV Status              available
  # open                 2
  LV Size                8.00 GiB
  Current LE             2049
  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                W3FPGB-61S8-A1ip-YXsa-dwJS-1wfy-NyxgNP
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-09-25 16:37:46 +0800
  LV Status              available
  # open                 1
  LV Size                440.98 GiB
  Current LE             112892
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0



[root@pp ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk
sda               8:0    0  450G  0 disk
├─sda1            8:1    0    2M  0 part
├─sda2            8:2    0    1G  0 part /boot
├─sda3            8:3    0  199G  0 part
│ ├─centos-root 253:0    0  441G  0 lvm  /
│ └─centos-swap 253:1    0    8G  0 lvm  [SWAP]
└─sda4            8:4    0  250G  0 part
  └─centos-root 253:0    0  441G  0 lvm  /
sr0              11:0    1 1024M  0 rom

参考资料

这里是一个广告位,,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn