Expand the home directory of centOS.

1 First of all, we must understand the meaning of PV\VG\LV

1.1 Basic concepts

insert image description here

  • Physical Volume (Physical Volume, PV)
    refers to a disk partition or a device (such as RAID) that logically has the same function as a disk partition. comparison, but contains management parameters related to LVM.
  • A volume group (Volume Group, VG)
    is similar to a physical disk in a non-LVM system, which consists of one or more physical volumes PV. One or more LVs (Logical Volumes) can be created on a volume group.
  • A logical volume (LV)
    is similar to a disk partition in a non-LVM system, and a logical volume is built on top of a volume group VG. A file system (such as /home or /usr, etc.) can be established on the logical volume LV.

ps: Section 1.1 is quoted from Jianshu, the author is Operation and Maintenance Youth, and it was originally a link

1.2 Basic command line

  • Common command linesinsert image description here
  • View the command line insert image description here
    ps: Section 1.2 The reference source is CSDN, the author is fat and not fat, the original is a link

2 actual operation

2.1 Current Status of Drive Letters

Because I installed a dual system, I need to divide 20G free space under windows first. As for how to allocate 20G, there are a lot of tutorials on the Internet. Viewed under linux as
insert image description here

2.1 Practical operation

  • Practical reference Baidu tutorial 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 ~]#

Guess you like

Origin blog.csdn.net/eettttttt/article/details/131346085