虚拟机是ubuntu20,centos操作也一样
(ps:如果重装虚拟机不麻烦的话,建议重装,不过下面的操作也可以用来熟悉linux磁盘命令和文件系统)
1、Ubuntu 关机,选择编辑虚拟机设置,硬盘,在实用工具那里选择“扩展”
填写扩展的磁盘容量
点击扩展后,VMware会提示磁盘已成功扩展。您必须从客户机操作系统内部对磁盘重新进行分区和扩展文件系统。也就是说,这里扩展的磁盘空间,在操作系统里面还不可用,还没生效,需要在操作系统里面进行设置后才能使用。
上述内容参考:这里
2、启动客户机操作系统,查看磁盘情况
fdisk -l
会出现有如下结果:
可选(建议切换到root下操作,避免经常输密码):
没有设置root密码的话先设置密码:
sudo passwd //然后输入当前用户的密码,enter。su root //输入刚刚设置的密码
3、创建分区 sda3
fdisk /dev/sda
根据命令提示创建分区:
WARNING: DOS-compatible mode is deprecated. It s strongly recommended toswitch off the mode (command 'c') and change display units tosectors (command 'u').Command (m for help): n # 输入 n 表示创建新分区Command actione extendedp primary partition (1-4)pPartition number (1-4): 3 # 输入 3 表示sda3,因为前面已经有两个了First cylinder (1306-4568, default 1306):# 回车,按默认值Using default value 1306Last cylinder, +cylinders or +size{K,M,G} (1306-4568, default 4568): # 回车,按默认值Using default value 4568Command (m for help): w# 输入 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.
再次查看分区情况:
fdisk -l
可以看到sda3创建成功,但是还没有挂载
4、重启操作系统
reboot
5、将物理硬盘分区初始化为物理卷,以便被LVM使用
pvcreate /dev/sda3
6、查看逻辑卷组
lvs
如果没有逻辑卷组,先创建:
vgcreate vg0001 /dev/sda3 //vg0001 是新建立的卷组的名称
7、建立逻辑卷
lvcreate -L 10G -n lvol0 vg0001
-L 命令指定逻辑卷的大小,在该状况中是 10 GB,-n 命令指定卷的名称。 指定 vg0001 以便 lvcreate 命令知道从什么卷组获取空间。
8、格式化并挂载逻辑卷
用一个文件系统格式化新的逻辑卷
mkfs -t ext3 /dev/vg0001/lvol0
建立挂载点并将卷挂载到你可使用的地方(这里是/mnt/stuff,按自己需要也可以设置在根目录)。
mkdir /mnt/stuffmount -t ext3 /dev/vg0001/lvol0 /mnt/stuff
9、查看扩展空间后的结果
df -h
10、重启后自动挂载 (这一步好像做了之后重启无法进入图形界面,因为我一直是用命令行的,所以没有受到影响,大家慎用~但是不用的话重启之后还需要手动挂载,有点繁琐)
sudo vim /etc/fstab在最后一行加入: /dev/vg0001/lvol0 /mnt/stuff ext3 defaults 0 0
解释:
1) /dev/vg0001/lvol 这个是你的逻辑卷
2)/mnt/stuff 这个是你要挂载到哪里
3)ext3 文件系统
更多逻辑卷的操作参考:如何在 Ubuntu 中管理和使用逻辑卷管理 LVM