小记centos7下将未使用的磁盘空间重新分区挂载使用

一块1TB的硬盘,用作samba共享,在安装系统时分区如下:

/boot   2048M 
swap    512M
/       229GB
剩下约 700GB左右未使用空间,在安装完系统后再使用

以下是详细操作,就几个步骤,很简单

[root@SZMT-SERVER ~]# fdisk -l              #<===查看磁盘使用情况
磁盘 /dev/sda:1000.2 GB, 1000204886016 字节,1953525168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000c868c

设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 4196351 2097152 83 Linux
/dev/sda2 4196352 485525503 240664576 8e Linux LVM

磁盘 /dev/mapper/centos-root:245.9 GB, 245895266304 字节,480264192 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘 /dev/mapper/centos-swap:536 MB, 536870912 字节,1048576 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@SZMT-SERVER samba]# df -lh
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 229G 1.7G 228G 1% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.7M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 2.0G 131M 1.9G 7% /boot
tmpfs 394M 0 394M 0% /run/user/0
[root@SZMT-SERVER samba]# fdisk /dev/sda         #<===fdisk命令很简单
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

命令(输入 m 获取帮助):m
命令操作
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 partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

命令(输入 m 获取帮助):p

磁盘 /dev/sda:1000.2 GB, 1000204886016 字节,1953525168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000c868c

设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 4196351 2097152 83 Linux
/dev/sda2 4196352 485525503 240664576 8e Linux LVM

命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p                          
分区号 (3,4,默认 3):3                 #<===以下步骤默认即将所有未使用空间划分给3
起始 扇区 (485525504-1953525167,默认为 485525504):
将使用默认值 485525504
Last 扇区, +扇区 or +size{K,M,G} (485525504-1953525167,默认为 1953525167):
将使用默认值 1953525167
分区 3 已设置为 Linux 类型,大小设为 700 GiB

命令(输入 m 获取帮助):w             #<===保存退出
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@SZMT-SERVER ~]# partprobe                   #<===关键命令,通知内核
[root@SZMT-SERVER ~]# mkfs -t xfs /dev/sda3                #<===格式化
meta-data=/dev/sda3 isize=512 agcount=4, agsize=45874990 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=183499958, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=89599, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@SZMT-SERVER ~]# mkdir /data
[root@SZMT-SERVER ~]# mount /dev/sda3 /data
[root@SZMT-SERVER ~]# df -l
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/mapper/centos-root 240014844 1687476 238327368 1% /
devtmpfs 2001036 0 2001036 0% /dev
tmpfs 2013560 0 2013560 0% /dev/shm
tmpfs 2013560 8848 2004712 1% /run
tmpfs 2013560 0 2013560 0% /sys/fs/cgroup
/dev/sda1 2086912 133196 1953716 7% /boot
tmpfs 402712 0 402712 0% /run/user/0
/dev/sda3 733641436 32944 733608492 1% /data

[root@SERVER1 ~]# cat /etc/fstab                 #<==保存至开机自动挂载
#
# /etc/fstab
# Created by anaconda on Wed Feb 15 09:40:26 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=0bdf1908-f065-4045-b6db-4b55e990cd0a / ext3 defaults 1 1
UUID=4a6701cf-4ad5-4011-b7c2-73d40a757a1d swap swap defaults 0 0
/dev/sda3         /data     xfs   defaults   0 0

  

原文地址:https://www.cnblogs.com/blog-tim/p/10518535.html