centos7根分區擴容過程。

根分區是LVM時

查看磁盤空間

[root@xiaoagiao /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  1.3G   16G   8% /            #根分區大小爲17G
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.5M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/sr0                 918M  918M     0 100% /media
/dev/sda1               1014M  133M  882M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0

查看磁盤分區情況

[root@xiaoagiao /]# fdisk -l

Disk /dev/sda: 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 label type: dos
Disk identifier: 0x000e174e

   Device Boot      Start         End     Blocks   Id   System
/dev/sda1   *        2048     2099199    1048576    83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM    #/dev/sda2就是根分區,默認爲LVM

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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

步驟

  1. 關機,添加一塊新的磁盤
    在這裏插入圖片描述2. 查看新加入的磁盤
[root@xiaoagiao ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0  100G  0 disk                         #sdb 大小爲100g
sr0              11:0    1  918M  0 rom  /media
  1. 對sdb進行分區
[root@xiaoagiao ~]# fdisk /dev/sdb                     #對/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 0xb6372483.

Command (m for help): m                            #m:顯示幫助
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n              #創建一塊新的分區
Partition type:
   p   primary (0 primary, 0 extended, 4 free)             #p:主分區
   e   extended                                            #e:擴展分區
Select (default p): p
Partition number (1-4, default 1): 1   #分區編號sdb1
First sector (2048-209715199, default 2048):   #分區開始柱面編號,一般默認
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +90G    #分區大小
Partition 1 of type Linux and of size 90 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.
  1. 刷新一下磁盤,把心分區做成pv
[root@xiaoagiao ~]# partprobe /dev/sdb
[root@xiaoagiao ~]# partprobe /dev/sdb1         #刷新磁盤,讓系統找到新添加的磁盤


[root@xiaoagiao ~]# pvcreate /dev/sdb1                   #將/dev/sdb1做成pv
  Physical volume "/dev/sdb1" successfully created.
[root@xiaoagiao ~]# pvs                                  #查看pv信息
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  centos lvm2 a--  <19.00g     0 
  /dev/sdb1         lvm2 ---   90.00g 90.00g
[root@xiaoagiao ~]# pvdisplay                    #pv詳細信息
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               exe6Gy-94VE-9UAH-6qCG-DB7k-PWME-6bz4u6
   
  "/dev/sdb1" is a new physical volume of "90.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               90.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               sHKVIM-KNWc-hbtx-8gYL-b24l-CxQa-SSPmRm
  1. 將新添加的pv擴展到root的vg中
[root@xiaoagiao ~]# vgs           # 先查看當前vg情況
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   1   2   0 wz--n- <19.00g    0          #現在根分區的vg名字爲centos ,大小爲小於19g
  
[root@xiaoagiao ~]# vgextend centos /dev/sdb1    #將/dev/sdb1加入到centos中
  Volume group "centos" successfully extended
[root@xiaoagiao ~]# vgs                          #再次查看vg,大小爲108.9g
  VG     #PV #LV #SN Attr   VSize   VFree  
  centos   2   2   0 wz--n- 108.99g <90.00g     
[root@xiaoagiao ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  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               108.99 GiB
  PE Size               4.00 MiB
  Total PE              27902
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       23039 / <90.00 GiB
  VG UUID               VWTn40-zXfH-77PH-riAc-HC1U-5lqQ-1juay8
  1. 擴展根分區lv邏輯卷
[root@xiaoagiao ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <17.00g                                                    
  swap centos -wi-ao----   2.00g                                                    
[root@xiaoagiao ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/root          #查看詳情得知邏輯卷名稱爲/dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                X1J3Oq-1NCY-pyv2-UmcC-5PtK-Maf5-5YWJto
  LV Write Access        read/write
  LV Creation host, time xiaoagiao, 2020-02-15 17:41:52 +0800
  LV Status              available
  # open                 1
  LV Size                <17.00 GiB                 #大小小於17G
  Current LE             4351
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                m4d0ur-Iz58-UAfd-tIPd-N5gM-Eqf8-NQvbvv
  LV Write Access        read/write
  LV Creation host, time xiaoagiao, 2020-02-15 17:41:53 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
[root@xiaoagiao ~]# lvextend -l +100%FREE /dev/centos/root  #擴展邏輯卷大小,-l:指定大小,+100%FREE:指定全部可用空間
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 106.99 GiB (27390 extents).
  Logical volume centos/root successfully resized.

[root@xiaoagiao ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 106.99g       #現在根分區物理卷大小106.99g                                             
  swap centos -wi-ao----   2.00g   
  1. 最後:刷新根分區 xfs_growfs /dev/centos/root
  • 由於文件系統屬於xfs,所以使用xfs_growfs,resize2fs無效
[root@xiaoagiao mapper]# xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, 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 4455424 to 28047360

[root@xiaoagiao mapper]# df -h        #再次查看,根分區成功擴容到107G
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  107G  1.3G  106G   2% /
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.5M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/sr0                 918M  918M     0 100% /media
/dev/sda1               1014M  133M  882M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章