Ching-Chuan Chen's Blogger

Statistics, Machine Learning and Programming

0%

Extend The Disk Space of CentOS 7 VM

這篇主要是紀錄怎麼在CentOS 7 VM上延展Disk

基本上,我是參考這篇做出來的

首先,當然你要先把VM的設定打開,將硬碟空間加大

之後,回到VM操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 對disk做操作
fdisk /dev/sda
# 用 p > d > 2 > n > p > 2 > t > 2 > 8e > p > w 這個順序來操作
# p是print,d是刪除,裡面的2都是選擇第二個分區的意思
# n是新增,t應該是align,8e是某個位置,w是寫入

## d之前
# Device Boot Start End Blocks Id System
# /dev/sda1 * 2048 2099199 1048576 83 Linux
# /dev/sda2 2099200 83886079 40893440 8e Linux LVM
## t之後 (我把硬碟從40G變成600G)
# Device Boot Start End Blocks Id System
# /dev/sda1 * 2048 2099199 1048576 83 Linux
# /dev/sda2 2099200 1258291199 628096000 8e Linux LVM

# 然後重開
reboot
# resize 你修改的硬碟

# 列出目前空間
df -h
# Filesystem Size Used Avail Use% Mounted on
# /dev/mapper/centos_jamalvm01-root 35G 1.6G 34G 5% /
# devtmpfs 3.8G 0 3.8G 0% /dev
# tmpfs 3.9G 0 3.9G 0% /dev/shm
# tmpfs 3.9G 12M 3.8G 1% /run
# tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
# /dev/sda1 1014M 222M 793M 22% /boot
# tmpfs 781M 0 781M 0% /run/user/0

pvresize /dev/sda2
# Physical volume "/dev/sda2" changed
# 1 physical volume(s) resized / 0 physical volume(s) not resized

lvextend -l +100%FREE /dev/mapper/centos_jamalvm01-root
# Size of logical volume centos_jamalvm01/root changed from <35.00 GiB (8959 extents) to <595.00 GiB (152319 extents).
# Logical volume centos_jamalvm01/root successfully resized.

xfs_growfs /
# meta-data=/dev/mapper/centos_jamalvm01-root isize=512 agcount=4, agsize=2293504 blks
# = sectsz=512 attr=2, projid32bit=1
# = crc=1 finobt=0 spinodes=0
# data = bsize=4096 blocks=9174016, imaxpct=25
# = sunit=0 swidth=0 blks
# naming =version 2 bsize=4096 ascii-ci=0 ftype=1
# log =internal bsize=4096 blocks=4479, version=2
# = sectsz=512 sunit=0 blks, lazy-count=1
# realtime =none extsz=4096 blocks=0, rtextents=0
# data blocks changed from 9174016 to 155974656

# 列出目前空間
df -h
# Filesystem Size Used Avail Use% Mounted on
# /dev/mapper/centos_jamalvm01-root 595G 1.6G 594G 1% /
# devtmpfs 3.8G 0 3.8G 0% /dev
# tmpfs 3.9G 0 3.9G 0% /dev/shm
# tmpfs 3.9G 12M 3.8G 1% /run
# tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
# /dev/sda1 1014M 222M 793M 22% /boot
# tmpfs 781M 0 781M 0% /run/user/0

這樣就搞定了~