关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

centos6/7使用fdisk扩展分区容量教程

发布时间:2019/10/13 22:31:53
香港云服务器

本文档主要对/dev/sdb1这个分区扩展,做任何操作之前都需要提前做好备份保存,这hi是一个习惯,虽然扩展分区大小不会导致数据丢失,但是安全起见,请提前做好备份;
卸载磁盘分区
[root@localhost ~]# umount /dev/sdb1
 image.png
若提示磁盘忙,使用fuser找出将正在使用磁盘的程序并结束掉;
1:fuser -m -v /data
2:fuser -m -v -i -k /data
使用fdisk工具先删除/dev/sdb1分区,然后创建新分区,注意开始的磁柱号要和原来的一致(是保证数据不丢失的关键步骤)!结束的磁柱号默认回车使用全部磁盘。
[root@localhost ~]# fdisk /dev/sdb
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/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x7efdf11b
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   104857599    52427776   83  Linux
 
Command (m for help): d  (删除分区,因为我默认只有一个,所以默认删除第一个,如果有多个,可以指定1,2,3..)
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): 1 (和之前的分区好一致
First sector (2048-104857599, default 2048): 2048 (需要和之前的分区的起始磁盘柱号一致,特别重要!!!)
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set
 
Command (m for help): wq (保存退出,如果操作有无可以直接退出不保存)
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 ~]# e2fsck -f /dev/sdb1
 image.png
重新挂载、查看分区大小、数据
[root@localhost ~]# mount /dev/sdb1 /data
[root@localhost ~]# df -hal