centos 7 扩容根分区(非LVM)

万事须己运,他得非我贤。这篇文章主要讲述centos 7 扩容根分区(非LVM)相关的知识,希望能为你提供帮助。
1.磁盘原来只有30G,在vmware workstation中扩展到了100G,但是还是需要在系统中扩容一下才行



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 BootStartEndBlocksIdSystem
/dev/sda1*204861644730720083Linux
/dev/sda26164484812799209817682Linux swap / Solaris
/dev/sda34812800629145592905088083Linux

[root@localhost ~]# df -TH
FilesystemTypeSizeUsed Avail Use% Mounted on
/dev/sda3xfs30G4.0G26G14% /
devtmpfsdevtmpfs939M0939M0% /dev
tmpfstmpfs956M0956M0% /dev/shm
tmpfstmpfs956M11M945M2% /run
tmpfstmpfs956M0956M0% /sys/fs/cgroup
/dev/sda1xfs312M155M157M50% /boot
tmpfstmpfs192M8.2k192M1% /run/user/42
tmpfstmpfs192M0192M0% /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 BootStartEndBlocksIdSystem
/dev/sda1*204861644730720083Linux
/dev/sda26164484812799209817682Linux swap / Solaris
/dev/sda34812800629145592905088083Linux

Command (m for help): m
Command action
atoggle a bootable flag
bedit bsd disklabel
ctoggle the dos compatibility flag
ddelete a partition
gcreate a new empty GPT partition table
Gcreate an IRIX (SGI) partition table
llist known partition types
mprint this menu
nadd a new partition
ocreate a new empty DOS partition table
pprint the partition table
qquit without saving changes
screate a new empty Sun disklabel
tchange a partitions system id
uchange display/entry units
vverify the partition table
wwrite table to disk and exit
xextra 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:
pprimary (2 primary, 0 extended, 2 free)
eextended
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 BootStartEndBlocksIdSystem
/dev/sda1*204861644730720083Linux
/dev/sda26164484812799209817682Linux swap / Solaris
/dev/sda3481280020971519910245120083Linux





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
NAMEMAJ:MIN RMSIZE RO TYPE MOUNTPOINT
sda8:00100G0 disk
├─sda18:10300M0 part /boot
├─sda28:202G0 part [SWAP]
└─sda38:30 97.7G0 part /
sr011:01 1024M0 rom
[root@localhost ~]# df -TH【df -TH 仍然只有30GB,没有100GB】
FilesystemTypeSizeUsed Avail Use% Mounted on
/dev/sda3xfs30G4.0G26G14% /
devtmpfsdevtmpfs939M0939M0% /dev
tmpfstmpfs956M0956M0% /dev/shm
tmpfstmpfs956M11M945M2% /run
tmpfstmpfs956M0956M0% /sys/fs/cgroup
/dev/sda1xfs312M155M157M50% /boot
tmpfstmpfs192M13k191M1% /run/user/42
tmpfstmpfs192M0192M0% /run/user/0
[root@localhost ~]# xfs_growfs /dev/sda3
meta-data=https://www.songbingjia.com/dev/sda3isize=512agcount=4, agsize=1815680 blks
=sectsz=512attr=2, projid32bit=1
=crc=1finobt=0 spinodes=0
data=https://www.songbingjia.com/android/bsize=4096blocks=7262720, imaxpct=25
=sunit=0swidth=0 blks
naming=version 2bsize=4096ascii-ci=0 ftype=1
log=internalbsize=4096blocks=3546, version=2
=sectsz=512sunit=0 blks, lazy-count=1
realtime =noneextsz=4096blocks=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
FilesystemTypeSizeUsed Avail Use% Mounted on
/dev/sda3xfs105G4.0G101G4% /
devtmpfsdevtmpfs939M0939M0% /dev
tmpfstmpfs956M0956M0% /dev/shm
tmpfstmpfs956M11M945M2% /run
tmpfstmpfs956M0956M0% /sys/fs/cgroup
/dev/sda1xfs312M155M157M50% /boot
tmpfstmpfs192M13k191M1% /run/user/42
tmpfstmpfs192M0192M0% /run/user/0
[root@localhost ~]#



结束!!!

【centos 7 扩容根分区(非LVM)】


    推荐阅读