從yum提示空間不足到根分區擴容

1.系統版本(VMware 虛擬機)linux

[root@ansible-admin ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

2.當執行yum安裝軟件時報以下錯git

Error: Error writing to file /var/cache/yum/x86_64/7/epel/gen/filelists_db.sqlite: [Errno 28] No space left on device

是因爲磁盤空間不夠,清除了部分無用日誌以後再次安裝sql

#yum install gitlab-ce -y
………………………………
Transaction Summary
=====================================================================================================================
Install  1 Package
Total download size: 378 M
Installed size: 378 M
Is this ok [y/d/N]: y
Downloading packages:
Error downloading packages:
  gitlab-ce-9.5.2-ce.0.el7.x86_64: Insufficient space in download directory /var/cache/yum/x86_64/7/gitlab-ce/packages
    * free   312 M
    * needed 378 M

3.提示空間不足,剩餘空間只有312M,查看磁盤使用空間發現根分區確實只剩313Mapp

[root@ansible-admin ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root  6.2G  5.9G  313M  96% /  #擴容的對象
devtmpfs             482M     0  482M   0% /dev
tmpfs                493M     0  493M   0% /dev/shm
tmpfs                493M   50M  443M  11% /run
tmpfs                493M     0  493M   0% /sys/fs/cgroup
/dev/sda1           1014M  139M  876M  14% /boot
tmpfs                 99M     0   99M   0% /run/user/0
/dev/sr0             680M  680M     0 100% /mnt
[root@ansible-admin boot]# df -h /var (/var目錄確實爲312M)
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root  6.2G  5.9G  312M  96% /

4.因而開始擴容根分區ide

 1)添加磁盤gitlab

   虛擬機——設置——硬盤——添加——下一步——選擇磁盤類型——填寫磁盤大小this

 2)查看磁盤spa

[root@ansible-admin boot]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes, 16777216 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: 0x000b9a5e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    16777215     7339008   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 label type: dos
Disk identifier: 0x4fddc909

   Device Boot      Start         End      Blocks   Id  System

Disk /dev/mapper/cl-root: 6652 MB, 6652166144 bytes, 12992512 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/cl-swap: 859 MB, 859832320 bytes, 1679360 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

(3)爲新磁盤建立分區3d

建立分區:
[root@ansible-admin boot]# 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.


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):  #默認爲1(由於是新磁盤第一次建立分區)
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): #這裏我只建立一個分區因此默認是使用全部空間
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.
讓系統從新讀取分區表:
[root@ansible-admin boot]# partprobe 
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

(4)擴容日誌

因爲sda已經爲LVM因此能夠直接爲其擴容,無需再建立新的LVM

建立物理卷(PV):

使用pvcreate命令建立物理卷,pvdisplay查看物理卷信息

建立物理卷:
[root@ansible-admin boot]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
查看物理卷信息:
[root@ansible-admin boot]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               cl   #原有盤上的PV
  PV Size               7.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1791
  Free PE               0
  Allocated PE          1791
  PV UUID               beyPTU-i2Ny-ltMw-0tfr-Me0b-Sz0Z-ybS4cy
   
  "/dev/sdb1" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name        #新建的PV的VG name是空的,下一步就是把PV加入VG       
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               5N1q14-vf7Y-U1dm-1tkf-ZxAQ-16lE-pW2M5F

 查看原VG的狀況

[root@ansible-admin boot]# vgdisplay 
  --- Volume group ---
  VG Name               cl  #注意記錄此名字,擴容時將新的pv加入指定的名字
  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               7.00 GiB
  PE Size               4.00 MiB
  Total PE              1791
  Alloc PE / Size       1791 / 7.00 GiB
  Free  PE / Size       0 / 0   #發現空閒空間爲0(以G計算)
  VG UUID               l4mGeJ-090j-NZ1U-UOhI-c56R-0mtM-xiBm9h

擴展卷組,/dev/sdb物理卷添加到cl卷組中

再查看VG狀況,能夠看到VG大小變化,空餘空間

將新的VG空間劃入LV(擴容lv_root

直接擴展10G/root分區,不用umount,也不須要重啓擴張多大可根據添加的磁盤大小自由支配

[root@ansible-admin boot]# lvextend -L +10G  /dev/mapper/cl-root 
  Size of logical volume cl/root changed from 6.20 GiB (1586 extents) to 16.20 GiB (4146 extents).
  Logical volume cl/root successfully resized.

也能夠使用命令

# lvextend -l +50%FREE /dev/mapper/cl-root表示將剩餘空間的50%劃入LV

使用xfs_growfs命令在線調整xfs格式文件系統大小(CentOS6使用resize2fs

#xfs_growfs /dev/cl/root (由於CentOS7默認文件系統類型爲xfs

最後咱們看到邏輯卷分區已經動態擴容到了11G

至此一次CentOS7 根分區擴容順利完成

相關文章
相關標籤/搜索