CentOS 7 非 LVM 硬盘简单扩容

CentOS 7 非 LVM 硬盘简单扩容

查看分区信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
└─sda1 8:1 0 8G 0 part /
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 1024M 0 rom
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 900M 0 900M 0% /dev
tmpfs 919M 0 919M 0% /dev/shm
tmpfs 919M 17M 903M 2% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/sda1 8.0G 3.8G 4.3G 48% /
tmpfs 184M 0 184M 0% /run/user/0

重新分区

用 cfdisk 也行,反正就是把原来的分区删了新建一个然后保存

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
61
62
63
64
65
66
67
[root@localhost ~]# fdisk  /dev/sda
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): p

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: 0x00095067

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 16777215 8387584 83 Linux

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): p

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: 0x00095067

Device Boot Start End Blocks Id System

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):
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): p

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: 0x00095067

Device Boot Start End Blocks Id System
/dev/sda1 2048 41943039 20970496 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.

刷新分区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@localhost ~]# partprobe /dev/sda
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
└─sda1 8:1 0 20G 0 part /
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 1024M 0 rom
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 900M 0 900M 0% /dev
tmpfs 919M 0 919M 0% /dev/shm
tmpfs 919M 17M 903M 2% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/sda1 8.0G 3.8G 4.2G 48% /
tmpfs 184M 0 184M 0% /run/user/0

扩容分区

如果磁盘格式是 xfs:

1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# xfs_growfs /dev/sda1
meta-data=/dev/sda1 isize=512 agcount=4, agsize=524224 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2096896, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
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 2096896 to 5242624

如果磁盘格式是 ext4:

1
[root@localhost ~]# resize2fs /dev/sda1

扩容完成

1
2
3
4
5
6
7
8
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 900M 0 900M 0% /dev
tmpfs 919M 0 919M 0% /dev/shm
tmpfs 919M 17M 903M 2% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/sda1 20G 3.8G 17G 19% /
tmpfs 184M 0 184M 0% /run/user/0

参考资料:

Centos 7如何进行磁盘扩容(LVM+非LVM)_centos磁盘扩容_氧化心的博客-CSDN博客