centos7.6下增加新硬盘并扩容指定目录

       逻辑卷是使用逻辑卷组管理(Logic Volume Manager)创建出来的设备,如果要了解逻辑卷,那么首先需要了解逻辑卷管理中的一些概念。

  • 物理卷(Physical Volume,PV):也就是物理磁盘分区,如果想要使用LVM来管理这个分区,可以使用fdisk将其ID改为LVM可以识别的值,即8e。

  • 卷组(Volume Group,VG):PV的集合

  • 逻辑卷(Logic Volume,LV):VG中画出来的一块逻辑磁盘

了解概念之后,逻辑卷是如何产生的就很清晰了:物理磁盘或者磁盘分区转换为物理卷,一个或多个物理卷聚集形成一个或多个卷组,而逻辑卷就是从某个卷组里面抽象出来的一块磁盘空间。具体架构如下:

目标:给根目录增加400G的逻辑卷大小

        虚拟机增加新硬盘就不操作了,我挂了一块400G的硬盘,这时要重启虚拟机,不然不识别

操作思路:

1.物理硬盘创建分区sdb1

2.修改分区属性为8e

3.修改分区文件系统格式为ext4

4.sdb1创建pv逻辑卷

5.将sdb1逻辑卷加入到vg卷组 centos下(原根卷组是centos)

6.给根目录扩大容量

7.刷新容量

使用的命令合集:

      reboot
   1/2  fdisk /dev/sdb
   3  mkfs.ext4 /dev/sdb1
   4  partprobe
   4  pvcreate /dev/sdb1
   5  vgextend centos /dev/sdb1
   6  lvextend -l +100%FREE /dev/centos/root
   7  xfs_growfs /
   8  df -h
   9  history

 全部命令+输出合集:

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

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

命令(输入 m 获取帮助):t
已选择分区 1

Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
fd0               2:0    1     4K  0 disk
sda               8:0    0   300G  0 disk
├─sda1            8:1    0     1G  0 part /boot
├─sda2            8:2    0   249G  0 part
│ ├─centos-root 253:0    0 291.1G  0 lvm  /
│ └─centos-swap 253:1    0   7.9G  0 lvm  [SWAP]
└─sda3            8:3    0    50G  0 part
  └─centos-root 253:0    0 291.1G  0 lvm  /
sdb               8:16   0   400G  0 disk
└─sdb1            8:17   0   400G  0 part
sr0              11:0    1  1024M  0 rom

[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
26214400 inodes, 104857344 blocks
5242867 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2252341248
3200 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, 8847                                                                           36, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71                                                                           663616, 78675968,
        102400000

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information:                                                                            完成

[root@localhost ~]# partprobe

[root@localhost ~]# pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 10                                                                           80. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.


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

[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root
  Size of logical volume centos/root changed from <527.37 GiB (135006 extents) to 691.11 GiB (176925 extents).
  Logical volume centos/root successfully resized.

[root@localhost ~]# xfs_growfs /
meta-data=/dev/mapper/centos-root isize=512    agcount=8, agsize=15801856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=123936768, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=30863, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 123936768 to 181171200
[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root  691G  1.3G  690G    1% /
devtmpfs                 7.8G     0  7.8G    0% /dev
tmpfs                    7.8G     0  7.8G    0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G    1% /run
tmpfs                    7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/sda1               1014M  148M  867M   15% /boot
tmpfs                    1.6G     0  1.6G    0% /run/user/0

猜你喜欢

转载自blog.csdn.net/weixin_42517271/article/details/130383898