1、扩容-parted >2G

[root@localhost ~]# fdisk -l
 
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000a597b
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    20971519     9436160   8e  Linux LVM
 
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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-root: 8585 MB, 8585740288 bytes, 16769024 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: 1073 MB, 1073741824 bytes, 2097152 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@localhost ~]# part
parted     partprobe  partx      
[root@localhost ~]# part
parted     partprobe  partx      
[root@localhost ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt                                                      
(parted) mkpart                                                           
Partition name?  []? sdb1                                                 
File system type?  [ext2]?                                                
Start? 0                                                                  
End? 100%                                                                 
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i                                                          
(parted) p                                                                
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
 
Number  Start   End     Size    File system  Name  Flags
 1      17.4kB  10.7GB  10.7GB               sdb1
 
(parted) toggle 1 lvm                                                     
(parted) p                                                                
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
 
Number  Start   End     Size    File system  Name  Flags
 1      17.4kB  10.7GB  10.7GB               sdb1  lvm
 
(parted) q                                                                
Information: You may need to update /etc/fstab.
 
[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# vgdisplay
  --- 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               <9.00 GiB
  PE Size               4.00 MiB
  Total PE              2303
  Alloc PE / Size       2303 / <9.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               BP6Pfn-Ft5e-fwqV-2E1M-Srkm-ckzc-1dv7lD
   
[root@localhost ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended
[root@localhost ~]# lvdis[lay
> ^C
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                We7rNW-MicQ-SiYp-e3ge-Ls6x-Xu9K-H6xS5W
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-05-25 14:59:25 +0800
  LV Status              available
  # open                 2
  LV Size                1.00 GiB
  Current LE             256
  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                OfMRMu-zrIr-pxxn-HVP0-WSgB-4Uio-cfft1P
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-05-25 14:59:25 +0800
  LV Status              available
  # open                 1
  LV Size                <8.00 GiB
  Current LE             2047
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
[root@localhost ~]# lvextend -l +100%free /dev/centos/root 
  Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 17.99 GiB (4606 extents).
  Logical volume centos/root successfully resized.
[root@localhost ~]# mkfs
mkfs         mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.xfs     
[root@localhost ~]# xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=524032 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2096128, 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 2096128 to 4716544
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
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/mapper/centos-root   18G  1.3G   17G   7% /
/dev/sda1               1014M  151M  864M  15% /boot
tmpfs                    1.6G     0  1.6G   0% /run/user/0

2、挂载-parted >2G

[root@localhost ~]# fdisk -l
 
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000a597b
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    20971519     9436160   8e  Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
 
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: gpt
Disk identifier: 6DE0E303-988A-4007-AA55-BFB4B61746A8
 
 
#         Start          End    Size  Type            Name
 1           34     20971486     10G  Linux LVM       sdb1
 
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 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-root: 19.3 GB, 19318964224 bytes, 37732352 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: 1073 MB, 1073741824 bytes, 2097152 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@localhost ~]# parted /dev/sdc
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt                                                      
(parted) mkpart                                                           
Partition name?  []? sdc1                                                 
File system type?  [ext2]?                                                
Start? 0                                                                  
End? 100%                                                                 
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i                                                          
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdc: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
 
Number  Start   End     Size    File system  Name  Flags
 1      17.4kB  10.7GB  10.7GB               sdc1
 
(parted) toggle 1 lvm                                                     
(parted) p                                                                
Model: VMware Virtual disk (scsi)
Disk /dev/sdc: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
 
Number  Start   End     Size    File system  Name  Flags
 1      17.4kB  10.7GB  10.7GB               sdc1  lvm
 
(parted) q                                                                
Information: You may need to update /etc/fstab.
 
[root@localhost ~]# pvcreate /dev/sdc1                                    
  Physical volume "/dev/sdc1" successfully created.
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  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               18.99 GiB
  PE Size               4.00 MiB
  Total PE              4862
  Alloc PE / Size       4862 / 18.99 GiB
  Free  PE / Size       0 / 0   
  VG UUID               BP6Pfn-Ft5e-fwqV-2E1M-Srkm-ckzc-1dv7lD
   
[root@localhost ~]# vgcreate test /dev/sdc1 
  Volume group "test" successfully created
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                We7rNW-MicQ-SiYp-e3ge-Ls6x-Xu9K-H6xS5W
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-05-25 14:59:25 +0800
  LV Status              available
  # open                 2
  LV Size                1.00 GiB
  Current LE             256
  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                OfMRMu-zrIr-pxxn-HVP0-WSgB-4Uio-cfft1P
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-05-25 14:59:25 +0800
  LV Status              available
  # open                 1
  LV Size                17.99 GiB
  Current LE             4606
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
[root@localhost ~]# lvcreate -l +100%free test -n data
  Logical volume "data" created.
[root@localhost ~]# mkfs
mkfs         mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.xfs     
[root@localhost ~]# mkfs.xfs /dev/test/data
meta-data=/dev/test/data         isize=512    agcount=4, agsize=655104 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2620416, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/test/data /data/
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
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/mapper/centos-root   18G  1.3G   17G   7% /
/dev/sda1               1014M  151M  864M  15% /boot
tmpfs                    1.6G     0  1.6G   0% /run/user/0
/dev/mapper/test-data     10G   33M   10G   1% /data
[root@localhost ~]# vim /etc/fstab 
-bash: vim: command not found
[root@localhost ~]# vi /etc/fstab