Linux LVM 系统盘的根 / 扩容

本文详细介绍了如何在Linux系统中通过使用LVM进行系统盘的扩容操作,包括利用系统盘所在物理硬盘未使用的空间及新增物理硬盘的方式进行扩容的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. Linux 系统盘的根 / 是 LVM,使用系统盘所在的物理硬盘中未使用的空间进行扩容:
    文本在图片下面
    在这里插入图片描述

    [root@centos7-2009 ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 898M     0  898M   0% /dev
    tmpfs                    910M     0  910M   0% /dev/shm
    tmpfs                    910M  9.6M  901M   2% /run
    tmpfs                    910M     0  910M   0% /sys/fs/cgroup
    /dev/mapper/centos-root   47G  1.3G   46G   3% /
    /dev/sda1               1014M  150M  865M  15% /boot
    tmpfs                    182M     0  182M   0% /run/user/0
    [root@centos7-2009 ~]# fdisk -l
    
    Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000a25d9
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   104857599    51379200   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 50.5 GB, 50457477120 bytes, 98549760 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: 2147 MB, 2147483648 bytes, 4194304 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@centos7-2009 ~]# fdisk /dev/sda
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): n
    Partition type:
       p   primary (2 primary, 0 extended, 2 free)
       e   extended
    Select (default p): p
    Partition number (3,4, default 3): 3
    First sector (104857600-167772159, default 104857600): 
    Using default value 104857600
    Last sector, +sectors or +size{K,M,G} (104857600-167772159, default 167772159): 
    Using default value 167772159
    Partition 3 of type Linux and of size 30 GiB is set
    
    Command (m for help): t
    Partition number (1-3, default 3): 
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
    
    Command (m for help): p
    
    Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000a25d9
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   104857599    51379200   8e  Linux LVM
    /dev/sda3       104857600   167772159    31457280   8e  Linux LVM
    
    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)
    Syncing disks.
    [root@centos7-2009 ~]# ll /dev/sda*
    brw-rw----. 1 root disk 8, 0 Sep 20 19:24 /dev/sda
    brw-rw----. 1 root disk 8, 1 Sep 20 19:24 /dev/sda1
    brw-rw----. 1 root disk 8, 2 Sep 20 19:24 /dev/sda2
    [root@centos7-2009 ~]# reboot 
    Connection closing...Socket close.
    
    Connection closed by foreign host.
    
    Disconnected from remote host(192.168.61.140) at 11:25:12.
    
    Type `help' to learn how to use Xshell prompt.
    [C:\~]$ 
    
    Connecting to 192.168.61.140:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.
    
    WARNING! The remote SSH server rejected X11 forwarding request.
    Last login: Tue Sep 20 19:25:45 2022 from 192.168.61.1
    [root@centos7-2009 ~]# ll /dev/sda*
    brw-rw----. 1 root disk 8, 0 Sep 20 19:25 /dev/sda
    brw-rw----. 1 root disk 8, 1 Sep 20 19:25 /dev/sda1
    brw-rw----. 1 root disk 8, 2 Sep 20 19:25 /dev/sda2
    brw-rw----. 1 root disk 8, 3 Sep 20 19:25 /dev/sda3
    [root@centos7-2009 ~]# fdisk -l
    
    Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000a25d9
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   104857599    51379200   8e  Linux LVM
    /dev/sda3       104857600   167772159    31457280   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 50.5 GB, 50457477120 bytes, 98549760 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: 2147 MB, 2147483648 bytes, 4194304 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@centos7-2009 ~]# df -T /dev/sda1
    Filesystem     Type 1K-blocks   Used Available Use% Mounted on
    /dev/sda1      xfs    1038336 153592    884744  15% /boot
    [root@centos7-2009 ~]# mkfs.ext4 /dev/sda3
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    1966080 inodes, 7864320 blocks
    393216 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2155872256
    240 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, 884736, 1605632, 2654208, 
    	4096000
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   
    
    [root@centos7-2009 ~]# pvcreate /dev/sda3
    WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
      Wiping ext4 signature on /dev/sda3.
      Physical volume "/dev/sda3" successfully created.
    [root@centos7-2009 ~]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               <49.00 GiB / not usable 3.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              12543
      Free PE               1
      Allocated PE          12542
      PV UUID               blYys0-jLwd-uNLn-0y5Q-9Ymi-ecCg-zCjccL
       
      "/dev/sda3" is a new physical volume of "30.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sda3
      VG Name               
      PV Size               30.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               HfSyAk-E37q-o23Z-J7fC-wZMY-q38L-av48iv
       
    [root@centos7-2009 ~]# vgextend centos /dev/sda3
      Volume group "centos" successfully extended
    [root@centos7-2009 ~]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               <49.00 GiB / not usable 3.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              12543
      Free PE               1
      Allocated PE          12542
      PV UUID               blYys0-jLwd-uNLn-0y5Q-9Ymi-ecCg-zCjccL
       
      --- Physical volume ---
      PV Name               /dev/sda3
      VG Name               centos
      PV Size               30.00 GiB / not usable 4.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              7679
      Free PE               7679
      Allocated PE          0
      PV UUID               HfSyAk-E37q-o23Z-J7fC-wZMY-q38L-av48iv
       
    [root@centos7-2009 ~]# vgs
      VG     #PV #LV #SN Attr   VSize  VFree 
      centos   2   2   0 wz--n- 78.99g 30.00g
    [root@centos7-2009 ~]# lvextend -l +100%FREE /dev/mapper/centos-root
      Size of logical volume centos/root changed from 46.99 GiB (12030 extents) to 76.99 GiB (19710 extents).
      Logical volume centos/root successfully resized.
    [root@centos7-2009 ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 898M     0  898M   0% /dev
    tmpfs                    910M     0  910M   0% /dev/shm
    tmpfs                    910M  9.6M  901M   2% /run
    tmpfs                    910M     0  910M   0% /sys/fs/cgroup
    /dev/mapper/centos-root   47G  1.3G   46G   3% /
    /dev/sda1               1014M  150M  865M  15% /boot
    tmpfs                    182M     0  182M   0% /run/user/0
    [root@centos7-2009 ~]# xfs_growfs /
    meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=3079680 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0 spinodes=0
    data     =                       bsize=4096   blocks=12318720, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal               bsize=4096   blocks=6015, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 12318720 to 20183040
    [root@centos7-2009 ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 898M     0  898M   0% /dev
    tmpfs                    910M     0  910M   0% /dev/shm
    tmpfs                    910M  9.6M  901M   2% /run
    tmpfs                    910M     0  910M   0% /sys/fs/cgroup
    /dev/mapper/centos-root   77G  1.3G   76G   2% /
    /dev/sda1               1014M  150M  865M  15% /boot
    tmpfs                    182M     0  182M   0% /run/user/0
    [root@centos7-2009 ~]# 
    
  2. Linux 系统盘的根 / 是 LVM,新增物理硬盘进行扩容:
    文本在图片下面
    在这里插入图片描述

    [root@centos7-2009 ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 898M     0  898M   0% /dev
    tmpfs                    910M     0  910M   0% /dev/shm
    tmpfs                    910M  9.6M  901M   2% /run
    tmpfs                    910M     0  910M   0% /sys/fs/cgroup
    /dev/mapper/centos-root   47G  1.3G   46G   3% /
    /dev/sda1               1014M  150M  865M  15% /boot
    tmpfs                    182M     0  182M   0% /run/user/0
    [root@centos7-2009 ~]# fdisk -l
    
    Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000a25d9
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   104857599    51379200   8e  Linux LVM
    
    Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 50.5 GB, 50457477120 bytes, 98549760 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: 2147 MB, 2147483648 bytes, 4194304 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@centos7-2009 ~]# pvcreate /dev/sdb
      Physical volume "/dev/sdb" successfully created.
    [root@centos7-2009 ~]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               <49.00 GiB / not usable 3.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              12543
      Free PE               1
      Allocated PE          12542
      PV UUID               blYys0-jLwd-uNLn-0y5Q-9Ymi-ecCg-zCjccL
       
      "/dev/sdb" is a new physical volume of "20.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb
      VG Name               
      PV Size               20.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               Nq2B5X-bEg0-UjV5-CIsU-26hK-w83d-KqKsx6
       
    [root@centos7-2009 ~]# vgextend centos /dev/sdb
      Volume group "centos" successfully extended
    [root@centos7-2009 ~]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               <49.00 GiB / not usable 3.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              12543
      Free PE               1
      Allocated PE          12542
      PV UUID               blYys0-jLwd-uNLn-0y5Q-9Ymi-ecCg-zCjccL
       
      --- Physical volume ---
      PV Name               /dev/sdb
      VG Name               centos
      PV Size               20.00 GiB / not usable 4.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              5119
      Free PE               5119
      Allocated PE          0
      PV UUID               Nq2B5X-bEg0-UjV5-CIsU-26hK-w83d-KqKsx6
       
    [root@centos7-2009 ~]# vgs
      VG     #PV #LV #SN Attr   VSize  VFree 
      centos   2   2   0 wz--n- 68.99g 20.00g
    [root@centos7-2009 ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 898M     0  898M   0% /dev
    tmpfs                    910M     0  910M   0% /dev/shm
    tmpfs                    910M  9.6M  901M   2% /run
    tmpfs                    910M     0  910M   0% /sys/fs/cgroup
    /dev/mapper/centos-root   47G  1.3G   46G   3% /
    /dev/sda1               1014M  150M  865M  15% /boot
    tmpfs                    182M     0  182M   0% /run/user/0
    [root@centos7-2009 ~]# lvextend -l +100%FREE /dev/mapper/centos-root 
      Size of logical volume centos/root changed from 46.99 GiB (12030 extents) to 66.99 GiB (17150 extents).
      Logical volume centos/root successfully resized.
    [root@centos7-2009 ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 898M     0  898M   0% /dev
    tmpfs                    910M     0  910M   0% /dev/shm
    tmpfs                    910M  9.6M  901M   2% /run
    tmpfs                    910M     0  910M   0% /sys/fs/cgroup
    /dev/mapper/centos-root   47G  1.3G   46G   3% /
    /dev/sda1               1014M  150M  865M  15% /boot
    tmpfs                    182M     0  182M   0% /run/user/0
    [root@centos7-2009 ~]# xfs_growfs /
    meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=3079680 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0 spinodes=0
    data     =                       bsize=4096   blocks=12318720, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal               bsize=4096   blocks=6015, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 12318720 to 17561600
    [root@centos7-2009 ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 898M     0  898M   0% /dev
    tmpfs                    910M     0  910M   0% /dev/shm
    tmpfs                    910M  9.6M  901M   2% /run
    tmpfs                    910M     0  910M   0% /sys/fs/cgroup
    /dev/mapper/centos-root   67G  1.3G   66G   2% /
    /dev/sda1               1014M  150M  865M  15% /boot
    tmpfs                    182M     0  182M   0% /run/user/0
    [root@centos7-2009 ~]# 
    
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐晓伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值