对centOS的home目录进行扩容。

文章详细介绍了如何在CentOS系统上使用LVM对/home目录进行扩容,包括理解PV、VG、LV的概念,使用命令行工具进行磁盘现状检查,以及实际操作步骤,如pvcreate、vgextend、lvextend和xfs_growfs命令的运用,成功将/home目录的逻辑卷大小增加20G。
摘要由CSDN通过智能技术生成

1 首先要了解PV\VG\LV的含义

1.1 基本概念

在这里插入图片描述

  • 物理卷(Physical Volume,PV)
    指磁盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。
  • 卷组(Volume Group,VG)
    类似于非LVM系统中的物理磁盘,其由一个或多个物理卷PV组成。可以在卷组上创建一个或多个LV(逻辑卷)。
  • 逻辑卷(Logical Volume,LV)
    类似于非LVM系统中的磁盘分区,逻辑卷建立在卷组VG之上。在逻辑卷LV之上可以建立文件系统(比如/home或者/usr等)。

ps: 1.1节引用来源为简书,作者为运维少年,原为链接

1.2 基本命令行

  • 常用命令行在这里插入图片描述
  • 查看命令行在这里插入图片描述
    ps: 1.2节引用来源为CSDN,作者为胖胖不胖、,原为链接

2 实际操作

2.1 盘符当前现状

因为我装的是双系统,所以需要先在windows下划分出20G空闲空间,至于怎么划出20G,网上有大量教程。在linux下查看为
在这里插入图片描述

2.1实操

  • 实操参考百度教程link
Last login: Thu Jun 22 23:35:22 2023 from 192.168.3.13
[root@study ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 931.5G  0 disk
├─sda1            8:1    0   150G  0 part
├─sda2            8:2    0     1K  0 part
├─sda3            8:3    0     1G  0 part /boot
├─sda4            8:4    0    30G  0 part
│ ├─centos-root 253:0    0    10G  0 lvm  /
│ ├─centos-swap 253:1    0     1G  0 lvm
│ └─centos-home 253:2    0     5G  0 lvm  /home
├─sda5            8:5    0   261G  0 part
├─sda6            8:6    0   261G  0 part
├─sda7            8:7    0 189.5G  0 part
└─sda8            8:8    0    20G  0 part
[root@study ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@study ~]# fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x7989ea63

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   314576895   157287424    7  HPFS/NTFS/exFAT
/dev/sda2       314576896  1848666111   767044608    f  W95 Ext'd (LBA)
/dev/sda3      1848666112  1850763263     1048576   83  Linux
/dev/sda4      1850763264  1913686015    31461376   8e  Linux LVM
/dev/sda5       314578944   861935615   273678336    7  HPFS/NTFS/exFAT
/dev/sda6       861939712  1409298431   273679360    7  HPFS/NTFS/exFAT
/dev/sda7      1409300480  1806723071   198711296    7  HPFS/NTFS/exFAT
/dev/sda8      1806725120  1848666111    20970496    7  HPFS/NTFS/exFAT

Disk /dev/mapper/centos-root: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/centos-home: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

[root@study ~]# pvcreate /dev/sda8
WARNING: ntfs signature detected on /dev/sda8 at offset 3. Wipe it? [y/n]: y                                                    Wiping ntfs signature on /dev/sda8.
  Physical volume "/dev/sda8" successfully created.
[root@study ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               30.00 GiB
  PE Size               4.00 MiB
  Total PE              7680
  Alloc PE / Size       4096 / 16.00 GiB
  Free  PE / Size       3584 / 14.00 GiB
  VG UUID               13qShD-1DCk-9LqQ-P8mU-JA5A-EqS6-2lwBpm

[root@study ~]# vgextend centos /dev/sda8
  Volume group "centos" successfully extended
[root@study ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                Yl0TIJ-GBld-sfcZ-lSs5-aC8g-h19l-5bfhOk
  LV Write Access        read/write
  LV Creation host, time study.centos.vbird, 2019-03-23 04:23:04 +0800
  LV Status              available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                KHhhNP-82Dx-0sUA-eAYU-tcHL-djnL-xhLZCn
  LV Write Access        read/write
  LV Creation host, time study.centos.vbird, 2019-03-23 04:23:05 +0800
  LV Status              available
  # open                 0
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                UvhEfA-0aku-UTsQ-DhjJ-J49N-8PCp-6EZ7wC
  LV Write Access        read/write
  LV Creation host, time study.centos.vbird, 2019-03-23 04:23:05 +0800
  LV Status              available
  # open                 1
  LV Size                5.00 GiB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

[root@study ~]# lvextend -l +20G /dev/centos/home
  Invalid argument for --extents: +20G
  Error during parsing of command line.
[root@study ~]# lvextend -L +20G /dev/centos/home
  Size of logical volume centos/home changed from 5.00 GiB (1280 extents) to 25.00 GiB (6400 extents).
  Logical volume centos/home successfully resized.
[root@study ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   10G  8.0G  2.0G  81% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G  4.0K  7.7G   1% /dev/shm
tmpfs                    7.7G  9.9M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sda3               1014M  236M  779M  24% /boot
/dev/mapper/centos-home  5.0G  5.0G   41M 100% /home
tmpfs                    1.6G   12K  1.6G   1% /run/user/42
tmpfs                    1.6G     0  1.6G   0% /run/user/0
[root@study ~]# xfs_growfs /dev/centos/home
meta-data=/dev/mapper/centos-home isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1310720, 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=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1310720 to 6553600
[root@study ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   10G  8.0G  2.0G  81% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G  4.0K  7.7G   1% /dev/shm
tmpfs                    7.7G  9.9M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sda3               1014M  236M  779M  24% /boot
/dev/mapper/centos-home   25G  5.0G   21G  20% /home
tmpfs                    1.6G   12K  1.6G   1% /run/user/42
tmpfs                    1.6G     0  1.6G   0% /run/user/0
[root@study ~]#

要扩充centos7逻辑卷的步骤如下: 1. 首先,使用命令`lvs`查看逻辑卷,确定要扩充的卷的名称和所在的卷组。比如,我们要扩充的是home卷,所在的卷组是centos。\[1\] 2. 使用命令`lvextend -L +19G /dev/mapper/centos-home`来扩展逻辑卷的容量。这里的"+19G"表示要增加的容量大小。执行该命令后,逻辑卷的大小会发生变化。\[2\] 3. 如果新增的容量没有完全扩展到逻辑卷上,可以使用命令`lvextend -l +100%FREE /dev/mapper/centos-home`来将剩余的空间全部扩展到逻辑卷上。 4. 扩展逻辑卷后,还需要对文件系统进行扩容。如果是ext4文件系统,可以使用命令`resize2fs /dev/mapper/centos-home`来扩展文件系统。 5. 如果新增的容量是来自于一个新的物理卷,需要将该物理卷添加到卷组中。可以使用命令`pvcreate /dev/sda3`来初始化新的物理卷。然后使用命令`vgextend centos /dev/sda3`将新的物理卷添加到centos卷组中。\[3\] 请注意,执行这些操作需要root权限,并且在进行任何磁盘操作之前,请务必备份重要的数据。 #### 引用[.reference_title] - *1* [关于centos7新增磁盘分区,扩容逻辑卷过程](https://blog.csdn.net/qq_40277788/article/details/124451130)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [关于虚拟机中Centos7的磁盘扩容步骤](https://blog.csdn.net/escFAJ/article/details/109901381)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值