Linux磁盘扩容(非lvm)操作手册
文章目录
- Linux磁盘扩容(非lvm)操作手册
- 1.磁盘查看及新磁盘添加扫描(非关机)
- 2. 非逻辑卷扩容
- 3.重载及挂载
早期Linux 只支持 MBR ,后面支持了MBR和GPT两种类型。
长期使用传统的分区工具一般都是用 fdisk,但是 fdisk 是很早用法,它只支持 MBR(Master Boot Record),并不支持新型的 GPT(GUID Partition Table)类型,不能操作超过2T的磁盘,因此使用gdisk,parted 等分区工具。
1.磁盘查看及新磁盘添加扫描(非关机)
# 服务器文件系统容量
[root@db02 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs tmpfs 7.7G 153M 7.6G 2% /run
tmpfs tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/sda4 xfs 41G 4.5G 36G 11% /
/dev/sda2 xfs 1014M 204M 811M 21% /boot
/dev/sda1 vfat 599M 7.3M 592M 2% /boot/efi
/dev/sdb1 xfs 200G 182G 19G 91% /mysqldata #文件系统挂载为200G
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
# 服务器磁盘容量检查
[root@db02 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 8G 0 part [SWAP]
└─sda4 8:4 0 40.4G 0 part /
sdb 8:16 0 200G 0 disk #磁盘容量为200G
└─sdb1 8:17 0 200G 0 part
sr0 11:0 1 11G 0 rom
# 服务器扫描新增磁盘(在服务器上加入新的磁盘,非关机识别)
[root@db02 ~]# ls /sys/class/scsi_device/
0:0:0:0 0:0:1:0 3:0:0:0
[root@db02 ~]# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
[root@db02 ~]# echo 1 > /sys/class/scsi_device/0\:0\:1\:0/device/rescan
[root@db02 ~]# echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
[root@db02 ~]# lsblk # 检查磁盘是否识别
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 8G 0 part [SWAP]
└─sda4 8:4 0 40.4G 0 part /
sdb 8:16 0 300G 0 disk #磁盘容量为300G
└─sdb1 8:17 0 200G 0 part
sr0 11:0 1 11G 0 rom
2. 非逻辑卷扩容
# 检查类型及容量
[root@db02 ~]# fdisk -l
GPT PMBR size mismatch (419430399 != 629145599) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sdb: 300 GiB, 322122547200 bytes, 629145600 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
Disklabel type: gpt #类型为gpt
Disk identifier: 8EC899B5-CB0E-451B-A11A-BECBFCEBFD9D
Device Start End Sectors Size Type
/dev/sdb1 2048 419428351 419426304 200G Linux filesystem
Disk /dev/sda: 50 GiB, 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
Disklabel type: gpt
Disk identifier: 0C766FF6-F4BF-423B-B9E4-4357350A7E10
Device Start End Sectors Size Type
/dev/sda1 2048 1230847 1228800 600M EFI System
/dev/sda2 1230848 3327999 2097152 1G Linux filesystem
/dev/sda3 3328000 20105215 16777216 8G Linux swap
/dev/sda4 20105216 104855551 84750336 40.4G Linux filesystem
# 卸载服务器挂载的文件系统
[root@db02 ~]# umount /dev/sdb1
[root@db02 ~]# df -h #检查已经卸载
# 使用parted分区工具,进行磁盘分区
[root@db02 ~]# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) h #查看帮助,会显示parted的使用
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
(parted) print #打印查看详细磁盘分区信息
Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 209715200 blocks) or continue with the
current setting?
Fix/Ignore? fix #重新修正分区信息
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 215GB 215GB xfs primary
(parted) resizepart #重置调整分区的大小
Partition number? 1 #输入重置的分区号
End? [215GB]? 100% #输入重置分区的大小,“100%”是指剩余的所有分区都划分,也可以输入“322GB”总
(parted) print #重新查看分区大小
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 322GB 322GB xfs primary
(parted) quit #完成退出
Information: You may need to update /etc/fstab.
3.重载及挂载
# 查看当前分区大小
[root@db02 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 8G 0 part [SWAP]
└─sda4 8:4 0 40.4G 0 part /
sdb 8:16 0 300G 0 disk
└─sdb1 8:17 0 300G 0 part
sr0 11:0 1 11G 0 rom
# 磁盘挂载
[root@db02 ~]# mount /dev/sdb1 /mysqldata/
[root@db02 ~]# df -Th | grep mysqldata #查看容量为200G
/dev/sdb1 xfs 200G 147G 53G 74% /mysqldata
#重新检查容量,刷新检查
[root@db02 ~]# xfs_growfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=13107072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=52428288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=25599, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 52428288 to 78642939
[root@db02 ~]# df -Th | grep mysqldata
/dev/sdb1 xfs 300G 148G 153G 50% /mysqldata
[root@db02 ~]#
#测试文件系统的可用性(至此完成扩容)
[root@db02 ~]# echo 123 > /mysqldata/test.txt
[root@db02 ~]# ls /mysqldata/
backup data test.txt zabbix0.sql
[root@db02 ~]# cat /mysqldata/test.txt
123