整块磁盘容量有3000G,其中2000G已经分给了vdb1分区,剩余1000G,现在需要把这1000G扩容到vdb1分区。
[root@dn236 datatom]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 197G 70G 119G 37% /
devtmpfs 9.8G 0 9.8G 0% /dev
tmpfs 9.8G 0 9.8G 0% /dev/shm
tmpfs 9.8G 18M 9.8G 1% /run
tmpfs 9.8G 0 9.8G 0% /sys/fs/cgroup
tmpfs 1.9G 0 1.9G 0% /run/user/1020
/dev/vdb1 2.0T 33G 2.0T 2% /mnt
[root@dn236 datatom]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 200G 0 disk
└─vda1 253:1 0 200G 0 part /
vdb 253:16 0 3T 0 disk
└─vdb1 253:17 0 2T 0 part /mnt
- 使用df -Th 命令查看文件系统类型,在Type列输出,xfs或者ext4.
- 关闭所有使用 /mnt 的服务并卸载该分区的挂载点,umount /mnt
若提示磁盘忙,fuser -m -v /mnt 以及 lsof |grep /mnt 找出正在使用磁盘的进程,并结束掉 - 使用fdisk 命令重新调整磁盘分区大小
fdisk -l
fdisk /dev/vdb
p #查看Start 磁柱号,并记录
g #创建一个新的空的GPT分区表,此时’p’再查看,原本的分区被清理掉了,磁盘头部的MBR分区表清除和替换为GPT分区表,实际上系统文件没有被破坏。
n #创建新分区
p #主分区
1 #第一个分区(创建分区时需要注意,开始的磁柱号要和原来的一致,结束的磁柱号可以直接回车使用全部磁盘)
wq #保存退出,
partprobe 使其操作不用重启生效。
[root@dn236 datatom]# fdisk /dev/vdb
WARNING: The size of this disk is 3.2 TB (3221225472000 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).
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/vdb: 3221.2 GB, 3221225472000 bytes, 6291456000 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: 0x7f0b0907
Device Boot Start End Blocks Id System
/dev/vdb1 2048 4194303999 2097150976 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 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)
Command (m for help):
Command (m for help): g
Building a new GPT disklabel (GUID: 730494AF-154C-4B45-AB97-5B14AC0F3F56)
Command (m for help): p
Disk /dev/vdb: 3221.2 GB, 3221225472000 bytes, 6291456000 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: gpt
Disk identifier: 730494AF-154C-4B45-AB97-5B14AC0F3F56
# Start End Size Type Name
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@dn236 datatom]# fdisk /dev/vdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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): n
Partition number (1-128, default 1):
First sector (2048-6291455966, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-6291455966, default 6291455966):
Created partition 1
Command (m for help): p
Disk /dev/vdb: 3221.2 GB, 3221225472000 bytes, 6291456000 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: gpt
Disk identifier: 730494AF-154C-4B45-AB97-5B14AC0F3F56
# Start End Size Type Name
1 2048 6291455966 3T Linux filesyste
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.
- 查看分区情况
对于 xfs : xfs_repair /dev/vdb1 #检查分区,遇错修复,
xfs_growfs /dev/vdb1 #调整分区大小
对于 ext4 : e2fsck -f /dev/vdb1 #检查分区,遇错修复,
resize2fs /dev/vdb1 #调整分区大小
[root@dn236 datatom]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 200G 0 disk
└─vda1 253:1 0 200G 0 part /
vdb 253:16 0 3T 0 disk
└─vdb1 253:17 0 2T 0 part /mnt
[root@dn236 datatom]#
[root@dn236 datatom]#
[root@dn236 datatom]# partprobe
[root@dn236 datatom]#
[root@dn236 datatom]#
[root@dn236 datatom]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 200G 0 disk
└─vda1 253:1 0 200G 0 part /
vdb 253:16 0 3T 0 disk
└─vdb1 253:17 0 3T 0 part /mnt
- 重新挂载分区 mount /mnt,查看分区
[root@dn236 datatom]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 197G 70G 119G 37% /
devtmpfs 9.8G 0 9.8G 0% /dev
tmpfs 9.8G 0 9.8G 0% /dev/shm
tmpfs 9.8G 18M 9.8G 1% /run
tmpfs 9.8G 0 9.8G 0% /sys/fs/cgroup
tmpfs 1.9G 0 1.9G 0% /run/user/1020
/dev/vdb1 3.0T 33G 2.9T 2% /mnt