Steps : 1.
LVM partition create
2. PV create
3. VG create
4. LV create
Note : ext2, ext3, ext4 file system can be extend and reduce , but xfs file system can only extend .
----------------LVM partition create----------------------------
[root@localhost ~]# fdisk -l
Disk /dev/nvme0n1: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: VMware Virtual NVMe Disk
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: 0x1ced91b6
Device Boot Start End Sectors Size Id Type
/dev/nvme0n1p1 * 2048 10487807 10485760 5G 83 Linux
/dev/nvme0n1p2 10487808 31459327 20971520 10G 83 Linux
/dev/nvme0n1p3 31459328 41945087 10485760 5G 83 Linux
/dev/nvme0n1p4 41945088 62914559 20969472 10G 5 Extended
/dev/nvme0n1p5 41947136 50335743 8388608 4G 82 Linux swap / Solaris
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual I
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdb: 6 GiB, 6442450944 bytes, 12582912 sectors
Disk model: VMware Virtual I
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@localhost ~]#
[root@localhost ~]# parted /dev/nvme0n1 print free
Model: VMware Virtual NVMe Disk (nvme)
Disk /dev/nvme0n1: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1024B 1049kB 1048kB Free Space
1 1049kB 5370MB 5369MB primary xfs boot
2 5370MB 16.1GB 10.7GB primary xfs
3 16.1GB 21.5GB 5369MB primary xfs
4 21.5GB 32.2GB 10.7GB extended
21.5GB 21.5GB 973kB Free Space
5 21.5GB 25.8GB 4295MB logical linux-swap(v1)
25.8GB 32.2GB 6440MB Free Space
[root@localhost ~]#
[root@localhost ~]# parted /dev/sda print free
Error: /dev/sda: unrecognised disk label
Model: ATA VMware Virtual I (scsi)
Disk /dev/sda: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
[root@localhost ~]#
[root@localhost ~]# parted /dev/sdb print free
Error: /dev/sdb: unrecognised disk label
Model: ATA VMware Virtual I (scsi)
Disk /dev/sdb: 6442MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sda (Make 3 LVM partition)
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xe9de9888.
Command (m for help): g
Created a new GPT disklabel (GUID: ABC79EBF-94B3-114E-82B1-22E19C51730F).
Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-10485726, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-10485726, default 10485726): +1G
Created a new partition 1 of type 'Linux filesystem' and of size 1 GiB.
Command (m for help): n
Partition number (2-128, default 2): 2
First sector (2099200-10485726, default 2099200): +1G
Value out of range.
First sector (2099200-10485726, default 2099200):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2099200-10485726, default 10485726): +1G
Created a new partition 2 of type 'Linux filesystem' and of size 1 GiB.
Command (m for help): n
Partition number (3-128, default 3): 3
First sector (4196352-10485726, default 4196352):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4196352-10485726, default 10485726): +1G
Created a new partition 3 of type 'Linux filesystem' and of size 1 GiB.
Command (m for help):m
Command (m for help): m
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
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Command (m for help): 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 (x86-64) 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
24 Linux root (ARM) 69DAD710-2CE4-4E3C-B16C-21A1D49ABED3
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 LVM E6D6D379-F507-44C2-A23C-238F2A3DF928
31 Linux variable data 4D21B016-B534-45C2-A9FB-5C16E091FD2D
Command (m for help): t
Command (m for help): t
Partition number (1-3, default 3): 1
Partition type or alias (type L to list all): 30
Changed type of partition 'Linux filesystem' to 'Linux LVM'.
Command (m for help): t
Partition number (1-3, default 3): 2
Partition type or alias (type L to list all): 30
Changed type of partition 'Linux filesystem' to 'Linux LVM'.
Command (m for help): t
Partition number (1-3, default 3): 3
Partition type or alias (type L to list all): 30
Changed type of partition 'Linux filesystem' to 'Linux LVM'.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
[root@localhost ~]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-3
[root@localhost ~]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-3
[root@localhost ~]#
[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual I
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: ABC79EBF-94B3-114E-82B1-22E19C51730F
Device Start End Sectors Size Type
/dev/sda1 2048 2099199 2097152 1G Linux LVM
/dev/sda2 2099200 4196351 2097152 1G Linux LVM
/dev/sda3 4196352 6293503 2097152 1G Linux LVM
[root@localhost ~]#
--------------------------PV Create----------------------------------------------
[root@localhost ~]# pvcreate /dev/sda1 /dev/sda2 /dev/sda3
Physical volume "/dev/sda1" successfully created.
Physical volume "/dev/sda2" successfully created.
Physical volume "/dev/sda3" successfully created.
Creating devices file /etc/lvm/devices/system.devices
[root@localhost ~]#
[root@localhost ~]# pvdisplay
"/dev/sda1" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda1
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID fFMV0w-zfB9-4DS9-vyT2-PQ3A-WgIM-eWQ0pL
"/dev/sda2" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda2
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Dy0npJ-FqdS-q8yS-MElB-ki4b-GovR-5jnsUR
"/dev/sda3" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 5t145h-NjAB-15Vs-3kta-OO6r-idnX-0PAWBp
[root@localhost ~]#
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 lvm2 --- 1.00g 1.00g
/dev/sda2 lvm2 --- 1.00g 1.00g
/dev/sda3 lvm2 --- 1.00g 1.00g
[root@localhost ~]#
-----------------------------VG create-------------------------------------------------
[root@localhost ~]# vgcreate myvg /dev/sda1 /dev/sda2
Volume group "myvg" successfully c
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name myvg
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 1.99 GiB
PE Size 4.00 MiB
Total PE 510
Alloc PE / Size 0/0
Free PE / Size 510 / 1.99 GiB
VG UUID oHFOGl-tnHT-AopL-soK8-r38e-w0fr-axanCS
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 2 0 0 wz--n- 1.99g 1.99g
[root@localhost ~]#
--------------------------------LV create---------------------------------------------
[root@localhost ~]# lvcreate -L 800M -n mylv myvg
Logical volume "mylv" created.
[root@localhost ~]#
[root@localhost ~]# lvcreate -L 800M -n mylv myvg
Logical volume "mylv" created.
[root@localhost ~]#
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID VkeV18-Z2TY-Ko21-Z6DR-MQvY-AkCe-lNuvVf
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-01-24 09:44:21 +0600
LV Status available
# open 0
LV Size 800.00 MiB
Current LE 200
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mylv myvg -wi-a----- 800.00m
[root@localhost ~]#
[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 204800 4k blocks and 51296 inodes
Filesystem UUID: 0d3edd3f-8f34-40e6-a63d-456696d682ec
Superblock backups stored on blocks:
32768, 98304, 163840
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]#
[root@localhost ~]# blkid /dev/myvg/mylv
/dev/myvg/mylv: UUID="0d3edd3f-8f34-40e6-a63d-456696d682ec" BLOCK_SIZE="4096" TYPE="ext4"
[root@localhost ~]#
[root@localhost ~]# vim /etc/fstab
UUID="0d3edd3f-8f34-40e6-a63d-456696d682ec" /lv1 ext4 defaults 00
[root@localhost ~]# mount -av
/ : ignored
/boot : already mounted
/home : already mounted
none : ignored
mount: /lv1 does not contain SELinux labels.
You just mounted a file system that supports labels which does not
contain labels, onto an SELinux box. It is likely that confined
applications will generate AVC messages and not be allowed access to
this file system. For more details see restorecon(8) and mount(8).
/lv1 : successfully mounted
[root@localhost ~]#
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 846M 0 846M 0% /dev
tmpfs tmpfs 875M 0 875M 0% /dev/shm
tmpfs tmpfs 350M 9.8M 341M 3% /run
/dev/nvme0n1p3 xfs 5.0G 3.9G 1.2G 77% /
/dev/nvme0n1p2 xfs 10G 104M 9.9G 2% /home
/dev/nvme0n1p1 xfs 5.0G 285M 4.8G 6% /boot
tmpfs tmpfs 175M 92K 175M 1% /run/user/0
/dev/sr0 iso9660 8.0G 8.0G 0 100% /run/media/root/RHEL-9-0-0-BaseOS-x86_64
/dev/mapper/myvg-mylv ext4 770M 24K 714M 1% /lv1
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 5G 0 disk
├─sda1 8:1 0 1G 0 part
│ └─myvg-mylv 253:0 0 800M 0 lvm /lv1
├─sda2 8:2 0 1G 0 part
└─sda3 8:3 0 1G 0 part
sdb 8:16 0 6G 0 disk
sr0 11:0 1 7.9G 0 rom /run/media/root/RHEL-9-0-0-BaseOS-x86_64
nvme0n1 259:0 0 30G 0 disk
├─nvme0n1p1 259:1 0 5G 0 part /boot
├─nvme0n1p2 259:2 0 10G 0 part /home
├─nvme0n1p3 259:3 0 5G 0 part /
├─nvme0n1p4 259:4 0 1K 0 part
└─nvme0n1p5 259:5 0 4G 0 part [SWAP]
[root@localhost ~]# lvcreate -L 1100M -n mylv2 myvg
Logical volume "mylv2" created.
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID VkeV18-Z2TY-Ko21-Z6DR-MQvY-AkCe-lNuvVf
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-01-24 09:44:21 +0600
LV Status available
# open 1
LV Size 800.00 MiB
Current LE 200
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/myvg/mylv2
LV Name mylv2
VG Name myvg
LV UUID vX62Ay-kfvb-LhCs-d3jL-Ikb1-c7ff-97zeL8
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-01-24 09:59:44 +0600
LV Status available
# open 0
LV Size 1.07 GiB
Current LE 275
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@localhost ~]# blkid /dev/myvg/mylv2
/dev/myvg/mylv2: UUID="b63f9dd1-a5fc-48d6-8924-2cd699f5dfdc" SEC_TYPE="ext2"
BLOCK_SIZE="4096" TYPE="ext3"
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mkdir /lv2
[root@localhost ~]# mount -av
/ : ignored
/boot : already mounted
/home : already mounted
none : ignored
/lv1 : already mounted
mount: /lv2 does not contain SELinux labels.
You just mounted a file system that supports labels which does not
contain labels, onto an SELinux box. It is likely that confined
applications will generate AVC messages and not be allowed access to
this file system. For more details see restorecon(8) and mount(8).
/lv2 : successfully mounted
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 846M 0 846M 0% /dev
tmpfs tmpfs 875M 0 875M 0% /dev/shm
tmpfs tmpfs 350M 9.8M 341M 3% /run
/dev/nvme0n1p3 xfs 5.0G 3.9G 1.2G 77% /
/dev/nvme0n1p2 xfs 10G 104M 9.9G 2% /home
/dev/nvme0n1p1 xfs 5.0G 285M 4.8G 6% /boot
tmpfs tmpfs 175M 92K 175M 1% /run/user/0
/dev/sr0 iso9660 8.0G 8.0G 0 100% /run/media/root/RHEL-9-0-0-BaseOS-x86_64
/dev/mapper/myvg-mylv ext4 770M 24K 714M 1% /lv1
/dev/mapper/myvg-mylv2 ext3 1.1G 60K 995M 1% /lv2
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 5G 0 disk
├─sda1 8:1 0 1G 0 part
│ ├─myvg-mylv 253:0 0 800M 0 lvm /lv1
│ └─myvg-mylv2 253:1 0 1.1G 0 lvm /lv2
├─sda2 8:2 0 1G 0 part
│ └─myvg-mylv2 253:1 0 1.1G 0 lvm /lv2
└─sda3 8:3 0 1G 0 part
sdb 8:16 0 6G 0 disk
sr0 11:0 1 7.9G 0 rom /run/media/root/RHEL-9-0-0-BaseOS-x86_64
nvme0n1 259:0 0 30G 0 disk
├─nvme0n1p1 259:1 0 5G 0 part /boot
├─nvme0n1p2 259:2 0 10G 0 part /home
├─nvme0n1p3 259:3 0 5G 0 part /
├─nvme0n1p4 259:4 0 1K 0 part
└─nvme0n1p5 259:5 0 4G 0 part [SWAP]
[root@localhost ~]#
------------------------------------------LV resize----------------------------------------------
[root@localhost ~]# lvresize -L 900M -r /dev/myvg/mylv
Size of logical volume myvg/mylv changed from 800.00 MiB (200 extents) to 900.00 MiB (225 extents).
Logical volume myvg/mylv successfully resized.
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/myvg-mylv is mounted on /lv1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/myvg-mylv is now 230400 (4k) blocks long.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mylv myvg -wi-ao---- 900.00m
mylv2 myvg -wi-ao---- 1.07g
[root@localhost ~]#
[root@localhost ~]# lvresize -L 500M -r /dev/myvg/mylv2
Do you want to unmount "/lv2" ? [Y|n] y
fsck from util-linux 2.37.4
/dev/mapper/myvg-mylv2: 11/70416 files (0.0% non-contiguous), 12976/281600 blocks
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/mapper/myvg-mylv2 to 128000 (4k) blocks.
The filesystem on /dev/mapper/myvg-mylv2 is now 128000 (4k) blocks long.
Size of logical volume myvg/mylv2 changed from 1.07 GiB (275 extents) to 500.00 MiB (125 extents).
Logical volume myvg/mylv2 successfully resized.
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mylv myvg -wi-ao---- 900.00m
mylv2 myvg -wi-ao---- 500.00m
[root@localhost ~]#
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 846M 0 846M 0% /dev
tmpfs tmpfs 875M 0 875M 0% /dev/shm
tmpfs tmpfs 350M 9.8M 341M 3% /run
/dev/nvme0n1p3 xfs 5.0G 3.9G 1.2G 77% /
/dev/nvme0n1p2 xfs 10G 104M 9.9G 2% /home
/dev/nvme0n1p1 xfs 5.0G 285M 4.8G 6% /boot
tmpfs tmpfs 175M 92K 175M 1% /run/user/0
/dev/sr0 iso9660 8.0G 8.0G 0 100% /run/media/root/RHEL-9-0-0-BaseOS-x86_64
/dev/mapper/myvg-mylv ext4 870M 2.0M 812M 1% /lv1
/dev/mapper/myvg-mylv2 ext3 461M 876K 435M 1% /lv2
[root@localhost ~]#
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 5G 0 disk
├─sda1 8:1 0 1G 0 part
│ └─myvg-mylv 253:0 0 900M 0 lvm /lv1
├─sda2 8:2 0 1G 0 part
│ └─myvg-mylv2 253:1 0 500M 0 lvm /lv2
└─sda3 8:3 0 1G 0 part
sdb 8:16 0 6G 0 disk
sr0 11:0 1 7.9G 0 rom /run/media/root/RHEL-9-0-0-BaseOS-x86_64
nvme0n1 259:0 0 30G 0 disk
├─nvme0n1p1 259:1 0 5G 0 part /boot
├─nvme0n1p2 259:2 0 10G 0 part /home
├─nvme0n1p3 259:3 0 5G 0 part /
├─nvme0n1p4 259:4 0 1K 0 part
└─nvme0n1p5 259:5 0 4G 0 part [SWAP]
[root@localhost ~]#
[root@localhost ~]# fdisk -l
Disk /dev/nvme0n1: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: VMware Virtual NVMe Disk
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: 0x1ced91b6
Device Boot Start End Sectors Size Id Type
/dev/nvme0n1p1 * 2048 10487807 10485760 5G 83 Linux
/dev/nvme0n1p2 10487808 31459327 20971520 10G 83 Linux
/dev/nvme0n1p3 31459328 41945087 10485760 5G 83 Linux
/dev/nvme0n1p4 41945088 62914559 20969472 10G 5 Extended
/dev/nvme0n1p5 41947136 50335743 8388608 4G 82 Linux swap / Solaris
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual I
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: ABC79EBF-94B3-114E-82B1-22E19C51730F
Device Start End Sectors Size Type
/dev/sda1 2048 2099199 2097152 1G Linux LVM
/dev/sda2 2099200 4196351 2097152 1G Linux LVM
/dev/sda3 4196352 6293503 2097152 1G Linux LVM
Disk /dev/sdb: 6 GiB, 6442450944 bytes, 12582912 sectors
Disk model: VMware Virtual I
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/myvg-mylv: 900 MiB, 943718400 bytes, 1843200 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
Disk /dev/mapper/myvg-mylv2: 500 MiB, 524288000 bytes, 1024000 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
[root@localhost ~]#
----------------------------xfs file system LV-----------------------------------
[root@localhost ~]# lvcreate -L 500M -n mylv3 myvg
Logical volume "mylv3" created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mylv myvg -wi-ao---- 900.00m
mylv2 myvg -wi-ao---- 500.00m
mylv3 myvg -wi-a----- 500.00m
[root@localhost ~]# partx -a /dev/sd
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb
[root@localhost ~]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-3
[root@localhost ~]# mkfs.xfs /dev/myvg/mylv3
meta-data=/dev/myvg/mylv3 isize=512 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=1368, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# blkid /dev/myvg/mylv3
/dev/myvg/mylv3: UUID="f3f90262-a9b2-4585-8e74-f4fe15f9e4d3" BLOCK_SIZE="512" TYPE="xfs"
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# [root@localhost ~]# mkdir /lv3
[root@localhost ~]# mount -av
/ : ignored
/boot : already mounted
/home : already mounted
none : ignored
/lv1 : already mounted
/lv2 : already mounted
mount: /lv3 does not contain SELinux labels.
You just mounted a file system that supports labels which does not
contain labels, onto an SELinux box. It is likely that confined
applications will generate AVC messages and not be allowed access to
this file system. For more details see restorecon(8) and mount(8).
/lv3 : successfully mounted
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 846M 0 846M 0% /dev
tmpfs tmpfs 875M 0 875M 0% /dev/shm
tmpfs tmpfs 350M 9.8M 341M 3% /run
/dev/nvme0n1p3 xfs 5.0G 3.9G 1.2G 77% /
/dev/nvme0n1p2 xfs 10G 104M 9.9G 2% /home
/dev/nvme0n1p1 xfs 5.0G 285M 4.8G 6% /boot
tmpfs tmpfs 175M 92K 175M 1% /run/user/0
/dev/sr0 iso9660 8.0G 8.0G 0 100% /run/media/root/RHEL-9-0-0-BaseOS-x86_64
/dev/mapper/myvg-mylv ext4 870M 2.0M 812M 1% /lv1
/dev/mapper/myvg-mylv2 ext3 461M 876K 435M 1% /lv2
/dev/mapper/myvg-mylv3 xfs 495M 29M 466M 6% /lv3
[root@localhost ~]# lvresize -L 600M -r /dev/myvg/mylv3
Size of logical volume myvg/mylv3 changed from 500.00 MiB (125 extents) to 600.00 MiB (150 extents).
Logical volume myvg/mylv3 successfully resized.
meta-data=/dev/mapper/myvg-mylv3 isize=512 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=1368, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 128000 to 153600
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mylv myvg -wi-ao---- 900.00m
mylv2 myvg -wi-ao---- 500.00m
mylv3 myvg -wi-ao---- 600.00m
[root@localhost ~]# lvresize -L 400M -r /dev/myvg/mylv3
fsadm: Xfs filesystem shrinking is unsupported.
/usr/sbin/fsadm failed: 1
Filesystem resize failed.
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mylv myvg -wi-ao---- 900.00m
mylv2 myvg -wi-ao---- 500.00m
mylv3 myvg -wi-ao---- 600.00m
[root@localhost ~]#
---------------------------------VG extend-----------------------------------------------
[root@localhost ~]# vgextend myvg /dev/sda3
Volume group "myvg" successfully extended
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 3 3 0 wz--n- <2.99g <1.04g
[root@localhost ~]#
---------------------------------VG create with 16M PE size-----------------------------------
[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual I
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: ABC79EBF-94B3-114E-82B1-22E19C51730F
Device Start End Sectors Size Type
/dev/sda1 2048 2099199 2097152 1G Linux LVM
/dev/sda2 2099200 4196351 2097152 1G Linux LVM
/dev/sda3 4196352 6293503 2097152 1G Linux LVM
[root@localhost ~]# parted /dev/sda print free
Model: ATA VMware Virtual I (scsi)
Disk /dev/sda: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
17.4kB 1049kB 1031kB Free Space
1 1049kB 1075MB 1074MB lvm
2 1075MB 2149MB 1074MB lvm
3 2149MB 3222MB 1074MB lvm
3222MB 5369MB 2146MB Free Space
[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help): n
Partition number (4-128, default 4): 4
First sector (6293504-10485726, default 6293504):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (6293504-10485726, default 10485726): +1G
Created a new partition 4 of type 'Linux filesystem' and of size 1 GiB.
Command (m for help): n
Partition number (5-128, default 5): 5
First sector (8390656-10485726, default 8390656):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8390656-10485726, default 10485726): +1G
Value out of range.
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8390656-10485726, default 10485726): +900M
Created a new partition 5 of type 'Linux filesystem' and of size 900 MiB.
Command (m for help): t
Partition number (1-5, default 5): 4
Partition type or alias (type L to list all): 30
Changed type of partition 'Linux filesystem' to 'Linux LVM'.
Command (m for help): t
Partition number (1-5, default 5): 5
Partition type or alias (type L to list all): 30
Changed type of partition 'Linux filesystem' to 'Linux LVM'.
Command (m for help): w
The partition table has been altered.
Syncing disks.
[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual I
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: ABC79EBF-94B3-114E-82B1-22E19C51730F
Device Start End Sectors Size Type
/dev/sda1 2048 2099199 2097152 1G Linux LVM
/dev/sda2 2099200 4196351 2097152 1G Linux LVM
/dev/sda3 4196352 6293503 2097152 1G Linux LVM
/dev/sda4 6293504 8390655 2097152 1G Linux LVM
/dev/sda5 8390656 10233855 1843200 900M Linux LVM
[root@localhost ~]#
[root@localhost ~]# pvcreate /dev/sda4 /dev/sda5
Physical volume "/dev/sda4" successfully created.
Physical volume "/dev/sda5" successfully created.
[root@localhost ~]#
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 myvg lvm2 a-- 1020.00m 40.00m
/dev/sda2 myvg lvm2 a-- 1020.00m 0
/dev/sda3 myvg lvm2 a-- 1020.00m 1020.00m
/dev/sda4 lvm2 --- 1.00g 1.00g
/dev/sda5 lvm2 --- 900.00m 900.00m
[root@localhost ~]#
[root@localhost ~]# vgcreate -s 16M myvg2 /dev/sda{4,5}
Volume group "myvg2" successfully created
[root@localhost ~]#
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 3 3 0 wz--n- <2.99g <1.04g
myvg2 2 0 0 wz--n- <1.86g <1.86g
[root@localhost ~]#
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name myvg2
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 <1.86 GiB
PE Size 16.00 MiB
Total PE 119
Alloc PE / Size 0/0
Free PE / Size 119 / <1.86 GiB
VG UUID bsOQZg-1I0D-hX8L-04Nq-vIie-WnDV-ixqX3f
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 10
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 3
Act PV 3
VG Size <2.99 GiB
PE Size 4.00 MiB
Total PE 765
Alloc PE / Size 500 / 1.95 GiB
Free PE / Size 265 / <1.04 GiB
VG UUID oHFOGl-tnHT-AopL-soK8-r38e-w0fr-axanCS
[root@localhost ~]#
--------------------------------LV create with 100 PE----------------------------------------------
[root@nodeb ~]# lvcreate -n ourlv -l 20 myvg2
Logical volume "ourlv" created.
[root@nodeb ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
ourlv myvg2 -wi-a----- 320.00m
mydatabase myvolume -wi-ao---- 504.00m
or
lvcreate -n ourlv -L 500M myvg2
----------------------------------------SWAP create from VG-----------------------------------------
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem: 1748 995 179 20 573 579
Swap: 4095 0 4095
[root@localhost ~]#
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/nvme0n1p5 partition 4194300 0 -2
[root@localhost ~]#
[root@localhost ~]# lvcreate -L 700M -n newswap myvg2
Rounding up size to full physical extent 704.00 MiB
Logical volume "newswap" created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mylv myvg -wi-ao---- 900.00m
mylv2 myvg -wi-ao---- 500.00m
mylv3 myvg -wi-ao---- 600.00m
newswap myvg2 -wi-a----- 704.00m
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg2/newswap
LV Name newswap
VG Name myvg2
LV UUID lqCDy8-A4gF-PCd1-ylro-hudq-4MVs-YvK07D
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-01-24 12:23:00 +0600
LV Status available
# open 0
LV Size 704.00 MiB
Current LE 44
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID VkeV18-Z2TY-Ko21-Z6DR-MQvY-AkCe-lNuvVf
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-01-24 09:44:21 +0600
LV Status available
# open 1
LV Size 900.00 MiB
Current LE 225
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/myvg/mylv2
LV Name mylv2
VG Name myvg
LV UUID vX62Ay-kfvb-LhCs-d3jL-Ikb1-c7ff-97zeL8
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-01-24 09:59:44 +0600
LV Status available
# open 1
LV Size 500.00 MiB
Current LE 125
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/myvg/mylv3
LV Name mylv3
VG Name myvg
LV UUID n7AeyZ-2EUV-xj5b-59dI-Wl7j-HGDx-06u7P5
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-01-24 11:31:32 +0600
LV Status available
# open 1
LV Size 600.00 MiB
Current LE 150
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
[root@localhost ~]# mkswap /dev/myvg2/newswap
Setting up swapspace version 1, size = 704 MiB (738193408 bytes)
no label, UUID=15c437de-5a1f-4ec1-a621-f60087554c2f
[root@localhost ~]# blkid /dev/myvg2/newswap
/dev/myvg2/newswap: UUID="15c437de-5a1f-4ec1-a621-f60087554c2f" TYPE="swap"
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mount -av
/ : ignored
/boot : already mounted
/home : already mounted
none : ignored
/lv1 : already mounted
/lv2 : already mounted
/lv3 : already mounted
swap : ignored
[root@localhost ~]# swapon -a
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/nvme0n1p5 partition 4194300 0 -2
/dev/dm-3 partition 720892 0 -3
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem: 1748 994 181 20 573 581
Swap: 4799 0 4799
[root@localhost ~]#