首页 > 编程知识 正文

vmware 扩展磁盘空间,vmware ubuntu扩展磁盘空间

时间:2023-05-06 09:32:23 阅读:264646 作者:3428

VMware下的Linux扩展磁盘空间 业务场景业务场景 操作流程一、VMware 加内存二 、linux操作查看磁盘空间信息:增加分区:检查分区:初始化分区,加入卷组卷扩容,添加进LVM组查看卷组,并将初始化的分区加入到虚拟卷组为卷组centos添加新的物理卷sda3增加卷组的容量扩展逻辑卷的大小(追加磁盘空间的过程)最后使用·resizefs2·命令重新加载逻辑卷的大小才能生效

业务场景 业务场景

本文以 VMware® Workstation 15 Pro -15.5.6 build-16341506+ CentOS Linux release 7.5.1804 (Core)为测试机,本文为扩展原有硬盘空间,如需增加新硬盘请参考 链接: VMware下的Linux扩展磁盘空间(增加全新的硬盘空间)

操作流程 一、VMware 加内存

如下图所示,此时可以看到虚拟机硬盘目前为25G,点击编辑虚拟机设置,进入虚拟机设置界面。

分别按下图步骤点击硬盘→扩展→扩展内存→扩展→确定。

硬盘扩展成功后,须要在客户机(即Linux虚拟机)上进行分区硬盘和扩展文件系统。

二 、linux操作 查看磁盘空间信息:

执行fdisk -l查看当前的系统的磁盘空间的情况:

[root@localhost ~]# fdisk -lDisk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000c591b Device Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 41943039 19921920 8e Linux LVMDisk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes 增加分区:

执行fdisk /dev/sda
键入n,增加一个分区,得到:
键入 p,主分区,并键入3(编号):
默认起始扇区和结束扇区即可(键入两次Enter) 键入t,
修改分区类型为8e
键入w,写分区表

[root@localhost ~]# fdisk /dev/sdaWelcome 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): nPartition type: p primary (2 primary, 0 extended, 2 free) e extendedSelect (default p): pPartition number (3,4, default 3): First sector (41943040-104857599, default 41943040): Using default value 41943040Last sector, +sectors or +size{K,M,G} (41943040-104857599, default 104857599): Using default value 104857599Partition 3 of type Linux and of size 30 GiB is setCommand (m for help): tPartition number (1-3, default 3): Hex code (type L to list all codes): 8eChanged type of partition 'Linux' to 'Linux LVM'Command (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks. 检查分区:

执行fdisk -l

[root@localhost ~]# fdisk -lDisk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000c591b Device Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 41943039 19921920 8e Linux LVMDisk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes

发现此时/dev/sda空间已经扩大,执行reboot重启

初始化分区,加入卷组 卷扩容,添加进LVM组

执行pvcreate /dev/sda3 初始化刚才的分区

[root@localhost ~]# pvcreate /dev/sda3WARNING: dos signature detected on /dev/sda3 at offset 510. Wipe it? [y/n]: y Wiping dos signature on /dev/sda3. Physical volume "/dev/sda3" successfully created. 查看卷组,并将初始化的分区加入到虚拟卷组

执行vgdisplay 查看卷组信息

[root@localhost ~]# vgdisplay --- Volume group --- VG Name centos #卷组名称 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <19.00 GiB PE Size 4.00 MiB Total PE 4863 Alloc PE / Size 4863 / <19.00 GiB Free PE / Size 0 / 0 VG UUID hCBaNk-KEkz-SKvR-gRP2-btG9-KqhR-BKtfTX 为卷组centos添加新的物理卷sda3增加卷组的容量

执行vgextend centos /dev/sda3

[root@localhost ~]# vgextend centos /dev/sda3 Volume group "centos" successfully extended 扩展逻辑卷的大小(追加磁盘空间的过程)

执行lvextend -L +30G /dev/mapper/centos-root1

[root@localhost ~]# lvextend -L +30G /dev/mapper/centos-root Insufficient free space: 7680 extents needed, but only 7679 available#此处提示 available 不足,没有去研究具体问题,直接执行下步操作,[root@localhost ~]# lvextend -L +29.9G /dev/mapper/centos-root Rounding size to boundary between physical extents: 29.90 GiB. Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <46.90 GiB (12006 extents). Logical volume centos/root successfully resized. 最后使用·resizefs2·命令重新加载逻辑卷的大小才能生效

resize2fs /dev/mapper/centos-root

[root@localhost ~]# resize2fs /dev/mapper/centos-rootresize2fs 1.42.9 (28-Dec-2013)resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-rootCouldn't find valid filesystem superblock.

若执行这上一步有尝试打开/dev/mapper/centos-root找不到有效的文件系统超级块的报错的时候,需要使用的是xfs_growfs /dev/mapper/centos-root

[root@localhost ~]# xfs_growfs /dev/mapper/centos-rootmeta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=4455424, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 4455424 to 12294144

ok,看空间去吧。


/dev/mapper/centos-root 这个可以在linux中的df -h中看到,根据要扩展的具体逻辑卷的名称决定
/dev/mapper/centos-root 这个可以在linux中的df -h中看到,根据要扩展的具体逻辑卷的名称决定 ↩︎

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。