擴容linux的根目錄(實操記錄!!)

前言

僅儘可能,方邊後面參考。
參考連接:https://blog.csdn.net/weixin_43139644/article/details/89948983node

準備動做

  • 1.數據無價,如下全部操做請務必在虛擬機上先操做1次
  • 2.在服務器中加入硬盤;sdb就是本次加入的硬盤
[root@compute11 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  1.8T  0 disk 
├─sda1            8:1    0    2G  0 part /boot
└─sda2            8:2    0  1.8T  0 part 
  └─centos-root 253:0    0  1.8T  0 lvm  /
sdb               8:16   0  1.8T  0 disk

操做步驟:

  • 1.使用 fdisk -l 查看硬盤序號,並用 fdisk 對硬盤操做,格式化成lvm的格式
[root@compute11 ~]# fdisk /dev/sdb
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xf2edcde9.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-3907029167, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-3907029167, default 3907029167): 
Using default value 3907029167
Partition 1 of type Linux and of size 1.8 TiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@compute11 ~]#
  • 2.從新識別硬盤
[root@compute11 ~]# partprobe
  • 3.將剛剛的硬盤從新格式化,格式化爲xfs格式
[root@compute11 ~]# mkfs.xfs /dev/sdb1 
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=122094598 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=488378390, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=238466, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@compute11 ~]#
  • 4.使用lvm命令,對根目錄進行擴容
# 進入lvm模式
[root@compute11 ~]# lvm
# 查看當前的pv卷
lvm> pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <1.82 TiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              476419
  Free PE               0
  Allocated PE          476419
  PV UUID               ZSlskf-Hrdk-4by2-jIUq-bbJD-kmfb-EptRPC

# 新建pv卷
lvm> pvcreate /dev/sdb1
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.

# 再次查看pv卷,已經有兩個pv捲了。
lvm> pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <1.82 TiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              476419
  Free PE               0
  Allocated PE          476419
  PV UUID               ZSlskf-Hrdk-4by2-jIUq-bbJD-kmfb-EptRPC

  "/dev/sdb1" is a new physical volume of "<1.82 TiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               <1.82 TiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               p844T5-gdrK-g63T-8zOT-IcYk-1Ren-32D2fZ

lvm> 

# 查看vg組
lvm> vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <1.82 TiB
  PE Size               4.00 MiB
  Total PE              476419
  Alloc PE / Size       476419 / <1.82 TiB
  Free  PE / Size       0 / 0   
  VG UUID               d7YIEM-gVrC-P6rl-DsH8-IVai-MeTO-9GGP1M

# 將剛剛生成的pv卷 /dev/sdb1 加入到根目錄所在的vg組:centos
lvm> vgextend centos /dev/sdb1
  Volume group "centos" successfully extended

# 再次查看,根目錄所在的vg組:centos 已經擴容成功
lvm> vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <3.64 TiB
  PE Size               4.00 MiB
  Total PE              953350
  Alloc PE / Size       476419 / <1.82 TiB
  Free  PE / Size       476931 / <1.82 TiB
  VG UUID               d7YIEM-gVrC-P6rl-DsH8-IVai-MeTO-9GGP1M
# 看到vg size 增長到了3.64T,Free PE size 也有了1.8T(476931)的大小。(咱們要增長的就是這個PE的大小!!)

lvm> 

# 先查看lv卷
lvm> lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                v9hEnv-KnJa-bM3A-gGgQ-pcXJ-G77d-4RAaZM
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-07-17 14:47:37 +0800
  LV Status              available
  # open                 1
  LV Size                <1.82 TiB
  Current LE             476419
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

# 使用 lvextend 爲根目錄進行擴容
lvm> lvextend -l +476931 /dev/centos/root
  Size of logical volume centos/root changed from <1.82 TiB (476419 extents) to <3.64 TiB (953350 extents).
  Logical volume centos/root successfully resized.

# 再次查看lv卷,LV Size 已經有3.64T啦
lvm> lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                v9hEnv-KnJa-bM3A-gGgQ-pcXJ-G77d-4RAaZM
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-07-17 14:47:37 +0800
  LV Status              available
  # open                 1
  LV Size                <3.64 TiB
  Current LE             953350
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

lvm> exit
  Exiting.
[root@compute11 ~]# 
[root@compute11 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                  95G     0   95G   0% /dev
tmpfs                     95G     0   95G   0% /dev/shm
tmpfs                     95G  670M   94G   1% /run
tmpfs                     95G     0   95G   0% /sys/fs/cgroup
/dev/mapper/centos-root  1.9T  1.6T  252G  87% /
/dev/sda1                2.0G  173M  1.9G   9% /boot
tmpfs                     19G   36K   19G   1% /run/user/0

# 硬盤大小仍是以前大小,再進行多1步:擴容文件系統
[root@compute11 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=121963264 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=487853056, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=238209, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 487853056 to 976230400

# 擴容成功
[root@compute11 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                  95G     0   95G   0% /dev
tmpfs                     95G     0   95G   0% /dev/shm
tmpfs                     95G  670M   94G   1% /run
tmpfs                     95G     0   95G   0% /sys/fs/cgroup
/dev/mapper/centos-root  3.7T  1.6T  2.1T  44% /
/dev/sda1                2.0G  173M  1.9G   9% /boot
tmpfs                     19G   36K   19G   1% /run/user/0
[root@compute11 ~]#
相關文章
相關標籤/搜索