centos7 根目錄增加磁碟空間
阿新 • • 發佈:2018-12-27
一、問題
我建立了一個 VMware 虛擬機器用來安裝 OpenStack Kolla,由於建立虛擬機器時僅給根目錄分配 8G 的空間,後續明顯不夠用,想再擴充套件 10G 的空間。
檢視當前磁碟
[[email protected] ~]# 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: 0x000d78d5
Device Boot Start End Blocks Id System
/dev/sda1 2048 20971519 10484736 8e Linux LVM
/dev/sda2 20971520 41943039 10485760 83 Linux
Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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
......
二、解決
由於 /dev/sda1
分割槽是 LVM 型別,可以進行擴充套件
首先,給虛擬機器加塊 10G 大小硬碟,然後重啟
看到已經存在盤 /dev/sdb
了,大小10.7 GB
[[email protected] ~]# 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: 0x000d78d5
Device Boot Start End Blocks Id System
/dev/sda1 2048 20971519 10484736 8e Linux LVM
/dev/sda2 20971520 41943039 10485760 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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
......
建立分割槽 /dev/sdb
,注意選擇 8e 也即是 LVM 型別
# 後面是我寫的註釋
[[email protected] ~]# 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 0xf9d73537.
Command (m for help): n # 輸入命令n,建立一個新的分割槽
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p # 輸入 p,或者直接按回車
Partition number (1-4, default 1): 1 # 輸入 1,或者直接按回車
First sector (2048-20971519, default 2048): # 直接按回車
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): # 直接按回車
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): t # 輸入命令 t,定義新分割槽的型別
Selected partition 1
Hex code (type L to list all codes): 8e # 輸入 8e,8e是Linux LVM型別的程式碼
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w # 輸入命令 w 完成修改
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
看到已經存在分割槽 /dev/sdb1
了
[[email protected] ~]# 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: 0x000d78d5
Device Boot Start End Blocks Id System
/dev/sda1 2048 20971519 10484736 8e Linux LVM
/dev/sda2 20971520 41943039 10485760 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xf9d73537
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 8e Linux LVM
Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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
......
建立 PV
[root@kolla-queens ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
檢視 LV,顯示 LV Path 為 /dev/centos/root
,VG Name 為 centos
[[email protected] ~]# lvdisplay
......
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID eh3XHa-w5Hy-pbGA-qqbi-p4j6-H5Gl-LdBRlu
LV Write Access read/write
LV Creation host, time localhost, 2016-09-13 23:42:05 +0800
LV Status available
# open 1
LV Size <8.00 GiB
Current LE 2047
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
擴充套件 VG centos
[[email protected] ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended
擴充套件 LV /dev/centos/root
[[email protected] ~]# lvextend /dev/centos/root /dev/sdb1
Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 17.99 GiB (4606 extents).
Logical volume centos/root successfully resized.
如果系統是用的XFS檔案系統,需要要執行以下命令:
xfs_growfs /dev/centos/root
如果系統不是使用XFS檔案系統,需要執行以下命令:
resize2fs /dev/centos/root
我這是xfs檔案系統
所以執行
[root@kolla-queens ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=524032 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=2096128, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 2096128 to 4716544
檢視磁碟空間資訊,/dev/mapper/centos-root
已經擴充到 18 G了
[root@kolla-queens ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 2.0G 16G 12% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.7M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 781M 0 781M 0% /run/user/0