centos7 磁盘空间不足扩容操作

您所在的位置:网站首页 centos7安装硬盘空间不足 centos7 磁盘空间不足扩容操作

centos7 磁盘空间不足扩容操作

2024-05-24 11:29| 来源: 网络整理| 查看: 265

无卷组后续操作:CentOS磁盘在根目录下扩容(无卷组情况下)

系统警告磁盘空间不足 在这里插入图片描述

关机后进行扩容,增加至50GB

在这里插入图片描述

查看本地磁盘环境

[lj@localhost ~]$ df -h 文件系统 容量 已用 可用 已用% 挂载点 devtmpfs 895M 0 895M 0% /dev tmpfs 910M 0 910M 0% /dev/shm tmpfs 910M 11M 900M 2% /run tmpfs 910M 0 910M 0% /sys/fs/cgroup /dev/sda3 18G 16G 2.0G 89% / /dev/sda1 297M 166M 132M 56% /boot tmpfs 182M 24K 182M 1% /run/user/1000 [lj@localhost ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 300M 0 part /boot ├─sda2 8:2 0 2G 0 part [SWAP] └─sda3 8:3 0 17.7G 0 part / sr0 11:0 1 1024M 0 rom

增加磁盘分区

命令 n 表示新建分区 p primary: 主分区 e extended: 扩展分区 命令 p 是列表查看分区信息 命令 w 退出

[lj@localhost ~]$ sudo fdisk /dev/sda 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 命令(输入 m 获取帮助):n Partition type: p primary (3 primary, 0 extended, 1 free) e extended Select (default e): p 已选择分区 4 起始 扇区 (41943040-104857599,默认为 41943040): 将使用默认值 41943040 Last 扇区, +扇区 or +size{K,M,G} (41943040-104857599,默认为 104857599): 将使用默认值 104857599 分区 4 已设置为 Linux 类型,大小设为 30 GiB 命令(输入 m 获取帮助):p 磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x000ee067 设备 Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris /dev/sda3 4810752 41943039 18566144 83 Linux /dev/sda4 41943040 104857599 31457280 83 Linux 命令(输入 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) 正在同步磁盘。

reboot重启之后增加了第四分区

[lj@localhost ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 300M 0 part /boot ├─sda2 8:2 0 2G 0 part [SWAP] ├─sda3 8:3 0 17.7G 0 part / └─sda4 8:4 0 30G 0 part sr0 11:0 1 1024M 0 rom

创建物理卷,查看物理卷和卷组:

pvdisplay # 查看物理分区 vgdisplay # 查看卷组信息 lvdisplay # 查看逻辑分区

vgdisplay 为空,说明无卷组 后续操作对有卷组和无卷组操作有差异,注意看自己是哪一种

[lj@localhost ~]$ sudo lvm [sudo] lj 的密码: lvm> pvcreate /dev/sda4 Physical volume "/dev/sda4" successfully created. lvm> pvdisplay "/dev/sda4" is a new physical volume of "30.00 GiB" --- NEW Physical volume --- PV Name /dev/sda4 VG Name PV Size 30.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID FcciA0-sOFJ-kugT-uEeN-fTWS-Qm6C-EKCeXT lvm> vgdisplay lvm> lvdisplay

这里我的卷组和逻辑分区都为空

对新增硬盘进行分区

执行步骤:

执行“fdisk /dev/sda”,进入到fdisk输入p指令,查看已分区数量(有4个 /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4)输入t {change partition id}指令,修改分区类型按提示输入刚才的分区号4输入分区类型 8e {Linux LVM partition}输入w指令,将以上改动写入分区表最后完成,退出fdisk命令 [lj@localhost block]$ sudo fdisk /dev/sda [sudo] lj 的密码: 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 命令(输入 m 获取帮助):p 磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x000ee067 设备 Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris /dev/sda3 4810752 41943039 18566144 83 Linux /dev/sda4 41943040 104857599 31457280 83 Linux 命令(输入 m 获取帮助):t 分区号 (1-4,默认 4):4 Hex 代码(输入 L 列出所有代码):8e 已将分区“Linux”的类型更改为“Linux LVM” 命令(输入 m 获取帮助):p 磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x000ee067 设备 Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris /dev/sda3 4810752 41943039 18566144 83 Linux /dev/sda4 41943040 104857599 31457280 8e Linux LVM 命令(输入 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) 正在同步磁盘。

无卷组:创建卷组

[lj@localhost block]$ sudo vgcreate centos /dev/sda4 Volume group "centos" successfully created [lj@localhost block]$ sudo lvm lvm> vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size lvdisplay --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID xflHQe-xZGx-9R3D-CcT1-l76w-i2bH-NMMdTd LV Write Access read/write LV Creation host, time localhost.localdomain, 2022-05-29 16:27:20 +0800 LV Status available # open 0 LV Size 29.00 GiB Current LE 7424 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0

有卷组: 扩展逻辑卷

lvextend -L +30G /dev/mapper/centos-root

无卷组:格式化逻辑分区

[root@localhost mapper]# mkfs.xfs /dev/centos/root meta-data=/dev/centos/root isize=512 agcount=4, agsize=1900544 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=7602176, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=3712, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0

无卷组:扩展已有卷的容量并同步到文件系统 扩展命令:

lvextend -l +100%FREE /dev/mapper/centos-root [root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root Size of logical volume centos/root changed from 29.00 GiB (7424 extents) to


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3