VMware虚拟机下为Ubuntu添加磁盘
20G的磁盘还是不够用啊,正好复习下磁盘分区和逻辑卷。
关闭虚拟机,打开VMware,右键虚拟机点击设置,点下下方的添加,就可以添加磁盘了。
进入虚拟机,查看:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | root@ubuntu: / # fdisk -l Disk / dev / sda: 20 GiB, 21474836480 bytes, 41943040 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 Disklabel type : dos Disk identifier: 0xe0f58c4a Device Boot Start End Sectors Size Id Type / dev / sda1 * 2048 39845887 39843840 19G 83 Linux / dev / sda2 39847934 41940991 2093058 1022M 5 Extended / dev / sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris Disk / dev / sdb: 10 GiB, 10737418240 bytes, 20971520 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 |
新的磁盘/dev/sdb已添加。
创建分区
创建一个5G分区:
1 2 3 4 5 6 7 8 9 10 11 | root@ubuntu: / # fdisk /dev/sdb Command (m for help ): n Partition type p primary ( 0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number ( 1 - 4 , default 1 ): 3 First sector ( 2048 - 20971519 , default 2048 ): Last sector, + sectors or + size{K,M,G,T,P} ( 2048 - 20971519 , default 20971519 ): + 5G Created a new partition 3 of type 'Linux' and of size 5 GiB. |
格式修改为8e(逻辑卷必须):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Command (m for help ): t Selected partition 3 Partition type ( type L to list all types): 8e Changed type of partition 'Linux' to 'Linux LVM' . Command (m for help ): p Disk / dev / sdb: 10 GiB, 10737418240 bytes, 20971520 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 Disklabel type : dos Disk identifier: 0x1df1b6c7 Device Boot Start End Sectors Size Id Type / dev / sdb3 2048 10487807 10485760 5G 8e Linux LVM |
保存:
1 2 3 4 | Command (m for help ): w The partition table has been altered. Calling ioctl() to re - read partition table. Syncing disks. |
创建物理卷PV
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | root@ubuntu: / # pvcreate /dev/sdb3 Physical volume "/dev/sdb3" successfully created root@ubuntu: / # pvdisplay "/dev/sdb3" is a new physical volume of "5.00 GiB" - - - NEW Physical volume - - - PV Name / dev / sdb3 VG Name PV Size 5.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 2rydZg - wXnl - vBlo - EhZ7 - T2YC - CRoc - Gw3NyP root@ubuntu: / # pvs PV VG Fmt Attr PSize PFree / dev / sdb3 lvm2 - - - 5.00g 5.00g |
创建卷组VG
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | root@ubuntu: / # vgcreate vgvg /dev/sdb3 Volume group "vgvg" successfully created root@ubuntu: / # vgdisplay - - - Volume group - - - VG Name vgvg 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 5.00 GiB PE Size 4.00 MiB Total PE 1279 Alloc PE / Size 0 / 0 Free PE / Size 1279 / 5.00 GiB VG UUID t9Ehku - ALdl - FCjl - sakI - sqDe - vx4H - lLqmIz root@ubuntu: / # vgs VG #PV #LV #SN Attr VSize VFree vgvg 1 0 0 wz - - n - 5.00g 5.00g |
创建逻辑卷LV
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | root@ubuntu: / # lvcreate -L 4G -n lvlv vgvg Logical volume "lvlv" created. root@ubuntu: / # lvdisplay - - - Logical volume - - - LV Path / dev / vgvg / lvlv LV Name lvlv VG Name vgvg LV UUID nP2sGc - KGyU - zJZ1 - IFk7 - aMjC - 39tm - sdgkue LV Write Access read / write LV Creation host, time ubuntu, 2018 - 01 - 06 10 : 20 : 19 - 0800 LV Status available # open 0 LV Size 4.00 GiB Current LE 1024 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253 : 0 root@ubuntu: / # lvs LV VG Attr LSize Pool Origin Data % Meta % Move Log Cpy % Sync Convert lvlv vgvg - wi - a - - - - - 4.00g |
格式化并且挂载
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | root@ubuntu: / # mkfs.ext4 /dev/vgvg/lvlv mke2fs 1.42 . 13 ( 17 - May - 2015 ) Creating filesystem with 1048576 4k blocks and 262144 inodes Filesystem UUID: fcffe231 - a2b5 - 429c - b95c - 1884cef6cfeb Superblock backups stored on blocks: 32768 , 98304 , 163840 , 229376 , 294912 , 819200 , 884736 Allocating group tables: done Writing inode tables: done Creating journal ( 32768 blocks): done Writing superblocks and filesystem accounting information: done root@ubuntu: / # mkdir /lvmdata root@ubuntu: / # mount /dev/vgvg/lvlv /lvmdata |
快照卷命令:
1 2 3 4 | lvcreate - s :指定快照卷; - p r:限定快照卷为只读; 格式: lvcreate - L SIZE - s - p r - n LV_NAME / path / to / lv |
创建快照卷:
1 | lvcreate - L 100M - s - p r - n lvm - snap / dev / vgvg / lvlv |
挂载:
1 | mount - o ro / dev / vgvg / lvm - snap / media / |
删除:
1 2 | umount / media / lvremove / dev / vgvg / lvm - snap |
要恢复快照的话,首先卸载:
1 | umount / lvmdata / |
然后使用快照恢复:
1 2 3 4 | root@ubuntu:~ # lvconvert --merge /dev/vgvg/lvm-snap Merging of volume lvm - snap started. lvlv: Merged: 100.0 % lvlv: Merged: 100.0 % |
再挂载即可:
1 | root@ubuntu:~ # mount /dev/vgvg/lvlv /lvmdata/ |
内容已恢复快照内容。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探