linux centos7扩展磁盘容量-实操

vmwave为centos7扩展磁盘容量

在这里插入图片描述
需要在没快照的且关机的情况下

linux内部扩展容量

新建分区

执行“fdisk /dev/sda”,进入到fdisk
输入p指令,查看已分区数量(有两个 /dev/sda1 /dev/sda2)
输入 n {new partition}指令,新增加一个分区
输入p {primary partition},分区类型选择为主分区
输入分区号 3 {partition number} ,分区号选3(上面显示我已经有2个分区了)
回车      默认(起始扇区)
回车      默认(结束扇区)
输入t {change partition id}指令,修改分区类型
按提示输入刚才的分区号3
输入分区类型 8e {Linux LVM partition}
输入w指令,将以上改动写入分区表
最后完成,退出fdisk命令

在这里插入图片描述

[root@localhost ~]# 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): p

Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 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: 0x000be063

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    20971519     9436160   8e  Linux LVM

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 (20971520-125829119, default 20971520): 
Using default value 20971520
Last sector, +sectors or +size{K,M,G} (20971520-125829119, default 125829119): 
Using default value 125829119
Partition 3 of type Linux and of size 50 GiB is set

Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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.

重启系统(重要)

shutdown -r now

对新增的硬盘格式化

mkfs.ext3 /dev/sda3

在这里插入图片描述

添加新LVM到已有的LVM组,实现扩容

在这里插入图片描述

lvm             进入lvm管理
lvm> pvcreate /dev/sda3 这是初始化刚才的分区,必须的
lvm>vgextend centos /dev/sda3 将初始化过的分区加入到虚拟卷组vg_dc01
lvm>lvextend -L +39.9G /dev/mapper/centos-root  扩展已有卷的容量(注意容量大小)
lvm>pvdisplay               查看卷容量,这时你会看到一个很大的卷了
lvm>quit                  退出

文件真正扩容

在这里插入图片描述
因为这里是xfs扩容的

resize2fs /dev/mapper/centos-root

因此更改命令

xfs_growfs /dev/mapper/centos-root

在这里插入图片描述
即可看到扩容后的状态
扩容前:
在这里插入图片描述
扩容后:
在这里插入图片描述

参考

虚拟机vmware centos7 扩展磁盘空间

### VMware CentOS 7 虚拟机扩展磁盘容量教程 #### 准备工作 在开始之前,确保虚拟机关机并备份重要数据以防万一。关闭虚拟机后,在VMware界面中进入硬件设置,找到目标硬盘进行扩容操作。 执行以下命令确认当前磁盘状态: ```bash df -h lsblk ``` 这些命令可以帮助识别现有磁盘及其挂载情况[^2]。 #### 步骤一:扩展虚拟磁盘 在VMware界面上完成磁盘的物理扩展操作。具体方法如下: 1. 关闭虚拟机。 2. 进入虚拟机设置 -> 硬件选项卡 -> 硬盘 (SCSI)。 3. 单击“扩展”,输入期望的新磁盘大小并保存更改[^4]。 #### 步骤二:创建新分区 启动虚拟机后,使用`fdisk`工具来重新分配新增加的空间: 运行以下命令查看磁盘变化以及新建分区: ```bash fdisk -l fdisk /dev/sda ``` 按照提示添加一个新的主分区(通常会命名为 `/dev/sdaX`),完成后再次运行 `fdisk -l` 验证结果,并通过下面这条指令让操作系统立即感知到新的分区结构: ```bash partprobe ``` #### 步骤三:初始化与加入卷组 将刚刚建立好的分区转换成 LVM 物理卷(PV),随后将其纳入现有的逻辑卷管理器(LVM)之中。 执行下列脚本来实现上述目的: ```bash pvcreate /dev/sdaX # 初始化分区作为 PV vgextend centos /dev/sdaX # 把此PV 添加至名为 'centos' 的 VG 中 lvextend -l +100%FREE /dev/mapper/centos-root # 使用全部可用空间扩充根 LV ``` #### 步骤四:调整文件系统尺寸 最后一步就是扩大实际使用的文件系统以匹配更新后的逻辑卷大小。如果基础文件系统为 XFS,则采用专用工具;如果是 EXT 类型则需指定不同参数: 对于 **XFS** 文件系统: ```bash xfs_growfs /dev/mapper/centos-root ``` 而对于 **EXT4** 则应这样处理: ```bash resize2fs /dev/mapper/centos-root ``` 至此整个流程结束,可以再一次利用先前提到过的 `df -h` 来检验最终效果[^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值