Linux虚拟机扩展磁盘

您所在的位置:网站首页 虚拟机怎么扩展磁盘 Linux虚拟机扩展磁盘

Linux虚拟机扩展磁盘

#Linux虚拟机扩展磁盘| 来源: 网络整理| 查看: 265

Linux虚拟机扩展磁盘 1.虚拟机关机,Vmware中扩展磁盘

image-20210726093124228

2.虚拟机开机,查看磁盘大小 [root@hadoop6 ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 891M 6.9G 12% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/mapper/centos-root 17G 17G 20K 100% / /dev/sda1 1014M 150M 865M 15% /boot cm_processes 7.8G 0 7.8G 0% /run/cloudera-scm-agent/process tmpfs 1.6G 0 1.6G 0% /run/user/0 [root@hadoop6 ~]# fdisk -l 磁盘 /dev/sda:536.9 GB, 536870912000 字节,1048576000 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x000ee5d4 设备 Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM 磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节

这里的扩展只是增加了操作系统的磁盘空间,并没有与系统内部的文件目录挂载,所以,磁盘占有量还是不会变化,下一步就是要把扩展的容量挂载到文件目录上去。

3.对新硬盘分区并修改系统类型 [root@hadoop6 ~]# fdisk /dev/sda 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 命令(输入 m 获取帮助):m 命令操作 a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)

依次输入:

n --新建分区 p --默认创建主分区 3 --默认分区号 回车 --默认大小不浪费空间 回车 --默认大小不浪费空间 命令(输入 m 获取帮助):n --新建分区 Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p --默认创建主分区 分区号 (3,4,默认 3):3 --默认 起始 扇区 (41943040-1048575999,默认为 41943040): --回车 将使用默认值 41943040 Last 扇区, +扇区 or +size{K,M,G} (41943040-1048575999,默认为 1048575999): --回车 将使用默认值 1048575999 分区 3 已设置为 Linux 类型,大小设为 480 GiB

输入:w --保持修改

命令(输入 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) 正在同步磁盘。

将system 类型改成Linux LVM

[root@hadoop6 ~]# fdisk -l 磁盘 /dev/sda:536.9 GB, 536870912000 字节,1048576000 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x000ee5d4 设备 Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM /dev/sda3 41943040 1048575999 503316480 83 Linux 磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节

我们的新建分区/dev/sda3,的Id为83不是LVM的。所以,接下来使用fdisk将其改成Id为8e的LVM。

[root@hadoop6 ~]# fdisk /dev/sda 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 命令(输入 m 获取帮助):m 命令操作 a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) 命令(输入 m 获取帮助):t --修改分区系统Id 分区号 (1-3,默认 3):3 --指定分区号 Hex 代码(输入 L 列出所有代码):8e --指定要改成的id号,8e代表LVM 已将分区“Linux”的类型更改为“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) 正在同步磁盘。

fdisk -l 再查看一下是否改成8e 和Linux LVM

[root@hadoop6 ~]# fdisk -l 磁盘 /dev/sda:536.9 GB, 536870912000 字节,1048576000 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x000ee5d4 设备 Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM /dev/sda3 41943040 1048575999 503316480 8e Linux LVM 磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节

重启系统

[root@hadoop6 ~]# reboot 4.扩充新分区

格式化新添加的分区,改为ext4类型

[root@hadoop6 ~]# mkfs.ext4 /dev/sda3 mke2fs 1.42.9 (28-Dec-2013) 文件系统标签= OS type: Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 31457280 inodes, 125829120 blocks 6291456 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=2273312768 3840 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000 Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成

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

创建sda3:

[root@hadoop6 ~]# pvcreate /dev/sda3 WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sda3. Physical volume "/dev/sda3" successfully created.

查看创建结果:

[root@hadoop6 ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size


【本文地址】


今日新闻


推荐新闻


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