Centos7系统给磁盘新增分区,启用未使用磁盘空间
使用模板新建一台华为云主机作为mysql数据库服务器,分配了200G磁盘空间。开机后,总磁盘空间只有50G。这就需要把剩余空间释放出来。由于以前没有处理过这样的问题,同时这又是台mysql 服务器,mysql文件及数据文件保存在/Data目录下,需要处理后mysql服务器还能正常启动。经过一番学习研究,整理出整个目前我遇到情况处理过程如下:
命令及命令解释
cd /Data/ #进入mysql 文件及mysql数据保存文件夹
ll
mv /Data/mysql/ /tmp/ #把/Data/mysql/ 文件移走,这样/Data文件夹就是空的了,后续好挂载
lsblk #查询实际磁盘使用及分区情况
df -h #查看磁盘使用情况
fdisk -l #查看硬盘情况
fdisk /dev/sda #磁盘分区 分别输入n p 其他为默认值,本次给sda增加一个分区sda3
ls /dev/sd* #查看硬盘情况 本次磁盘名称是sda 所以命令中有sd
partprobe #通知系统分区表的变化
ls /dev/sd* #partprobe命令前后查询下,能看partprobe执行后多了个sda3,这个sda3就是要启用的剩余150G空间
pvcreate /dev/sda3 # 用于将物理硬盘分区初始化为物理卷,以便LVM使用
ls /dev/sd*
mkfs.xfs -f /dev/sda3 #格式化磁盘sda3
df -h
mount /dev/sda3 /Data/ #挂载
df -h #挂载后,就可以看出多了个/Data 挂载了sda3 总空间150G
mv /tmp/mysql/ /Data/ #欢迎mysql服务 文件
service mysqld start # 启动mysql
cat /etc/fstab #手动挂载后,机器重启后还需要继续手动挂载,需要在/etc/fstab添加一行,服务器重启后,不在需要手动挂载
vim /etc/fstab 添加一行,开机自动挂载
/dev/sda3 /Data xfs defaults 0 0
cat /etc/fstab
命令执行结果:
[root@0005 Data]# cd /Data/
[root@0005 Data]# ll
total 4
drwxr-x--- 5 mysql mysql 4096 Dec 6 08:19 mysql
[root@0005 Data]# mv /Data/mysql/ /tmp/
[root@0005 Data]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 476M 0 part /boot
└─sda2 8:2 0 49.5G 0 part
├─centos-SysLVM 253:0 0 45.7G 0 lvm /
└─centos-swap 253:1 0 3.8G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
[root@0005 Data]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-SysLVM 46G 5.7G 41G 13% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 473M 154M 320M 33% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/5681
[root@0005 Data]# fdisk -l
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000c06de
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 976895 487424 83 Linux
/dev/sda2 976896 104857599 51940352 8e Linux LVM
Disk /dev/mapper/centos-SysLVM: 49.1 GB, 49085939712 bytes, 95870976 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 /dev/mapper/centos-swap: 4097 MB, 4097835008 bytes, 8003584 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
[root@0005 Data]# fdisk /dev/sda
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 type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (104857600-419430399, default 104857600):
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-419430399, default 419430399):
Using default value 419430399
Partition 3 of type Linux and of size 150 GiB is set
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@0005 Data]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2
[root@0005 Data]# partprobe
[root@0005 Data]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3
[root@0005 Data]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@0005 Data]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3
[root@0005 Data]# mkfs.xfs -f /dev/sda3
meta-data=/dev/sda3 isize=512 agcount=4, agsize=9830400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=39321600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=19200, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@0005 Data]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-SysLVM 46G 5.7G 41G 13% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 473M 154M 320M 33% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/5681
[root@0005 Data]# mount /dev/sda3 /Data/
[root@0005 Data]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-SysLVM 46G 5.7G 41G 13% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 473M 154M 320M 33% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/5681
/dev/sda3 150G 33M 150G 1% /Data
[root@0005 Data]# mv /tmp/mysql/ /Data/
[root@0005 Data]# service mysqld start
Starting MySQL (Percona Server).Logging to '/Data/mysql/0005.novalocal.err'.
.. [ OK ]
[root@0005 Data]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Nov 19 02:41:53 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-SysLVM / xfs defaults 0 0
UUID=39305a68-e983-4e80-8625-76ac41da94b0 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/mapper/centos-swap none swap sw,comment=cloudconfig 0 0
[root@0005 Data]# vim /etc/fstab
[root@0005 Data]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Nov 19 02:41:53 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-SysLVM / xfs defaults 0 0
/dev/sda3 /Data xfs defaults 0 0
UUID=39305a68-e983-4e80-8625-76ac41da94b0 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/mapper/centos-swap none swap sw,comment=cloudconfig 0 0
[root@0005 Data]# service mysqld stop
Shutting down MySQL (Percona Server).. [ OK ]
备注:本次处理和新增一块磁盘处理方式有点不一样。本次是主要是给磁盘扩容新增分区
欢迎关注公众号: