centos 7 扩容根分区(非LVM)

Posted 小叶子i

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos 7 扩容根分区(非LVM)相关的知识,希望对你有一定的参考价值。

1.磁盘原来只有30G,在vmware workstation中扩展到了100G,但是还是需要在系统中扩容一下才行

centos


2.磁盘各个目录占用情况和各分区大小

[root@localhost ~]# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009f262

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 4812799 2098176 82 Linux swap / Solaris
/dev/sda3 4812800 62914559 29050880 83 Linux
[root@localhost ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 30G 4.0G 26G 14% /
devtmpfs devtmpfs 939M 0 939M 0% /dev
tmpfs tmpfs 956M 0 956M 0% /dev/shm
tmpfs tmpfs 956M 11M 945M 2% /run
tmpfs tmpfs 956M 0 956M 0% /sys/fs/cgroup
/dev/sda1 xfs 312M 155M 157M 50% /boot
tmpfs tmpfs 192M 8.2k 192M 1% /run/user/42
tmpfs tmpfs 192M 0 192M 0% /run/user/0

上面所示,虽然/dev/sda显示共有107GB,但是根目录仍然只有30GB。

3./dev/sda3挂载在根目录上,我们删掉这个/目录,但是切记不要保存。

[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: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009f262

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 4812799 2098176 82 Linux swap / Solaris
/dev/sda3 4812800 62914559 29050880 83 Linux

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partitions system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): d ------------ 【d为删除一个分区】
Partition number (1-3, default 3): 3 --------【我们要删除sda上的第三个主分区,挂载在/目录上,所以我们删除这个目录

/dev/sda3,】


Partition 3 is deleted

Command (m for help): n --------【新建一个分区】
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p ---------【主分区】
Partition number (3,4, default 3): 3
First sector (4812800-209715199, default 4812800):
Using default value 4812800
Last sector, +sectors or +sizeK,M,G (4812800-209715199, default 209715199):
Using default value 209715199
Partition 3 of type Linux and of size 97.7 GiB is set

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009f262

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 4812799 2098176 82 Linux swap / Solaris
/dev/sda3 4812800 209715199 102451200 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.
[root@localhost ~]# partprobe /dev/sda 【刷新根分区】
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 300M 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 97.7G 0 part /
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# df -TH 【 df -TH 仍然只有30GB,没有100GB】
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 30G 4.0G 26G 14% /
devtmpfs devtmpfs 939M 0 939M 0% /dev
tmpfs tmpfs 956M 0 956M 0% /dev/shm
tmpfs tmpfs 956M 11M 945M 2% /run
tmpfs tmpfs 956M 0 956M 0% /sys/fs/cgroup
/dev/sda1 xfs 312M 155M 157M 50% /boot
tmpfs tmpfs 192M 13k 191M 1% /run/user/42
tmpfs tmpfs 192M 0 192M 0% /run/user/0
[root@localhost ~]# xfs_growfs /dev/sda3
meta-data=/dev/sda3 isize=512 agcount=4, agsize=1815680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=7262720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3546, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 7262720 to 25612800
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 105G 4.0G 101G 4% /
devtmpfs devtmpfs 939M 0 939M 0% /dev
tmpfs tmpfs 956M 0 956M 0% /dev/shm
tmpfs tmpfs 956M 11M 945M 2% /run
tmpfs tmpfs 956M 0 956M 0% /sys/fs/cgroup
/dev/sda1 xfs 312M 155M 157M 50% /boot
tmpfs tmpfs 192M 13k 191M 1% /run/user/42
tmpfs tmpfs 192M 0 192M 0% /run/user/0
[root@localhost ~]#



结束!!!


以上是关于centos 7 扩容根分区(非LVM)的主要内容,如果未能解决你的问题,请参考以下文章

centos使用lvm扩容根分区

LVM分区扩容(以根分区为例)

centos7上对LVM根分区扩容vg无法添加pv故障解决

centos7---LVM根分区扩容

Centos7下,LVM根分区扩容

centos7在线扩容根分区LVM