root@ubuntu20-04:~# fdisk -l root@ubuntu20-04:~# fdisk -l /dev/sda # 查看磁盘分区情况 GPT PMBR size mismatch (41943039 != 419430399) will be corrected by write. Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors Disk model: VMware Virtual S 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: gpt Disk identifier: 9732D11F-D526-4419-8BCA-35D48F77AACE
Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 4198399 4194304 2G Linux swap /dev/sda3 4198400 41940991 37742592 18G Linux filesystem
root@ubuntu20-04:~# fdisk /dev/sda # 对磁盘sda进行分区
Welcome to fdisk (util-linux 2.34). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
GPT PMBR size mismatch (41943039 != 419430399) will be corrected by write.
Command (m for help): m # 输出Help信息
Help:
GPT M enter protective/hybrid MBR
Generic d delete a partition # 删除分区 F list free unpartitioned space l list known partition types n add a new partition # 新建分区 p print the partition table # 打印分区表 t change a partition type # 修改分区类型 v verify the partition table i print information about a partition
Misc m print this menu # 输出Help信息 x extra functionality (experts only)
Script I load disk layout from sfdisk script file O dump disk layout to sfdisk script file
Save & Exit w write table to disk and exit # 保存并退出 q quit without saving changes # 退出不保存
Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table
Command (m for help): n # 新建分区 Partition number (4-128, default 4): 4 # 分区号,即后来的sda4 First sector (41940992-419430366, default 41940992): # 开始扇区,分区起始位置。enter默认为下一个扇区 Last sector, +/-sectors or +/-size{K,M,G,T,P} (41940992-419430366, default 419430366): +100G # 结束扇区,分区结束位置。enter默认为最后一个扇区
Created a new partition 4 of type 'Linux filesystem' and of size 100 GiB.
Command (m for help): p # 打印分区表 Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors Disk model: VMware Virtual S 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: gpt Disk identifier: 9732D11F-D526-4419-8BCA-35D48F77AACE
Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 4198399 4194304 2G Linux swap /dev/sda3 4198400 41940991 37742592 18G Linux filesystem /dev/sda4 41940992 251656191 209715200 100G Linux filesystem
Command (m for help): t # 修改分区类型 Partition number (1-4, default 4): 4 # 要改变的分区号 Partition type (type L to list all types): L # 输出所有类型 1 EFI System C12A7328-F81F-11D2-BA4B-00A0C93EC93B 2 MBR partition scheme 024DEE41-33E7-11D3-9D69-0008C781F39F 3 Intel Fast Flash D3BFE2DE-3DAF-11DF-BA40-E3A556D89593 4 BIOS boot 21686148-6449-6E6F-744E-656564454649 5 Sony boot partition F4019732-066E-4E12-8273-346C5641494F 6 Lenovo boot partition BFBFAFE7-A34F-448A-9A5B-6213EB736C22 7 PowerPC PReP boot 9E1A2D38-C612-4316-AA26-8B49521E5A8B 8 ONIE boot 7412F7D5-A156-4B13-81DC-867174929325 9 ONIE config D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149 10 Microsoft reserved E3C9E316-0B5C-4DB8-817D-F92DF00215AE 11 Microsoft basic data EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 12 Microsoft LDM metadata 5808C8AA-7E8F-42E0-85D2-E1E90434CFB3 13 Microsoft LDM data AF9B60A0-1431-4F62-BC68-3311714A69AD 14 Windows recovery environment DE94BBA4-06D1-4D40-A16A-BFD50179D6AC 15 IBM General Parallel Fs 37AFFC90-EF7D-4E96-91C3-2D7AE055B174 16 Microsoft Storage Spaces E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D 17 HP-UX data 75894C1E-3AEB-11D3-B7C1-7B03A0000000 18 HP-UX service E2A1E728-32E3-11D6-A682-7B03A0000000 19 Linux swap 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F 20 Linux filesystem 0FC63DAF-8483-4772-8E79-3D69D8477DE4 21 Linux server data 3B8F8425-20E0-4F3B-907F-1A25A76F98E8 22 Linux root (x86) 44479540-F297-41B2-9AF7-D131D5F0458A 23 Linux root (ARM) 69DAD710-2CE4-4E3C-B16C-21A1D49ABED3 24 Linux root (x86-64) 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709 25 Linux root (ARM-64) B921B045-1DF0-41C3-AF44-4C6F280D3FAE 26 Linux root (IA-64) 993D8D3D-F80E-4225-855A-9DAF8ED7EA97 27 Linux reserved 8DA63339-0007-60C0-C436-083AC8230908 28 Linux home 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 29 Linux RAID A19D880F-05FC-4D3B-A006-743F0F84911E 30 Linux extended boot BC13C2FF-59E6-4262-A352-B275FD6F7172 31 Linux LVM E6D6D379-F507-44C2-A23C-238F2A3DF928 32 FreeBSD data 516E7CB4-6ECF-11D6-8FF8-00022D09712B 33 FreeBSD boot 83BD6B9D-7F41-11DC-BE0B-001560B84F0F 34 FreeBSD swap 516E7CB5-6ECF-11D6-8FF8-00022D09712B 35 FreeBSD UFS 516E7CB6-6ECF-11D6-8FF8-00022D09712B 36 FreeBSD ZFS 516E7CBA-6ECF-11D6-8FF8-00022D09712B 37 FreeBSD Vinum 516E7CB8-6ECF-11D6-8FF8-00022D09712B
Partition type (type L to list all types): 20 # 20对应"Linux filesystem"类型
Changed type of partition 'Linux filesystem' to 'Linux filesystem'.
Command (m for help): w # 保存并退出 The partition table has been altered. # 分区表已更改 Syncing disks. # 正在同步磁盘
root@ubuntu20-04:~# fdisk -l /dev/sda # 再次查看磁盘分区情况 Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors Disk model: VMware Virtual S 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: gpt Disk identifier: 9732D11F-D526-4419-8BCA-35D48F77AACE
Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 4198399 4194304 2G Linux swap /dev/sda3 4198400 41940991 37742592 18G Linux filesystem /dev/sda4 41940992 251656191 209715200 100G Linux filesystem
root@ubuntu20-04:/# cat /etc/fstab # 列的详细描述请查看 "fstab (简体中文) - ArchWiki" # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> /dev/disk/by-uuid/0f5010bc-bc78-4f32-a8b8-aeeed49db343 none swap sw 0 0 # / was on /dev/sda3 during curtin installation /dev/disk/by-uuid/a78143b8-b84a-440e-b330-346eae21aac4 / ext4 defaults 0 0 /swap.img none swap sw 0 0
root@ubuntu20-04:~# pvdisplay # 显示物理卷 "/dev/sda4" is a new physical volume of "100.00 GiB" --- NEW Physical volume --- PV Name /dev/sda4 VG Name PV Size 100.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID guJjk2-UNDp-FOaf-ZDw4-iaDG-UMqX-5uDeWu
"/dev/sda5" is a new physical volume of "80.00 GiB" --- NEW Physical volume --- PV Name /dev/sda5 VG Name PV Size 80.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID VpeMAB-grsB-vir9-vYuJ-7WQd-LMmM-s371Mu
root@ubuntu20-04:~# vgcreate volume-group1 /dev/sda4 /dev/sda5 # 创建LVM卷组 Volume group "volume-group1" successfully created root@ubuntu20-04:~# vgdisplay # 显示LVM卷组 --- Volume group --- VG Name volume-group1 System ID Format lvm2 Metadata Areas 2 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 2 Act PV 2 VG Size 179.99 GiB PE Size 4.00 MiB Total PE 46078 Alloc PE / Size 0 / 0 Free PE / Size 46078 / 179.99 GiB VG UUID qy0u2U-k7ef-rchG-coDQ-Wt0o-YGkx-9gtWAY
root@ubuntu20-04:/# vgdisplay volume-group1 --- Volume group --- VG Name volume-group1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 179.99 GiB PE Size 4.00 MiB Total PE 46078 Alloc PE / Size 12800 / 50.00 GiB Free PE / Size 33278 / 129.99 GiB VG UUID qy0u2U-k7ef-rchG-coDQ-Wt0o-YGkx-9gtWAY
root@ubuntu20-04:/# umount /data root@ubuntu20-04:/# lvremove /dev/volume-group1/lv1 Do you really want to remove and DISCARD active logical volume volume-group1/lv1? [y/n]: y Logical volume "lv1" successfully removed
Command (m for help): n Partition number (3-128, default 3): 3 First sector (4198400-419430366, default 4198400): Last sector, +/-sectors or +/-size{K,M,G,T,P} (4198400-419430366, default 419430366):
Created a new partition 3 of type 'Linux filesystem' and of size 198 GiB. Partition #3 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: y
The signature will be removed by a write command.
Command (m for help): p Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors Disk model: VMware Virtual S 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: gpt Disk identifier: 9732D11F-D526-4419-8BCA-35D48F77AACE
Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 4198399 4194304 2G Linux swap /dev/sda3 4198400 419430366 415231967 198G Linux filesystem
Filesystem/RAID signature on partition 3 will be wiped.
保存退出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Command (m for help): w The partition table has been altered. Syncing disks.