1. 程式人生 > >從yum提示空間不足到根分區擴容

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

map 擴展卷 bsp ica /var/ 類型 pvcreate 提示 success

記錄一次安裝軟件的報錯

                                                                  ——[email protected]

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

[[email protected] ~]# cat /etc/redhat-release

CentOS Linux release 7.3.1611 (Core)

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

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

是由於磁盤空間不夠,清除了部分無用日誌之後再次安裝

#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,查看磁盤使用空間發現根分區確實只剩313M

[[email protected] ~]# 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

[[email protected] boot]# df -h /var /var目錄確實為312M

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/cl-root 6.2G 5.9G 312M 96% /

4.於是開始擴容根分區

1)添加磁盤

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

2)查看磁盤

[[email protected] 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)為新磁盤創建分區

創建分區:

[[email protected] 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.

讓系統重新讀取分區表:

[[email protected] 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查看物理卷信息

創建物理卷:

[[email protected] boot]# pvcreate /dev/sdb1

Physical volume "/dev/sdb1" successfully created.

查看物理卷信息:

[[email protected] 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 #新建的PVVG 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的情況

[[email protected] 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,也不需要重啟擴張多大可根據添加的磁盤大小自由支配

[[email protected] 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 根分區擴容順利完成

若為非商業用途,轉發請註明出處。

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