1、找到未使用的磁盘
df -hT,目前是1T的空间
|
fdisk -l
磁盘是2T的容量
磁盘 /dev/sda:2199.0 GB, 2199023255552 字节,4294967296 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b948d
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 2147483647 1072692224 8e Linux LVM
磁盘 /dev/mapper/centos-root:1036.3 GB, 1036286689280 字节,2023997440 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:8455 MB, 8455716864 字节,16515072 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-home:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
2. 新建分区
fdisk /dev/sda
然后输入m->n->p->回车->回车->回车->w (如果是大于2T的硬盘GPT格式,输入g,n,回车,回车,回车,w,以下操作相同)切记大于2T的需要单独磁盘(vdb、vdc),源硬盘扩容系统会崩溃!!!
然后重起机器 reboot
WARNING: The size of this disk is 2.2 TB (2199023255552 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).
欢迎使用 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 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
分区号 (3,4,默认 3):
起始 扇区 (2147483648-4294967295,默认为 2147483648):
将使用默认值 2147483648
Last 扇区, +扇区 or +size{K,M,G} (2147483648-4294967294,默认为 4294967294):
将使用默认值 4294967294
分区 3 已设置为 Linux 类型,大小设为 1024 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)
正在同步磁盘。
可以看到,新的分区号是3
3. 对分区进行格式化,格式化后的文件系统也是xfs格式
fdisk -l,可以看到新的分区号是3
磁盘 /dev/sda:2199.0 GB, 2199023255552 字节,4294967296 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b948d
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 2147483647 1072692224 8e Linux LVM
/dev/sda3 2147483648 4294967294 1073741823+ 83 Linux
磁盘 /dev/mapper/centos-root:1036.3 GB, 1036286689280 字节,2023997440 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:8455 MB, 8455716864 字节,16515072 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-home:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
对/dev/sda3进行格式化
mkfs.xfs /dev/sda3
meta-data=/dev/sda3 isize=512 agcount=4, agsize=67108864 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=268435455, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=131071, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
4. 创建pv
pvcreate /dev/sda3
然后输入y
|
5. 处理逻辑卷
vgs
|
vgextend centos /dev/sda3
|
vgs
|
可以看到由原来的1023G变成了2T。其中1T是空闲的
df -h
查看要扩容的文件系统的位置 ,这是是/dev/mapper/centos-root
|
lvextend -l +100%free /dev/mapper/centos-root
|
6. 扩容,调整分区
xfs_growfs /dev/mapper/centos-root
|
df -h
扩容成功
|