View disk size and format
df -hT
➜ ~ df -hT file system type Capacity used available used% Mount point udev devtmpfs 433M 0 433M 0% /dev tmpfs tmpfs 96M 1.3M 95M 2% /run /dev/mapper/ubuntu--vg-ubuntu--lv ext4 29G 5.5G 22G 20% / tmpfs tmpfs 477M 0 477M 0% /dev/shm tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs tmpfs 477M 0 477M 0% /sys/fs/cgroup /dev/nvme0n1p2 ext4 976M 202M 708M 23% /boot /dev/loop1 squashfs 68M 68M 0 100% /snap/lxd/21545 /dev/loop0 squashfs 62M 62M 0 100% /snap/core20/1169 /dev/loop4 squashfs 33M 33M 0 100% /snap/snapd/13640 /dev/loop3 squashfs 56M 56M 0 100% /snap/core18/2128 /dev/loop5 squashfs 56M 56M 0 100% /snap/core18/2246 /dev/loop6 squashfs 33M 33M 0 100% /snap/snapd/12704 /dev/loop7 squashfs 68M 68M 0 100% /snap/lxd/21835 tmpfs tmpfs 96M 0 96M 0% /run/user/0
From the above information: the root directory / format is ext4 (this parameter will be used below), the size is 60GB, and the path is / dev / mapper / Ubuntu -- VG Ubuntu -- LV (logical volume path, this parameter will be used below)
View unused disk information
lsblk
➜ ~ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 61.9M 1 loop /snap/core20/1169 loop1 7:1 0 67.3M 1 loop /snap/lxd/21545 loop3 7:3 0 55.4M 1 loop /snap/core18/2128 loop4 7:4 0 32.5M 1 loop /snap/snapd/13640 loop5 7:5 0 55.5M 1 loop /snap/core18/2246 loop6 7:6 0 32.3M 1 loop /snap/snapd/12704 loop7 7:7 0 67.2M 1 loop /snap/lxd/21835 sr0 11:0 1 1024M 0 rom nvme0n1 259:0 0 60G 0 disk ├─nvme0n1p1 259:1 0 1M 0 part ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 59G 0 part └─ubuntu--vg-ubuntu--lv 253:0 0 29.5G 0 lvm / nvme0n2 259:4 0 60G 0 disk
From the above information: the root directory / disk is nvme0n1, the type is ext4, and nvme0n2 is a newly mounted unformatted data disk of 60GB
View partition information
fdisk -l
➜ ~ fdisk -l Disk /dev/loop0: 61.85 MiB,64835584 Bytes, 126632 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop1: 67.26 MiB,70516736 Bytes, 137728 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop3: 55.45 MiB,58130432 Bytes, 113536 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop4: 32.45 MiB,34017280 Bytes, 66440 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop5: 55.51 MiB,58191872 Bytes, 113656 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop6: 32.3 MiB,33865728 Bytes, 66144 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop7: 67.25 MiB,70508544 Bytes, 137712 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/nvme0n1: 60 GiB,64424509440 Bytes, 125829120 sectors Disk model: VMware Virtual NVMe Disk Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk label type: gpt Disk identifier: BF757F1D-75C3-4C0D-A220-AF7FA91A4A6A equipment starting point end Sector size type /dev/nvme0n1p1 2048 4095 2048 1M BIOS start-up /dev/nvme0n1p2 4096 2101247 2097152 1G Linux file system /dev/nvme0n1p3 2101248 125827071 123725824 59G Linux file system Disk /dev/nvme0n2: 60 GiB,64424509440 Bytes, 125829120 sectors Disk model: VMware Virtual NVMe Disk Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 29.51 GiB,31675383808 Bytes, 61865984 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte
From the above information: the root directory / disk is nvme0n1, and the disk label type is GPT; The path of nvme0n2 is / dev/nvme0n2
Add logical volume
Know from the above information that the partition is gpt, and use the tool gdisk; If the partition is mbr, use the tool fdisk
gdisk /dev/nvme0n2
➜ ~ gdisk /dev/nvme0n2 GPT fdisk (gdisk) version 1.0.5 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries in memory. Command (? for help): n Partition number (1-128, default 1): First sector (34-125829086, default = 2048) or {+-}size: Last sector (2048-125829086, default = 125829086) or {+-}size: Current type is 8300 (Linux filesystem) Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): p Disk /dev/nvme0n2: 125829120 sectors, 60.0 GiB Model: VMware Virtual NVMe Disk Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): A73C7A1B-22DA-40A2-A10A-A12B1489A828 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 125829086 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 125829086 60.0 GiB 8300 Linux filesystem Command (? for help): t Using 1 Current type is 8300 (Linux filesystem) Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): Y OK; writing new GUID partition table (GPT) to /dev/nvme0n2. The operation has completed successfully.
View the disk information after creating a new partition
fdisk -l
➜ ~ fdisk -l Disk /dev/loop0: 61.85 MiB,64835584 Bytes, 126632 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop1: 67.26 MiB,70516736 Bytes, 137728 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop3: 55.45 MiB,58130432 Bytes, 113536 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop4: 32.45 MiB,34017280 Bytes, 66440 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop5: 55.51 MiB,58191872 Bytes, 113656 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop6: 32.3 MiB,33865728 Bytes, 66144 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/loop7: 67.25 MiB,70508544 Bytes, 137712 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk /dev/nvme0n1: 60 GiB,64424509440 Bytes, 125829120 sectors Disk model: VMware Virtual NVMe Disk Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk label type: gpt Disk identifier: BF757F1D-75C3-4C0D-A220-AF7FA91A4A6A equipment starting point end Sector size type /dev/nvme0n1p1 2048 4095 2048 1M BIOS start-up /dev/nvme0n1p2 4096 2101247 2097152 1G Linux file system /dev/nvme0n1p3 2101248 125827071 123725824 59G Linux file system Disk /dev/nvme0n2: 60 GiB,64424509440 Bytes, 125829120 sectors Disk model: VMware Virtual NVMe Disk Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte Disk label type: gpt Disk identifier: A73C7A1B-22DA-40A2-A10A-A12B1489A828 equipment starting point end Sector size type /dev/nvme0n2p1 2048 125829086 125827039 60G Linux file system Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 29.51 GiB,31675383808 Bytes, 61865984 sectors Units: sectors / 1 * 512 = 512 byte Sector Size (logic/Physics): 512 byte / 512 byte I/O size(minimum/optimum): 512 byte / 512 byte
It is found from the above information that there is an additional partition path / dev/nvme0n2p1, which will be used for formatting below
Format disk
Because the root directory is in ext4 format, / dev / nvme0n2p1 (this parameter is in Click jump Get)
mkfs -t ext4 /dev/nvme0n2p1
➜ ~ mkfs -t ext4 /dev/nvme0n2p1 mke2fs 1.45.5 (07-Jan-2020) Create 15728379 blocks (4 blocks each) k)And 3932160 inode File system for file system UUID: 49ff51fe-b635-4880-9708-b96215eb09cd Backups of superblocks are stored in the following blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424 Assigning group table: done Writing inode Table: completed Create log (65536 blocks) complete Write superblock and file system account statistics: completed
Create physical volume
/dev/nvme0n2p1 (this parameter is in the Click jump Get)
pvcreate /dev/nvme0n2p1
➜ ~ pvcreate /dev/nvme0n2p1 WARNING: ext4 signature detected on /dev/nvme0n2p1 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/nvme0n2p1. Physical volume "/dev/nvme0n2p1" successfully created.
Viewing volume groups
vgdisplay
➜ ~ vgdisplay --- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size <59.00 GiB PE Size 4.00 MiB Total PE 15103 Alloc PE / Size 7552 / 29.50 GiB Free PE / Size 7551 / <29.50 GiB VG UUID upx2M2-D30c-REdO-uaIg-eiAr-YkzO-eDIzc1
According to the above information, the volume group name of the system partition is Ubuntu VG (this parameter will be used below)
Join volume group
The physical volume / dev/nvme0n2p1 parameter is Click jump Get join volume group Ubuntu VG (this parameter is in Click jump Get)
vgextend ubuntu-vg /dev/nvme0n2p1
➜ ~ vgextend ubuntu-vg /dev/nvme0n2p1 Volume group "ubuntu-vg" successfully extended
Viewing volume group information
vgdisplay
➜ ~ vgdisplay --- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 118.99 GiB PE Size 4.00 MiB Total PE 30462 Alloc PE / Size 7552 / 29.50 GiB Free PE / Size 22910 / 89.49 GiB VG UUID upx2M2-D30c-REdO-uaIg-eiAr-YkzO-eDIzc1
From the above information, we know that the Free PE / Size is 22910 / 89.49 gib, and 22910 (this parameter will be used later) is used for expansion
Logical volume expansion
Logical volume expansion, expansion / dev / mapper / Ubuntu -- VG Ubuntu -- LV (this parameter is in Click jump Get) + 22910 (this parameter is in Click jump Get)
lvextend -l +22910 /dev/mapper/ubuntu--vg-ubuntu--lv
➜ ~ lvextend -l +22910 /dev/mapper/ubuntu--vg-ubuntu--lv Size of logical volume ubuntu-vg/ubuntu-lv changed from 29.50 GiB (7552 extents) to 118.99 GiB (30462 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized.
View logical volume size
lvdisplay
➜ ~ lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID 28ISao-1q5A-fhRL-eH7X-vSz9-mXJ4-cTWUqR LV Write Access read/write LV Creation host, time ubuntu-server, 2021-08-15 18:34:19 +0000 LV Status available # open 1 LV Size 118.99 GiB Current LE 30462 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
According to the above information, LV Size has become 118.99 GiB
Capacity expansion file system
If the file system is in XFS format, use xfs_growfs. Here, I use resize 2fs in ext4 format
Capacity expansion / dev / mapper / Ubuntu -- VG Ubuntu -- LV (this parameter is in Click jump Get)
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
➜ ~ resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv resize2fs 1.45.5 (07-Jan-2020) /dev/mapper/ubuntu--vg-ubuntu--lv The file system on is mounted on /;Online resizing required old_desc_blocks = 4, new_desc_blocks = 15 /dev/mapper/ubuntu--vg-ubuntu--lv The file system on is now 31193088 blocks (4 blocks each) k)
View expansion results
df -hT
➜ ~ df -hT file system type Capacity used available used% Mount point udev devtmpfs 433M 0 433M 0% /dev tmpfs tmpfs 96M 1.3M 95M 2% /run /dev/mapper/ubuntu--vg-ubuntu--lv ext4 117G 5.5G 107G 5% / tmpfs tmpfs 477M 0 477M 0% /dev/shm tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs tmpfs 477M 0 477M 0% /sys/fs/cgroup /dev/nvme0n1p2 ext4 976M 202M 708M 23% /boot /dev/loop1 squashfs 68M 68M 0 100% /snap/lxd/21545 /dev/loop0 squashfs 62M 62M 0 100% /snap/core20/1169 /dev/loop4 squashfs 33M 33M 0 100% /snap/snapd/13640 /dev/loop3 squashfs 56M 56M 0 100% /snap/core18/2128 /dev/loop5 squashfs 56M 56M 0 100% /snap/core18/2246 /dev/loop6 squashfs 33M 33M 0 100% /snap/snapd/12704 /dev/loop7 squashfs 68M 68M 0 100% /snap/lxd/21835 tmpfs tmpfs 96M 0 96M 0% /run/user/0