0、思路
建立一個新的邏輯分區,將新的邏輯分區格式化ext3(或其餘類型)的文件系統,mount到磁盤空間不夠的文件系統,就跟原來的分區/文件系統同樣的使用node
一、準備
1.1 注意使用VMware自帶的Expand功能不能有Snapshot存在,因此在expand以前先把全部的Snapshot刪掉了linux
1.2 爲了以防萬一,把VMware虛擬機copy了一份備用。centos
二、查看掛載點
-
-
-
/
dev/mapper/centos-root 36G 5.4G 31G 15
-
-
-
-
-
/
dev/sda1 497M 125M 373M 26
-
三、擴展VMWare硬盤空間
3.1 關閉Vmware 的 Linux系統ruby
3.2 在VMWare菜單中設置:app
VM -> Settings… -> Hardware -> Hard Disk -> Utilities -> Expandide
輸入你想要擴展到多少G,假設新增長了 40G
ui
四、對新增長的硬盤進行分區
執行步驟:atom
- 執行「fdisk /dev/sda」,進入到fdisk
- 輸入p指令,查看已分區數量(有兩個 /dev/sda1 /dev/sda2)
- 輸入 n {new partition}指令,新增長一個分區
- 輸入p {primary partition},分區類型選擇爲主分區
- 輸入分區號 3 {partition number} ,分區號選3(上面顯示我已經有2個分區了)
- 回車 默認(起始扇區)
- 回車 默認(結束扇區)
- 輸入t {change partition id}指令,修改分區類型
- 按提示輸入剛纔的分區號3
- 輸入分區類型 8e {Linux LVM partition}
- 輸入w指令,將以上改動寫入分區表
- 最後完成,退出fdisk命令
-
[root@vnode1 ~]# fdisk /dev/sda
-
歡迎使用 fdisk (util-linux 2.23.2)。
-
-
-
-
-
-
-
設備 Boot
Start End Blocks Id System
-
/dev/sda1 * 2048 1026047 512000 83 Linux
-
/dev/sda2 1026048 83886079 41430016 8e Linux LVM
-
-
-
-
p primary (2 primary, 0 extended, 2 free)
-
-
-
-
起始 扇區 (83886080-167772159,默認爲 83886080):
-
-
Last 扇區, +扇區 or +size{K,M,G} (83886080-167772159,默認爲 167772159):
-
-
分區 3 已設置爲 Linux 類型,大小設爲 40 GiB
-
-
-
-
-
已將分區「Linux」的類型更改成「Linux LVM」
-
-
-
The partition table has been altered!
-
-
Calling ioctl() to re-read partition table.
-
-
WARNING: Re-reading the partition table failed with error 16: 設備或資源忙.
-
The kernel still uses the old table. The new table will be used at
-
the next reboot or after you run partprobe(8) or kpartx(8)
-
重啓系統:
[root@vnode1 ~]# shutdown -r now (很重要)centos7
四、對新增長的硬盤格式化
-
[
root@vnode1 ~]# mkfs.ext3 /dev/sda3
-
mke2fs
1.42.9 (28-Dec-2013)
-
-
-
-
-
Stride=
0 blocks, Stripe width=0 blocks
-
2621440 inodes, 10485760 blocks
-
524288 blocks (5.00%) reserved for the super user
-
-
Maximum filesystem blocks=
4294967296
-
-
32768 blocks per group, 32768 fragments per group
-
-
Superblock backups stored
on blocks:
-
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
-
-
-
Allocating
group tables: 完成
-
-
Creating journal (32768 blocks): 完成
-
Writing superblocks and filesystem accounting information: 完成
五、添加新LVM到已有的LVM組,實現擴容
-
-
-
WARNING: ext3 signature detected
on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
-
Wiping ext3 signature on /dev/sda3.
-
Physical volume
"/dev/sda3" successfully created
-
lvm> vgextend centos /dev/sda3
-
Volume group
"centos" successfully extended
-
lvm> lvextend -L +
39.9G /dev/mapper/centos-root
-
Rounding size
to boundary between physical extents: 39.90 GiB
-
Size
of logical volume centos/root changed from 35.47 GiB (9080 extents) to 75.37 GiB (19295 extents).
-
Logical volume root successfully resized.
-
-
-
-
-
PV Size
39.51 GiB / not usable 3.00 MiB
-
Allocatable yes (
but full)
-
-
-
-
-
PV UUID vtNvX3-b1yw-ePoh-YGHQ-tDhL-x0ru-mfts3k
-
-
-
-
-
PV Size
40.00 GiB / not usable 4.00 MiB
-
-
-
-
-
-
PV UUID jWqvcF-R53u-ZeAy-zO2L-PbtI-
51VP-yHNZ1g
-
-
-
-
備註:spa
-
-
lvm
> pvcreate /dev/sda3 這是初始化剛纔的分區,必須的
-
lvm
>vgextend centos /dev/sda3 將初始化過的分區加入到虛擬卷組vg_dc01
-
lvm
>lvextend -L +39.9G /dev/mapper/centos-root 擴展已有卷的容量(注意容量大小)
-
lvm
>pvdisplay 查看卷容量,這時你會看到一個很大的捲了
-
以上只是卷擴容了,下面是文件系統的真正擴容,輸入如下命令:
-
-
resize2fs
1.42.9 (28-Dec-2013)
-
resize2fs: Bad magic number in super-block 當嘗試打開 /dev/mapper/centos-root 時
-
報錯:當嘗試打開 /dev/mapper/centos-root 時 找不到有效的文件系統超級塊
由於個人centos7的某些分區用的是xfs的文件系統(使用df -T查看便可知道)
-
-
-
/
dev/mapper/centos-root xfs 37173520 5574340 31599180 15
-
devtmpfs devtmpfs 3987400 0 3987400 0
-
tmpfs tmpfs 3997856 0 3997856 0
-
tmpfs tmpfs 3997856 8628 3989228 1
-
tmpfs tmpfs 3997856 0 3997856 0
-
/
dev/sda1 xfs 508588 127152 381436 26
-
tmpfs tmpfs 799572 0 799572 0
-
將resize2fs替換爲xfs_growfs,從新執行一遍便可,以下:
-
[
root@vnode1 ~]# xfs_growfs /dev/mapper/centos-root
-
meta-
data=/dev/mapper/centos-root isize=256 agcount=4, agsize=2324480 blks
-
=
sectsz=512 attr=2, projid32bit=1
-
-
data = bsize=4096 blocks=9297920, imaxpct=25
-
-
naming =version
2 bsize=4096 ascii-ci=0 ftype=0
-
log =
internal bsize=4096 blocks=4540, version=2
-
=
sectsz=512 sunit=0 blks, lazy-count=1
-
realtime =none extsz=
4096 blocks=0, rtextents=0
-
data blocks changed from 9297920 to 19758080
最後再運行下:df -h
便可看到擴容後的磁盤空間
-
-
-
/
dev/mapper/centos-root 76G 5.4G 71G 8
-
-
-
-
-
/
dev/sda1 497M 125M 373M 26
-
ps:修復 unknown 區 vgreduce --removemissing centos
--- Physical volume --- PV Name [unknown] VG Name centos PV Size 10.00 GiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 2559 Free PE 2559 Allocated PE 0 PV UUID VCwaaP-hhX8-YcSg-Cqji-ctob-AAod-wRnOLO