磁盘空间不足,扩充根分区,添加新的磁盘
一、扩充根分区
根分区使用率超过预警值,经排查删除了无用数据,但使用率依然居高不下,于是决定扩充根分区。
一、查看目前的使用情况
[root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 997M 994M 2.9M 100% / devtmpfs devtmpfs 915M 0 915M 0% /dev tmpfs tmpfs 921M 0 921M 0% /dev/shm tmpfs tmpfs 921M 17M 905M 2% /run tmpfs tmpfs 921M 0 921M 0% /sys/fs/cgroup /dev/mapper/centos-usr xfs 4.9G 1.6G 3.4G 33% /usr /dev/sda1 xfs 97M 66M 31M 69% /boot /dev/mapper/centos-var xfs 2.4G 473M 1.9G 21% /var
/dev/mapper/centos-root 已经使用了100%
二、添加新的磁盘,分区格式化
根据公司环境不同,自行添加新的磁盘
1、添加完后,查看磁盘情况
[root@localhost ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000940ec Device Boot Start End Blocks Id System /dev/sda1 * 2048 206847 102400 83 Linux /dev/sda2 206848 41943039 20868096 8e Linux LVM Disk /dev/sdb: 3221 MB, 3221225472 bytes, 6291456 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: 2097 MB, 2097152000 bytes, 4096000 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-usr: 5242 MB, 5242880000 bytes, 10240000 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-root: 1048 MB, 1048576000 bytes, 2048000 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 ... ...
可以看到新添加的磁盘/dev/sdb
2、对磁盘进行分区
n --创建新分区 p --创建主分区 <回车> --默认分区编号 <回车> --默认起始扇区位置。 <回车> --默认结束扇区位置。 w --写入分区表
3、再查看磁盘情况
多出下面的分区
Device Boot Start End Blocks Id System /dev/sdb1 2048 6291455 3144704 83 Linux
三、扩充根分区:将新分区扩展/root
1、查看卷分组
Finding all volume groups Finding volume group "centos" --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 5 Open LV 5 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.90 GiB PE Size 4.00 MiB Total PE 5094 Alloc PE / Size 5093 / 19.89 GiB Free PE / Size 1 / 4.00 MiB VG UUID vtJL08-7Jxi-5IqK-3fUg-Pben-682a-wiv2GL --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID ZWTgoT-AMWs-g54v-dZA1-NQUj-mqGa-8tmr4U LV Write Access read/write LV Creation host, time localhost, 2016-07-03 21:59:31 -0400 LV Status available # open 1 LV Size 1000.00 MiB Current LE 250 Segments 1 Allocation inherit Read ahead sectors auto currently set to 256 Block device 253:2 ... ... ... --- Physical volumes --- PV Name /dev/sda2 PV UUID fiVH1e-lwfi-63Lr-oIlK-GDZI-dcuZ-T04VlC PV Status allocatable Total PE / Free PE 5094 / 1
2、为新增的分区创建物理卷
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n] y Wiping xfs signature on /dev/sdb1. Physical volume "/dev/sdb1" successfully created
3、查看结果
--- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size 19.90 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 5094 Free PE 1 Allocated PE 5093 PV UUID fiVH1e-lwfi-63Lr-oIlK-GDZI-dcuZ-T04VlC "/dev/sdb1" is a new physical volume of "3.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 3.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID VGXSAn-UiZ0-Fy40-eQxb-53xA-5hZM-3eGPg0
4、扩展卷分组,"centos"是vgdisplay命令查到的卷分组名
v
提示扩展成功
5、查看逻辑卷,并扩展逻辑卷
l
可以看到/dev/centos/root目前的LV Size是1000MiB。
Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 4.0G 995M 3.1G 25% / devtmpfs devtmpfs 915M 0 915M 0% /dev tmpfs tmpfs 921M 0 921M 0% /dev/shm tmpfs tmpfs 921M 8.4M 913M 1% /run tmpfs tmpfs 921M 0 921M 0% /sys/fs/cgroup /dev/mapper/centos-usr xfs 4.9G 1.6G 3.4G 33% /usr /dev/mapper/centos-home xfs 9.8G 391M 9.4G 4% /home /dev/mapper/centos-var xfs 2.4G 469M 1.9G 20% /var /dev/sda1 xfs 97M 66M 31M 69% /boot
/root已经扩充到4GiB
磁盘空间不足,添加新的磁盘
ECS赠送的系统盘20G,明显不够使用。购买一块500G的数据盘,作为应用服务及数据存储使用。
一、检查目前磁盘情况
1、看现在磁盘情况
2、查看磁盘个数以及分区情况
新加的500G磁盘为:/dev/xvdb
二、对新磁盘进行分区、格式化、挂载
1、对新磁盘进行分区(根据实际需求)
2、再查看磁盘个数与分区情况
可以看到新建分区创建完毕
3、通知内存磁盘分区变化
不通知内核,有可能无法格式化操作
partprobe /dev/xvdb
4、格式化分区(根据系统和实际情况格式化成自己想要的文件系统
5、创建挂载目录
6、挂载分区指定目录,并创建开机自动挂载
1、挂载分区
mount /dev/xvdb1 /licheng
2、创建开机自动挂载
1.可以通过磁盘分区名挂载
2. 也可以通过uuid进行挂载
查看磁盘的uuid
blkid
挂载
UUID=688f7de2-cdd3-444b-8ffc-3d3239e3e123 /opt ext4 defaults 1 2
物理卷(PV,Physical Volumes)对应的是硬件存储,是磁盘或者磁盘分区,是物理存在。而卷组(VG,Volume Group)和逻辑卷(LV,Logical Volumes)则是逻辑上的存在。
在LVM(逻辑卷管理)的磁盘中,先创建物理卷,然后将物理卷加入到卷组,在通过卷组来创建逻辑卷使用.
参考文档:https://www.cnblogs.com/happy-king/p/9070496.html#_label1