CentOS 7 下使用 fdisk 扩容分区容量

  • 背景
CentOS 7 下有磁盘 500GB,最初分配 200GB,因数据不断增加,磁盘不够,因需扩充已有 200GB 磁盘。

磁盘使用查看

磁盘使用查看
[root@demo ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        22G  3.4G   19G  16% /
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G  9.0M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda2               xfs       194M  120M   75M  62% /boot
tmpfs                   tmpfs     380M     0  380M   0% /run/user/0
/dev/sdb1               ext4      1.9G  1.5G  218M  88% /test
所有磁盘查看
[root@demo ~]# fdisk -l | grep Disk | grep sd
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors

查看磁盘数据

  • ls 查看文件
[root@demo ~]# ll /test//*/*
-rw-r--r-- 1 root root  528015360 Jul 13 12:08 /test//soft/mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415  25402568 Dec 24  2018 /test//soft/mysql-community-client-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    280904 Dec 24  2018 /test//soft/mysql-community-common-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   3839640 Dec 24  2018 /test//soft/mysql-community-devel-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  46782224 Dec 24  2018 /test//soft/mysql-community-embedded-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  24079656 Dec 24  2018 /test//soft/mysql-community-embedded-compat-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 130149460 Dec 24  2018 /test//soft/mysql-community-embedded-devel-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2271668 Dec 24  2018 /test//soft/mysql-community-libs-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2116628 Dec 24  2018 /test//soft/mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 173130520 Dec 24  2018 /test//soft/mysql-community-server-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 119947432 Dec 24  2018 /test//soft/mysql-community-test-5.7.25-1.el7.x86_64.rpm
  • 文件夹内容 md5 记录
[root@demo ~]# find /test -type f -print0 | xargs -0 md5sum | sort > /root/md5_old.txt

卸载 && 重新分配

卸载磁盘
[root@demo ~]# umount /dev/sdb1 
[root@demo ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        22G  3.4G   19G  16% /
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G  9.0M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda2               xfs       194M  120M   75M  62% /boot
tmpfs                   tmpfs     380M     0  380M   0% /run/user/0
重建分区
  • 使用 fdisk 进行分区操作
[root@demo ~]# fdisk /dev/sdb

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
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):
  • 查看现有分区
Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0xdff524f7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     3907583     1952768   83  Linux
  • 删除分区
Command (m for help): d
Selected partition 1
Partition 1 is deleted
  • 重新创建分区 – 确保分区开始同删除前
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-20971519, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): 
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p 			# 查看现有分区

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0xdff524f7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   83  Linux

Command (m for help): w 			# 保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
调增分区
  • 检查分区表信息
[root@demo ~]# e2fsck -f /dev/sdb1 
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 24/122160 files (16.7% non-contiguous), 404036/488192 blocks
  • 调整分区大小
[root@demo ~]# resize2fs /dev/sdb1 
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/sdb1 to 2621184 (4k) blocks.
The filesystem on /dev/sdb1 is now 2621184 blocks long
  • 重新挂载分区
[root@demo ~]# mount /dev/sdb1 /test
  • 查看磁盘信息
[root@demo ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        22G  3.4G   19G  16% /
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G  9.0M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda2               xfs       194M  120M   75M  62% /boot
tmpfs                   tmpfs     380M     0  380M   0% /run/user/0
/dev/sdb1               ext4      9.9G  1.5G  7.9G  16% /test
  • 确认磁盘数据
[root@demo ~]# ll /test//*/*
-rw-r--r-- 1 root root  528015360 Jul 13 12:08 /test//soft/mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415  25402568 Dec 24  2018 /test//soft/mysql-community-client-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    280904 Dec 24  2018 /test//soft/mysql-community-common-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   3839640 Dec 24  2018 /test//soft/mysql-community-devel-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  46782224 Dec 24  2018 /test//soft/mysql-community-embedded-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  24079656 Dec 24  2018 /test//soft/mysql-community-embedded-compat-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 130149460 Dec 24  2018 /test//soft/mysql-community-embedded-devel-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2271668 Dec 24  2018 /test//soft/mysql-community-libs-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2116628 Dec 24  2018 /test//soft/mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 173130520 Dec 24  2018 /test//soft/mysql-community-server-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 119947432 Dec 24  2018 /test//soft/mysql-community-test-5.7.25-1.el7.x86_64.rpm
  • 文件夹内容 md5 记录
[root@demo ~]# find /test -type f -print0 | xargs -0 md5sum | sort > /root/md5_new.txt
  • 对比扩容前后数据一致性
[root@demo ~]# diff /root/md5_old.txt /root/md5_new.txt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值