Linux Storage Concepts
Table of Contents
units of measurement in storage#
When referring to storage capacities, there are two units of measurements:
- the multiples of 1024, where capacities are written using the IEC notation:
- 1 kiB = 1 K, one kibibyte
- 1 MiB = 1 M, one mebibyte
- 1 GiB = 1 G, one gibibyte
- 1 TiB = 1 T, one tebibyte
- etc.
- the multiples of 1000, which is also used in IT networking for communication speed, throughput or bandwidth. In this case, capacity values are written using this notation:
- 1 kB: one kilobyte
- 1 MB: one megabyte
- 1 GB: one gigabyte
- 1 TB: one terabyte
- etc.
Commands that use units of 1024 bytes: fdisk, lsblk, sfdisk, etc.
Commands that use units of 1000 bytes: parted, etc.
Example 1: I create a partition with a size of 120 MB ( the 1000s notation) using parted. lsblk will display the start, end and capacity values in the 1024s notation.
user1@rhel10-vm2:~$ sudo parted /dev/sdc print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdc: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
user1@rhel10-vm2:~$ sudo parted /dev/sdc mkpart ext4 1m 121m
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ sudo parted /dev/sdc print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdc: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 121MB 120MB ext4
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ lsblk /dev/sdc
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdc 8:32 0 409.6M 0 disk
└─sdc1 8:33 0 114M 0 part
user1@rhel10-vm2:~$
Example 2: I create a partition with a size of 120 MiB (units of 1024) using parted. The print option of parted will convert the start, end and capacity values to the 1000s notation.
user1@rhel10-vm2:~$ sudo parted /dev/sdc rm 1
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ sudo parted /dev/sdc mkpart ext4 1MiB 121MiB
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ sudo parted /dev/sdc print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdc: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 127MB 126MB ext4
user1@rhel10-vm2:~$ lsblk /dev/sdc
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdc 8:32 0 409.6M 0 disk
└─sdc1 8:33 0 120M 0 part
user1@rhel10-vm2:~$
I am able to convert storage sizes between the two unit systems by breaking the size down to the bytes then dividing by 1000 or 1024, depending on the unit system. In the second example above, using parted mkpart command, I created a 120 MiB partition. 120 MiB is exactly what is displayed in the output of lsblk /dev/sdc. 120 MiB is also 120 * 1024 * 1024 = 125.829.120 bytes. When converted to the units of 1000, it becomes 125.829.120 /1000/1000 = 125,829, or roughly 126 MB, which is the size I’ve got displayed with the parted /dev/sdc print command.
block device vs character device#
A block device is a device that supports I/O operations in block sizes. A character device is also a device that supports I/O operations, but one character at a time. Storage devices like HDD, SSD and USB removable media are block devices, thus are represented by block device nodes.
block device node#
A block device node is a file under /dev that presents a physical storage device (HDD, SSD, CDROM, DVDROM, usb stick, etc.) to the kernel device drivers.
When a storage device is partitioned, the corresponding block device node name reflects the partition number within that storage device. Example: /dev/sdc2 is the second partition in the disk represented by sdc.
The block device node name typically indicates the type and index of the hardware device it represents. For example, /dev/hda and /dev/hdb are the first and second hard disk drives respectively when both are older HDD technology.
virtual block device#
A virtual block device is a file under the /dev directory that presents a storage device to the Linux kernel device driver, but the device is not backed by real hardware.
Both block device nodes and virtual block devices constitute interfaces between hardware and the Linux kernel device driver. The latter does not need to access the hardware device directly, but rather the corresponding device file in the /dev/ directory.
disks#
A disk is a raw storage device that needs these things to be operational: labeling, partitioning, filesystem formatting and a special section that contains a bootloader. A disk is said to be labeled when a partition table is written on it, typically MBR or GPT. A disk that holds an MBR label is called an MBR disk (aka dos or msdos disk). A disk that holds a GPT label is called a GPT disk. Labeling a disk must inevitably occur before it is partitioned.
disk partitions#
A partition is a logical portion of a hard disk. It defines a single logical drive.
the lsblk command#
The most straightforward command to find out the local storage block devices, whether complete disks, partitions or removable media, is lsblk.
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$
A useful option of lsblk is -f. I used it in my post on Linux filesystems and swap.
vda stands for “virtual disk a”. The digit indicates the partition number.
Any newly-attached local disk will be displayed has having the devtmpfs filesystem on it. And this happens regardless of whether or not the disk has been initialized with a partition table:
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
sdb 8:16 0 409.6M 0 disk
sdc 8:32 0 409.6M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ lsblk -f /dev/sda
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
user1@rhel10-vm2:~$ sudo parted /dev/sda mklabel gpt
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ df /dev/sda
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 4096 0 4096 0% /dev
user1@rhel10-vm2:~$ df /dev/sdb
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 4096 0 4096 0% /dev
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ df /dev/sdc
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 4096 0 4096 0% /dev
user1@rhel10-vm2:~$
It seems that devtmpfs is a lightweight filesystem that is managed by the kernel and whose role is to create the virtual device files under /dev/ as soon as new devices are detected.
the sfdisk command#
Before learning this command, the way I did to find remaining storage capcity on a block device was by visually substracting the sizes of partitions from the size of their disk device. It was a risky method because it does not take into consideration the storage capacity occupied by metadata and not displayed in lsblk. That was until I discovered sfdisk --list-free. sfdisk parses partition tables to give exact numbers.
user1@rhel10-vm2:~$ sfdisk --list-free
sfdisk: cannot open /dev/vda: Permission denied
sfdisk: cannot open /dev/sda: Permission denied
sfdisk: cannot open /dev/sdc: Permission denied
sfdisk: cannot open /dev/sdb: Permission denied
sfdisk: cannot open /dev/sr0: Permission denied
sfdisk: cannot open /dev/mapper/rhel-root: Permission denied
sfdisk: cannot open /dev/mapper/rhel-swap: Permission denied
sfdisk: cannot open /dev/mapper/vgfs-ext4vol: Permission denied
sfdisk: cannot open /dev/mapper/vgfs-xfsvol: Permission denied
sfdisk: cannot open /dev/mapper/vgfs-swapvol: Permission denied
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo sfdisk --list-free
[sudo] password for user1:
Unpartitioned space /dev/vda: 0 B, 0 bytes, 0 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Unpartitioned space /dev/sdc: 2 MiB, 2097152 bytes, 4096 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Start End Sectors Size
235520 237567 2048 1M
724992 727039 2048 1M
Unpartitioned space /dev/sdb: 11.6 MiB, 12164096 bytes, 23758 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Start End Sectors Size
815104 838861 23758 11.6M
user1@rhel10-vm2:~$
The output above indicates that:
- there is no storage capacity left on /dev/vda,
- only 2 MiB of unallocated storage capacity are left on /dev/sdc,
- only 11 MiB of unallocated storage capacity are left on /dev/sdb.
It seemed that the tool skipped /dev/sda altogether. I deleted all extra disks and re-attached them again. I observed that sfdisk skipped disks that were not initialized with a partition table. Example: /dev/sda has been initialized with a partition table but /dev/sdb was not:
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
sdb 8:16 0 409.6M 0 disk
<---- output omitted ---->
user1@rhel10-vm2:~$ sudo parted /dev/sda mklabel gpt
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ sudo sfdisk --list-free /dev/sda
Unpartitioned space /dev/sda: 408.58 MiB, 428431872 bytes, 836781 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Start End Sectors Size
2048 838828 836781 408.6M
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sda mklabel msdos
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Error: /dev/sdb: unrecognised disk label
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
user1@rhel10-vm2:~$ sudo parted /dev/sda print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo sfdisk --list-free /dev/sda
Unpartitioned space /dev/sda: 408.6 MiB, 428448768 bytes, 836814 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Start End Sectors Size
2048 838861 836814 408.6M
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo sfdisk --list-free /dev/sdb
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$
BIOS vs UEFI#
Both BISO and UEFI constitute an interface between the Operating System and the firmware of the hardware platform. They are pieces of software that is embedded on some chip or controller on the hardware, i.e. the motherboard of a server. Both BIOS and UEFI look for instructions on the disks that help locate the respective bootloader. BIOS Looks for the MBR (Master Boot Record) in the first sector of the disk. UEFI looks for the .efi files that are located in the EFI Special Partition (ESP) under /boot/efi/EFI/. Once the bootloader is located, the interface (BIOS or UEFI) loads it in memory and give it control for the rest of the OS boot operations.
The EFI Special Partition (ESP) is mount at the /boot/efi/ mount point:
Wassim@linux:~$ ls -la /boot/efi/EFI
ls: cannot access '/boot/efi/EFI': Permission denied
Wassim@linux:~$
Wassim@linux:~$ sudo ls -la /boot/efi/EFI/
total 16
drwx------. 4 root root 4096 Mar 15 01:00 .
drwx------. 3 root root 4096 Jan 1 1970 ..
drwx------. 2 root root 4096 Jun 21 12:42 BOOT
drwx------. 2 root root 4096 Jun 21 12:42 rocky
Wassim@linux:~$
Under the /boot/efi/ mount point, I have a directory called rocky. It makes sense because Rocky Linux is the unique OS I have on this machine. In that directory, I found the .efi bootloader files:
Wassim@linux:~$ sudo ls -l /boot/efi/EFI/rocky
total 7988
-rwx------. 1 root root 104 May 23 02:00 BOOTX64.CSV
-rwx------. 1 root root 159 Oct 2 2025 grub.cfg
-rwx------. 1 root root 4200776 May 23 02:00 grubx64.efi
-rwx------. 1 root root 874808 May 23 02:00 mmx64.efi
-rwx------. 1 root root 1036024 May 23 02:00 shim.efi
-rwx------. 1 root root 1036024 May 23 02:00 shimx64.efi
-rwx------. 1 root root 1019168 May 23 02:00 shimx64-rocky.efi
Wassim@linux:~$
Although BIOS requires MBR and UEFI requires GPT, UEFI creates a section of the disk called ==protective MBR== in the LBA 0 for retrocompatibility with BIOS systems; The protective MBR is configured is a way, that when a BIOS system detects the protective MBR, it concludes that the rest of the disk space has already been allocated. LBA stands for Logical Bloc Address and is the memory addressing scheme used by UEFI.
BIOS and EUFI are properties of the hardware platform. A hardware platform can support either BIOS, UEFI or both.
Both BIOS and UEFI offer a central configuration interface that is typically accessible by pressing F2 during system boot. The configuration interface of UEFI typically looks modern whe compared with that of BIOS.
My hardware platform seem to support UEFI and the bootloader file (shimx64.efi) is under the /rocky/ directory, which is the only OS installed:
Wassim@linux:~$ sudo efibootmgr -v
[sudo] password for Wassim:
BootCurrent: 0001
Timeout: 1 seconds
BootOrder: 0001,0002
Boot0001* rocky HD(1,GPT,b8cee562-e729-421c-b068-eff40ef3edc2,0x800,0x12c000)/\EFI\rocky\shimx64.efi
dp: 04 01 2a 00 01 00 00 00 00 08 00 00 00 00 00 00 00 c0 12 00 00 00 00 00 62 e5 ce b8 29 e7 1c 42 b0 68 ef f4 0e f3 ed c2 02 02 / 04 04 32 00 5c 00 45 00 46 00 49 00 5c 00 72 00 6f 00 63 00 6b 00 79 00 5c 00 73 00 68 00 69 00 6d 00 78 00 36 00 34 00 2e 00 65 00 66 00 69 00 00 00 / 7f ff 04 00
Boot0002* UEFI OS HD(1,GPT,b8cee562-e729-421c-b068-eff40ef3edc2,0x800,0x12c000)/\EFI\BOOT\BOOTX64.EFI0000424f
dp: 04 01 2a 00 01 00 00 00 00 08 00 00 00 00 00 00 00 c0 12 00 00 00 00 00 62 e5 ce b8 29 e7 1c 42 b0 68 ef f4 0e f3 ed c2 02 02 / 04 04 30 00 5c 00 45 00 46 00 49 00 5c 00 42 00 4f 00 4f 00 54 00 5c 00 42 00 4f 00 4f 00 54 00 58 00 36 00 34 00 2e 00 45 00 46 00 49 00 00 00 / 7f ff 04 00
data: 00 00 42 4f
Wassim@linux:~$
UUID#
When a storage device is labeled, it receives a Universally Unique Identifier (UUID). UUID is a permanent attribute of a disk, a partition and even a filesystem that remains consistent even after system reboot.
Here is how to find out the UUID of a filesystem.
partition tables#
A partition table contains entries about partitions. Each partition table entry contains information like the start and end points of a partition on the hard disk, the type and state of the partition. There are two types of partition tables that are supported on most hardware platfomrs: MBR (for BIOS systems) and GPT (for UEFI systems).
Master Boot Record: MBR#
MBR is the firmware interface that is located on the first sector of the disk. It is also the partion table format used by BIOS systems. MBR is also called dos.
Partitions in BIOS systems#
When a system uses MBR disks, there are concepts of primary, extended and logical partition. Both a primary and a logical partition hold data. The extended partition is merely a container of logical partitions. On a Linux MBR-based system, there can up to four primary partitions or three primary partitions and one extended partition that holds the logical partitions.
interacting with local physical storage using fdisk#
This section describes the use of fdisk to CRUD partitions on MBR disks. (CRUD stands for Create, Read, Update, Delete).
create partition tables#
create a MBR (dos) partition table#
user1@rhel10-vm2:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
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
e resize 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
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 MBR (DOS) partition table
s create a new empty Sun partition table
Command (m for help): o
Created a new DOS (MBR) disklabel with disk identifier 0x63fba509.
The device contains 'gpt' signature and it will be removed by a write command. See fdisk(8) man page and --wipe option for more details.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
user1@rhel10-vm2:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 409.6 MiB, 429497344 bytes, 838862 sectors
Disk model: QEMU HARDDISK
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: 0x63fba509
Command (m for help): q
user1@rhel10-vm2:~$
create a GPT partition table#
user1@rhel10-vm2:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): g
Created a new GPT disklabel (GUID: C909717D-5AB8-4420-B919-47A79B7B8DC9).
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
user1@rhel10-vm2:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 409.6 MiB, 429497344 bytes, 838862 sectors
Disk model: QEMU HARDDISK
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: C909717D-5AB8-4420-B919-47A79B7B8DC9
Command (m for help): q
user1@rhel10-vm2:~$
listing disks and partitions#
List all partitions with fdisk -l. Notice the UUID value created for the /dev/vda disk:
user1@rhel10-vm2:~$ sudo fdisk -l
[sudo] password for user1:
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 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: gpt
Disk identifier: 15DBF6BF-18B3-4524-8FFB-394998182EBA
Device Start End Sectors Size Type
/dev/vda1 2048 4095 2048 1M BIOS boot
/dev/vda2 4096 2101247 2097152 1G Linux extended boot
/dev/vda3 2101248 52426751 50325504 24G Linux LVM
Disk /dev/mapper/rhel-root: 21.95 GiB, 23571988480 bytes, 46039040 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/rhel-swap: 2.04 GiB, 2193620992 bytes, 4284416 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
user1@rhel10-vm2:~$
#QA Why are /dev/mapper/rhel-root and /dev/mapper/rhel-swap are listed as disks and not partitions?
I manually added a disk to the RHEL VM:
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 399.4M 0 disk
sdb 8:16 0 399.4M 0 disk
sdc 8:32 0 399.4M 0 disk
sdd 8:48 0 409.6M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$
I list the physical disks and the partitions:
user1@rhel10-vm2:~$ sudo fdisk -l
[sudo] password for user1:
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 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: gpt
Disk identifier: 15DBF6BF-18B3-4524-8FFB-394998182EBA
Device Start End Sectors Size Type
/dev/vda1 2048 4095 2048 1M BIOS boot
/dev/vda2 4096 2101247 2097152 1G Linux extended boot
/dev/vda3 2101248 52426751 50325504 24G Linux LVM
Disk /dev/sdb: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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/sdc: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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/sda: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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/sdd: 409.6 MiB, 429497344 bytes, 838862 sectors
Disk model: QEMU HARDDISK
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: 0x113ba544
Disk /dev/mapper/rhel-root: 21.95 GiB, 23571988480 bytes, 46039040 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/rhel-swap: 2.04 GiB, 2193620992 bytes, 4284416 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
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$
The sda disk represented by /dev/sda. Note that /dev/vda shows Disklabel type: gpt while the other disks show no mention of any disk label.
creating partitions with fdisk#
I create a new partition on /dev/sda:
user1@rhel10-vm2:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
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 (MBR) disklabel with disk identifier 0xef2f6a52.
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): 1
First sector (2048-817889, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-817889, default 817889): 200
Value out of range.
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-817889, default 817889): +200
Created a new partition 1 of type 'Linux' and of size 100.5 KiB.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):
fdisk reasons in terms of sectors, not bytes, when creating partitions. Each sector is 512 bytes in size, according to the output of fdisk. So a simple mathematical formula gives the number of sectors for a desired partition size. Example: for a desired partition size of 150 MiB, I would need (150 * 1024 * 1024) / 512 = 307200 sectors. And since creating a partition with fdisk does not start with sector 0, I would then need to add 307200 sectors to whatever start sector value I’m presented with:
Command (m for help): p
Disk /dev/sdb: 409.6 MiB, 429497344 bytes, 838862 sectors
Disk model: QEMU HARDDISK
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: 0x2cb1bb74
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): 1
First sector (2048-838861, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-838861, default 838861): +307200
Created a new partition 1 of type 'Linux' and of size 150 MiB.
Command (m for help):
From the output it seems that up to only four primary partitions can be created, which is a typical behavior of BIOS systems. I write the changes to the partition table with w:
Select (default p):
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
user1@rhel10-vm2:~$
Here is the new layout for the disks and partitions:
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 399.4M 0 disk
└─sda1 8:1 0 100.5K 0 part
sdb 8:16 0 399.4M 0 disk
sdc 8:32 0 399.4M 0 disk
sdd 8:48 0 409.6M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo fdisk -l
[sudo] password for user1:
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 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: gpt
Disk identifier: 15DBF6BF-18B3-4524-8FFB-394998182EBA
Device Start End Sectors Size Type
/dev/vda1 2048 4095 2048 1M BIOS boot
/dev/vda2 4096 2101247 2097152 1G Linux extended boot
/dev/vda3 2101248 52426751 50325504 24G Linux LVM
<---- output omitted ---->
Disk /dev/sda: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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: 0xef2f6a52
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 2248 201 100.5K 83 Linux
<---- output omitted ---->
user1@rhel10-vm2:~$
I list the disk and partition information for a specific disk by printing the partition table entry with fdisk then the print option. Note that I must specify the device file as an argument, not the disk name:
user1@rhel10-vm2:~$ sudo fdisk sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
fdisk: cannot open sda: No such file or directory
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): print
Disk /dev/sda: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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: 0xef2f6a52
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 2248 201 100.5K 83 Linux
Command (m for help):
Also note that the output of fdisk -l /dev/sda is identical to that of fdisk /dev/sda then print.
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sda
Disk /dev/sda: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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: 0xef2f6a52
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 2248 201 100.5K 83 Linux
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): print
Disk /dev/sda: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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: 0xef2f6a52
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 2248 201 100.5K 83 Linux
Command (m for help):
resizing a partition with fdisk#
I created a single partition of size 149 MiB on a dos disk. I want to change it to 150 MiB. I can do that from within the fdisk menu using the e key (for extend) then save the changes to the partition table with w:
Command (m for help): e
Selected partition 1
New <size>{K,M,G,T,P} in bytes or <size>S in sectors (default 408.6M): 150M
Partition 1 has been resized.
Command (m for help): p
Disk /dev/sdb: 409.6 MiB, 429497344 bytes, 838862 sectors
Disk model: QEMU HARDDISK
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: 0x2cb1bb74
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 309247 307200 150M 83 Linux
Command (m for help):
partition types vs partition tables#
Once a disk has been initialized with a specific partition table, like msdos or gpt, any partition that is created on the disk will be assigned a hex code, commonly known as the partition type. This is not to be confused with the partition table.
The partition type is a method for an OS to quicly identify a partition and decide whether to read its filesystem or not. This becomes interesting when more than one OS resides on a machine with partitioned disks.
A confusing situation might arise when the output of fdisk shows msdos as the partition table and the first partition has GPT as partition type:
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sdc
Disk /dev/sdc: 409.6 MiB, 429497344 bytes, 838862 sectors
Disk model: QEMU HARDDISK
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: 0x7896feae
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 235519 233472 114M ee GPT
/dev/sdc2 237568 243711 6144 3M 83 Linux
user1@rhel10-vm2:~$
The hex code for a partition type is a section of the partition table data. I can assume that partition types of all partitions of a disk are stored in some area of the partition table.
The partition type is also not to be confused with the filesystem that resides on the partition.
The default partition type that I observed in the lab was Linux with hex code of 0x83. I can change it in the fdisk menu:
user1@rhel10-vm2:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): print
Disk /dev/sda: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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: 0xef2f6a52
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 2248 201 100.5K 83 Linux
Command (m for help): type
Selected partition 1
Hex code or alias (type L to list all): L
00 Empty 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
01 FAT12 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
02 XENIX root 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
03 XENIX usr 40 Venix 80286 85 Linux extended c7 Syrinx
04 FAT16 <32M 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
05 Extended 42 SFS 87 NTFS volume set db CP/M / CTOS / .
06 FAT16 4d QNX4.x 88 Linux plaintext de Dell Utility
07 HPFS/NTFS/exFAT 4e QNX4.x 2nd part 8e Linux LVM df BootIt
08 AIX 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
09 AIX bootable 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
0a OS/2 Boot Manag 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
0b W95 FAT32 52 CP/M a0 IBM Thinkpad hi ea Linux extended
0c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
0e W95 FAT16 (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
0f W95 Ext'd (LBA) 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a9 NetBSD f1 SpeedStor
12 Compaq diagnost 61 SpeedStor ab Darwin boot f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
16 Hidden FAT16 64 Novell Netware b7 BSDI fs f8 EBBR protective
17 Hidden HPFS/NTF 65 Novell Netware b8 BSDI swap fb VMware VMFS
18 AST SmartSleep 70 DiskSecure Mult bb Boot Wizard hid fc VMware VMKCORE
1b Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fd Linux raid auto
1c Hidden W95 FAT3 80 Old Minix be Solaris boot fe LANstep
1e Hidden W95 FAT1 81 Minix / old Lin bf Solaris ff BBT
24 NEC DOS
Aliases:
linux - 83
swap - 82
extended - 05
uefi - EF
raid - FD
lvm - 8E
linuxex - 85
Hex code or alias (type L to list all): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sda
Disk /dev/sda: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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: 0xef2f6a52
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 2248 201 100.5K 8e Linux LVM
user1@rhel10-vm2:~$
Note that:
- the
typeandtoptions are equivalent, - the
landLoptions are equivalent.
user1@rhel10-vm2:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.40.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): t
Selected partition 1
Hex code or alias (type L to list all): l
00 Empty 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
01 FAT12 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
02 XENIX root 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
03 XENIX usr 40 Venix 80286 85 Linux extended c7 Syrinx
04 FAT16 <32M 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
05 Extended 42 SFS 87 NTFS volume set db CP/M / CTOS / .
06 FAT16 4d QNX4.x 88 Linux plaintext de Dell Utility
07 HPFS/NTFS/exFAT 4e QNX4.x 2nd part 8e Linux LVM df BootIt
08 AIX 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
09 AIX bootable 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
0a OS/2 Boot Manag 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
0b W95 FAT32 52 CP/M a0 IBM Thinkpad hi ea Linux extended
0c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
0e W95 FAT16 (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
0f W95 Ext'd (LBA) 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a9 NetBSD f1 SpeedStor
12 Compaq diagnost 61 SpeedStor ab Darwin boot f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
16 Hidden FAT16 64 Novell Netware b7 BSDI fs f8 EBBR protective
17 Hidden HPFS/NTF 65 Novell Netware b8 BSDI swap fb VMware VMFS
18 AST SmartSleep 70 DiskSecure Mult bb Boot Wizard hid fc VMware VMKCORE
1b Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fd Linux raid auto
1c Hidden W95 FAT3 80 Old Minix be Solaris boot fe LANstep
1e Hidden W95 FAT1 81 Minix / old Lin bf Solaris ff BBT
24 NEC DOS
Aliases:
linux - 83
swap - 82
extended - 05
uefi - EF
raid - FD
lvm - 8E
linuxex - 85
Hex code or alias (type L to list all): L
00 Empty 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
01 FAT12 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
02 XENIX root 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
03 XENIX usr 40 Venix 80286 85 Linux extended c7 Syrinx
04 FAT16 <32M 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
05 Extended 42 SFS 87 NTFS volume set db CP/M / CTOS / .
06 FAT16 4d QNX4.x 88 Linux plaintext de Dell Utility
07 HPFS/NTFS/exFAT 4e QNX4.x 2nd part 8e Linux LVM df BootIt
08 AIX 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
09 AIX bootable 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
0a OS/2 Boot Manag 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
0b W95 FAT32 52 CP/M a0 IBM Thinkpad hi ea Linux extended
0c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
0e W95 FAT16 (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
0f W95 Ext'd (LBA) 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a9 NetBSD f1 SpeedStor
12 Compaq diagnost 61 SpeedStor ab Darwin boot f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
16 Hidden FAT16 64 Novell Netware b7 BSDI fs f8 EBBR protective
17 Hidden HPFS/NTF 65 Novell Netware b8 BSDI swap fb VMware VMFS
18 AST SmartSleep 70 DiskSecure Mult bb Boot Wizard hid fc VMware VMKCORE
1b Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fd Linux raid auto
1c Hidden W95 FAT3 80 Old Minix be Solaris boot fe LANstep
1e Hidden W95 FAT1 81 Minix / old Lin bf Solaris ff BBT
24 NEC DOS
Aliases:
linux - 83
swap - 82
extended - 05
uefi - EF
raid - FD
lvm - 8E
linuxex - 85
Hex code or alias (type L to list all):
deleting a partition using fdisk#
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sda
[sudo] password for user1:
Disk /dev/sda: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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: 0xef2f6a52
user1@rhel10-vm2:~$
On one occasion, I did not understand the error message: #QA
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
[sudo] password for user1:
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 158MB 157MB primary ext4
2 158MB 316MB 157MB primary fat16
3 317MB 417MB 101MB primary
user1@rhel10-vm2:~$ df -h /dev/sdb3
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sdb rm 3
Error: Partition(s) 3 on /dev/sdb have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will
remain in use. You should reboot now before making further changes.
Ignore/Cancel?
interacting with local physical storage using parted#
user1@rhel10-vm2:~$ parted /dev/sdb print
WARNING: You are not superuser. Watch out for permissions.
Error: Error opening /dev/sda: Permission denied
Retry/Cancel? C
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sdb: 419MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
user1@rhel10-vm2:~$
When a disk has no label, it shows in the output of parted print command. The following output shows that /dev/sda has a label; The partition table is msdos or MBR. The /dev/sdb disk however has no label. This explains the error message in the first line after parted /dev/sdb print:
user1@rhel10-vm2:~$ sudo parted /dev/sda print
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sda: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Error: /dev/sdb: unrecognised disk label
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sdb: 419MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
user1@rhel10-vm2:~$
The error message is not always a result of a missing label; In case of a disk that has been initialized for a LVM physical volume, neither fdisk nor parted recognize the label:
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Error: /dev/sdb: unrecognised disk label
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sdb: 419MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvs /dev/sdb
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 399.36m 399.36m
user1@rhel10-vm2:~$
As opposed to fdisk, which automatically creates a partition table when it does not detect one on a disk, parted requires manual intervention using the mklabel argument. Also, fdisk seem to support only the MBR (dos) partition table while parted supports both MBR and GPT.
fdisk saves changes in memory and requires a write confirmation before quitting the configuration menu, with w, while parted seem to apply changes immediately.
user1@rhel10-vm2:~$ sudo parted /dev/sda print
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sda: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
user1@rhel10-vm2:~$ sudo parted /dev/sdb mklabel msdos
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sdb: 419MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sdb | grep label
Disklabel type: dos
user1@rhel10-vm2:~$
What if I changed my mind and wanted a GPT disk instead? It seems possible to rewrite the partition table with parted:
user1@rhel10-vm2:~$ sudo parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Y
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sdb: 419MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
user1@rhel10-vm2:~$
creating partitions with parted#
I created a partition on the sdb disk with a size of 100 MiB, starting at the first Mebibyte of the disk:
user1@rhel10-vm2:~$ sudo parted /dev/sdb mkpart primary 1 101m
[sudo] password for user1:
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 0 399.4M 0 disk
└─sdb1 8:17 0 95M 0 part
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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: 0x087bebe6
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 196607 194560 95M 83 Linux
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sdb: 419MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 101MB 99.6MB primary
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ cat /proc/partitions
major minor #blocks name
252 0 26214400 vda
252 1 1024 vda1
252 2 1048576 vda2
252 3 25162752 vda3
8 0 408945 sda
8 16 408945 sdb
8 17 97280 sdb1
8 32 419431 sdc
8 48 408945 sdd
11 0 9925440 sr0
253 0 23019520 dm-0
253 1 2142208 dm-1
user1@rhel10-vm2:~$
#QA Why is there a difference in sizes for the same partition with both commands?
What if I relabel the disk after I created a partition on it: This will erase the partition and all data on the disk:
user1@rhel10-vm2:~$ sudo parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will
be lost. Do you want to continue?
Yes/No?
Yes/No? Y
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sdb: 419MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
user1@rhel10-vm2:~$ lsblk | grep sdb
sdb 8:16 0 399.4M 0 disk
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ grep sdb /proc/partitions
8 16 408945 sdb
user1@rhel10-vm2:~$
parted is intelligent enough to detect whether the creation of a new partition overlaps with an existing one and prevents incidentally overwriting it. And the existing partition was not necessarily created with parted. In my example, the existing partition was sda1, which is a physical volume participating to the virtual group vg03 and is being used to provide storage for the myLV2 logical volume.
Scenario 1: I Accept the proposition of parted:
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
└─sda1 8:1 0 20M 0 part
└─vg03-myLV2 253:4 0 6M 0 lvm
sdb 8:16 0 399.4M 0 disk
sdc 8:32 0 399.4M 0 disk
├─vg03-myLV1 253:2 0 30M 0 lvm
└─vg03-lvol0 253:3 0 50M 0 lvm
sdd 8:48 0 399.4M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$ sudo parted /dev/sda mkpart primary 5 105m
Warning: You requested a partition from 5000kB to 105MB (sectors 9765..205078).
The closest location we can manage is 24.1MB to 105MB (sectors 47104..205078).
Is this still acceptable to you?
Yes/No?
Scenario 2: I do not accept the proposition of parted: Nothing is created or destructed:
user1@rhel10-vm2:~$ sudo parted /dev/sda mkpart primary 5 105m
Warning: You requested a partition from 5000kB to 105MB (sectors 9765..205078).
The closest location we can manage is 24.1MB to 105MB (sectors 47104..205078).
Is this still acceptable to you?
Yes/No? No
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
└─sda1 8:1 0 20M 0 part
└─vg03-myLV2 253:4 0 6M 0 lvm
sdb 8:16 0 399.4M 0 disk
sdc 8:32 0 399.4M 0 disk
├─vg03-myLV1 253:2 0 30M 0 lvm
└─vg03-lvol0 253:3 0 50M 0 lvm
sdd 8:48 0 399.4M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$
creating additional partitions with parted#
Sometimes, a disk is partitioned with a single partition that takes the whole capacity:
user1@rhel10-vm2:~$ lsblk /dev/sdc
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdc 8:32 0 409.6M 0 disk
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sdc print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdc: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system Flags
1 0.00B 429MB 429MB xfs
user1@rhel10-vm2:~$
In such scenarios, it is not possible to add partitions:
user1@rhel10-vm2:~$ sudo parted /dev/sdc mkpart ext4 1 120
Error: Too many primary partitions.
user1@rhel10-vm2:~$
A solution is to wipe the disk and create smaller partitions. Example:
user1@rhel10-vm2:~$ sudo parted /dev/sdc mklabel gpt
[sudo] password for user1:
Warning: The existing disk label on /dev/sdc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ lsblk /dev/sdc
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdc 8:32 0 409.6M 0 disk
user1@rhel10-vm2:~$ sudo parted /dev/sdc print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdc: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
user1@rhel10-vm2:~$ sudo parted /dev/sdc mkpart ext4 1 120
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ sudo parted /dev/sdc print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdc: 429MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 120MB 118MB ext4
user1@rhel10-vm2:~$
deleting partitions with parted#
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sdb: 419MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 101MB 99.6MB primary
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sdb rm 1
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ sudo parted /dev/sdb print
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sdb: 419MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
user1@rhel10-vm2:~$
using mke2fs#
To create ext2, ext3 or ext4 partitions, use the mke2fs tool. I use the -c option to check for bad sectors before creating the filesystem:
user1@rhel10-vm2:~$ sudo mke2fs -c /dev/sdb1
[sudo] password for user1:
mke2fs 1.47.1 (20-May-2024)
Discarding device blocks: done
Creating filesystem with 153600 1k blocks and 38456 inodes
Filesystem UUID: 424efc19-01fb-4ff7-9ae7-8e3affb8b1b7
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Checking for bad blocks (read-only test): done
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
user1@rhel10-vm2:~$
The default values are stored in /etc/mke2fs.conf but I could not determine the default value for new filesystems only after I initialized a partition and looked its deployed filesystem:
user1@rhel10-vm2:~$ cat /etc/mke2fs.conf
[defaults]
base_features = sparse_super,large_file,filetype,resize_inode,dir_index,ext_attr
default_mntopts = acl,user_xattr
enable_periodic_fsck = 0
blocksize = 4096
inode_size = 256
inode_ratio = 16384
[fs_types]
ext3 = {
features = has_journal
}
ext4 = {
features = has_journal,extent,huge_file,flex_bg,metadata_csum,64bit,dir_nlink,extra_isize
}
small = {
blocksize = 1024
inode_ratio = 4096
}
floppy = {
blocksize = 1024
inode_ratio = 8192
}
big = {
inode_ratio = 32768
}
huge = {
inode_ratio = 65536
}
news = {
inode_ratio = 4096
}
largefile = {
inode_ratio = 1048576
blocksize = -1
}
largefile4 = {
inode_ratio = 4194304
blocksize = -1
}
hurd = {
blocksize = 4096
inode_size = 128
warn_y2038_dates = 0
}
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ lsblk -f /dev/sdb1
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sdb1 ext2 1.0 424efc19-01fb-4ff7-9ae7-8e3affb8b1b7
user1@rhel10-vm2:~$
So I made sure the next time that I specified the desired filesystem type as option to the command:
user1@rhel10-vm2:~$ mke2fs -t ext4 /dev/sdb1
mke2fs 1.47.1 (20-May-2024)
mke2fs: Permission denied while trying to determine filesystem size
user1@rhel10-vm2:~$ sudo mke2fs -t ext4 /dev/sdb1
mke2fs 1.47.1 (20-May-2024)
/dev/sdb1 contains a ext2 file system
created on Mon Sep 7 10:20:46 2026
Proceed anyway? (y,N) y
Discarding device blocks: done
Creating filesystem with 153600 1k blocks and 38456 inodes
Filesystem UUID: 72cdbb05-64a5-4a91-982f-c80b873a9536
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
user1@rhel10-vm2:~$ lsblk -f /dev/sdb1
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sdb1 ext4 1.0 72cdbb05-64a5-4a91-982f-c80b873a9536
user1@rhel10-vm2:~$
LVM#
Apart from fdisk and parted, a third way to manage disks is by using the Logical Volume Manager, LVM. In contrast to fdisk and parted, LVM is a storage virtualization software that creates an abstraction of the physical storage devices, using a similar philosophy to what a hypervisor software on a virtualization server does to the underlying hardware resources.
LVM does not create partitions. So prior work with fdisk or parted is required.
LVM unlocks the support of advanced disk management features like flexible capacity creation, RAID and snapshotting.
The LVM architecture is composed of three elements: one or more Physical Volumes -> (form) one Virtual Group -> (contains) Logical Volumes.
Deploying an LVM structure goes through these steps:
1- designate the disks and partitions; Partitions can be created with fdisk or parted
2- initialize the designated disks and partitions for LVM by converting them to physical volumes using pvcreate
3- create a virtual group and attach physical volumes to it
4- create logical volumes.
Deleting an LVM structure goes through these steps:
1- remove the logical volumes and/or the virtual group, because removing the virtual group automatically deletes its logical volumes
2- remove the LVM metadata from the physical volumes with pvremove.
A disk or a partition must be initialized with LVM, so that it becomes a Physical Volume. The initialization step creates a label for the physical volume and writes redundant LVM metadata, including a UUID, on the volume.
physical volumes#
A physical volume (PV) is the building block of the LVM architecture. It can be a single storage device or a single partition.
Use the pvs command to scan for the existing physical volumes:
user1@rhel10-vm2:~$ pvs
WARNING: Running as a non-root user. Functionality may be unavailable.
/run/lock/lvm/P_global:aux: open failed: Permission denied
user1@rhel10-vm2:~$ sudo pvs
[sudo] password for user1:
Sorry, try again.
r[sudo] password for user1:
PV VG Fmt Attr PSize PFree
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
Display a report of the physical volumes with pvdisplay:
user1@rhel10-vm2:~$ sudo pvdisplay
--- Physical volume ---
PV Name /dev/vda3
VG Name rhel
PV Size <24.00 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 6143
Free PE 0
Allocated PE 6143
PV UUID hzpR6U-8XIg-heCy-5Rca-Bmxx-ClO7-Cblxlg
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvdisplay /dev/vda3
--- Physical volume ---
PV Name /dev/vda3
VG Name rhel
PV Size <24.00 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 6143
Free PE 0
Allocated PE 6143
PV UUID hzpR6U-8XIg-heCy-5Rca-Bmxx-ClO7-Cblxlg
user1@rhel10-vm2:~$
create#
I am going to create a physical volume out of /dev/sdb:
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
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: 22DBFFA7-5AD6-407D-8E79-522906D74134
user1@rhel10-vm2:~$ sudo pvcreate /dev/sdb
[sudo] password for user1:
WARNING: gpt signature detected on /dev/sdb at offset 512. Wipe it? [y/n]: y
Wiping gpt signature on /dev/sdb.
WARNING: gpt signature detected on /dev/sdb at offset 418759168. Wipe it? [y/n]: y
Wiping gpt signature on /dev/sdb.
WARNING: PMBR signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y
Wiping PMBR signature on /dev/sdb.
Physical volume "/dev/sdb" successfully created.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 399.36 MiB, 418759680 bytes, 817890 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
user1@rhel10-vm2:~$
The new physical volume, /dev/sdb is created. Notice the UUID given to the physical volume when executing the pvdisplay command and that the volume is not allocatable yet:
user1@rhel10-vm2:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 399.36m 399.36m
/dev/sdc lvm2 --- 399.36m 399.36m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
WARNING: Running as a non-root user. Functionality may be unavailable.
/run/lock/lvm/P_global:aux: open failed: Permission denied
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvdisplay
--- Physical volume ---
PV Name /dev/vda3
VG Name rhel
PV Size <24.00 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 6143
Free PE 0
Allocated PE 6143
PV UUID hzpR6U-8XIg-heCy-5Rca-Bmxx-ClO7-Cblxlg
"/dev/sdb" is a new physical volume of "399.36 MiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 399.36 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID cUMNP8-2jUc-t6vn-ewuP-V0DR-e14Y-XDaNOc
"/dev/sdc" is a new physical volume of "399.36 MiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 399.36 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ZAfQ08-iWMP-5pGg-fcmV-Aesx-T1je-L5XEMH
user1@rhel10-vm2:~$
When a whole disk is converted to a physical volume, no partitioning can take place on it anymore unless the LVM metadata is overwritten by another partition table.
user1@rhel10-vm2:~$ lsblk /dev/sda
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
├─vgfs-ext4vol 253:2 0 96M 0 lvm /ext4fs2
└─vgfs-xfsvol 253:3 0 360M 0 lvm /xfsfs2
user1@rhel10-vm2:~$ sudo pvs /dev/sda
PV VG Fmt Attr PSize PFree
/dev/sda vgfs lvm2 a-- 408.00m 0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo parted /dev/sda mkpart primary ext4
Error: /dev/sda: unrecognised disk label
user1@rhel10-vm2:~$
I noticed that lsblk -f displays LVM2_member in the FSTYPE column where a partition is a physical volume. In the example, the following are marked with LVM2_member:
- /dev/sda2, the second partition in the /dev/sda block device,
- /dev/sdb, the whole second disk,
- /dev/sdc3, the third partition in the /dev/sdc block device,
- /dev/vda3, the third partition in the /dev/vda block device.
user1@rhel10-vm2:~$ lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 swap 1 59e98274-b212-4fa2-b6c4-8e10726302ec [SWAP]
└─sda2 LVM2_member LVM2 001 iv5SDH-Oiyn-uSdh-6BUW-ETvx-F1JP-BWvCeP
└─vgfs-swapvol swap 1 13b32685-320b-4c45-9809-c929f8825b05 [SWAP]
sdb LVM2_member LVM2 001 jVGmEt-OfuX-siS4-cufB-ceN6-QNHO-KeycBX
├─vgfs-ext4vol ext4 1.0 5377d2bc-f963-4db5-b0dc-679481b8da82 78.2M 0% /ext4fs2
└─vgfs-xfsvol xfs 4f91a6a3-9dc1-480c-9467-379666ef7566 272M 8% /xfsfs2
sdc
├─sdc1 ext4 1.0 72cdbb05-64a5-4a91-982f-c80b873a9536
├─sdc2 vfat FAT16 454C-606D
└─sdc3 LVM2_member LVM2 001 OMg5Lu-N6qU-HfQF-iK5U-RPNe-Skbt-xen5JX
├─vgfs-ext4vol ext4 1.0 5377d2bc-f963-4db5-b0dc-679481b8da82 78.2M 0% /ext4fs2
├─vgfs-xfsvol xfs 4f91a6a3-9dc1-480c-9467-379666ef7566 272M 8% /xfsfs2
└─vgfs-swapvol swap 1 13b32685-320b-4c45-9809-c929f8825b05 [SWAP]
sr0 iso9660 Joliet Extension RHEL-10-1-BaseOS-x86_64 2025-10-21-06-14-30-00
vda
├─vda1
├─vda2 xfs mybootFS aeaf7891-fb70-4df0-90b6-bbd996703b8d 634.3M 34% /boot
└─vda3 LVM2_member LVM2 001 hzpR6U-8XIg-heCy-5Rca-Bmxx-ClO7-Cblxlg
├─rhel-root xfs 1cc2a0e5-8ea2-4b31-bbe7-a6d47a824276 17.8G 19% /
└─rhel-swap swap 1 543756ba-806e-4129-bc0b-757fb1e4d832 [SWAP]
user1@rhel10-vm2:~$
When I do vgdisplay -v, the output confirms the physical volumes:
- the rhel default virtual group has only one physical volume, /dev/vda3,
user1@rhel10-vm2:~$ sudo vgdisplay -v rhel
--- Volume group ---
VG Name rhel
System ID
Format lvm2
<---- output omitted ---->
--- Physical volumes ---
PV Name /dev/vda3
PV UUID hzpR6U-8XIg-heCy-5Rca-Bmxx-ClO7-Cblxlg
PV Status allocatable
Total PE / Free PE 6143 / 0
user1@rhel10-vm2:~$
- the vgfs virtual group has three physical volumes, /dev/sdb, /dev/sdc3, /dev/sda2.
user1@rhel10-vm2:~$ sudo vgdisplay -v vgfs
--- Volume group ---
VG Name vgfs
System ID
Format lvm2
Metadata Areas 3
<---- output omitted ---->
--- Physical volumes ---
PV Name /dev/sdb
PV UUID jVGmEt-OfuX-siS4-cufB-ceN6-QNHO-KeycBX
PV Status allocatable
Total PE / Free PE 51 / 0
PV Name /dev/sdc3
PV UUID OMg5Lu-N6qU-HfQF-iK5U-RPNe-Skbt-xen5JX
PV Status allocatable
Total PE / Free PE 11 / 2
PV Name /dev/sda2
PV UUID iv5SDH-Oiyn-uSdh-6BUW-ETvx-F1JP-BWvCeP
PV Status allocatable
Total PE / Free PE 29 / 0
user1@rhel10-vm2:~$
remove#
Use pvremove to remove LVM metadata from a physical volume then verify the result with the pvs command:
user1@rhel10-vm2:~$ sudo pvs /dev/sdb
[sudo] password for user1:
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 399.36m 399.36m
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvremove /dev/sdb
Labels on physical volume "/dev/sdb" successfully wiped.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvs /dev/sdb
Failed to find physical volume "/dev/sdb".
user1@rhel10-vm2:~$
pvremove supports removing LVM metadata for more than one physical volume simultaneously:
user1@rhel10-vm2:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 399.36m 399.36m
/dev/sdd lvm2 --- 399.36m 399.36m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvremove /dev/sdb /dev/sdd
Labels on physical volume "/dev/sdb" successfully wiped.
Labels on physical volume "/dev/sdd" successfully wiped.
user1@rhel10-vm2:~$
Trying to remove a physical volume that belongs to a virtual group:
user1@rhel10-vm2:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb myLVMvg lvm2 a-- 396.00m 396.00m
/dev/sdd myLVMvg lvm2 a-- 396.00m 396.00m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
myLVMvg 2 0 0 wz--n- 792.00m 792.00m
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$ sudo pvremove /dev/sdb
PV /dev/sdb is used by VG myLVMvg so please use vgreduce first.
(If you are certain you need pvremove, then confirm by using --force twice.)
/dev/sdb: physical volume label not removed.
user1@rhel10-vm2:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb myLVMvg lvm2 a-- 396.00m 396.00m
/dev/sdd myLVMvg lvm2 a-- 396.00m 396.00m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
#LessonLearned Removing a physical volume is only possible when it does not belong to a virtual group already.
#Observation: in RHEL documentation related to storage devices, pvremove is typically followed by wipefs -a which deletes all filesystems, partition tables and signatures on the disk or partition. Example:
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
├─sda1 8:1 0 20M 0 part
└─sda2 8:2 0 78.1M 0 part
sdb 8:16 0 399.4M 0 disk
sdc 8:32 0 399.4M 0 disk
sdd 8:48 0 399.4M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sda1
[sudo] password for user1:
Disk /dev/sda1: 20 MiB, 20971520 bytes, 40960 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
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo wipefs -a /dev/sda1
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo fdisk -l /dev/sda1
Disk /dev/sda1: 20 MiB, 20971520 bytes, 40960 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
user1@rhel10-vm2:~$
virtual groups#
A virtual group (VG) is composed of one or more physical volumes. It provides the storage pool from which logical volumes can be created.
scan and display#
Use the vgs command to scan the existing volume groups and vgdisplay to display a report.
user1@rhel10-vm2:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgs rhel
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgs -v rhel
VG Attr Ext #PV #LV #SN VSize VFree VG UUID VProfile
rhel wz--n- 4.00m 1 2 0 <24.00g 0 2QotKh-8w0L-I3Ns-I15u-nP0O-RigF-REpN5O
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ vgdisplay
WARNING: Running as a non-root user. Functionality may be unavailable.
/run/lock/lvm/P_global:aux: open failed: Permission denied
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgdisplay
[sudo] password for user1:
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <24.00 GiB
PE Size 4.00 MiB
Total PE 6143
Alloc PE / Size 6143 / <24.00 GiB
Free PE / Size 0 / 0
VG UUID 2QotKh-8w0L-I3Ns-I15u-nP0O-RigF-REpN5O
user1@rhel10-vm2:~$
The field Attr in the output of the vgs command indicates the attributes of the virtual group. Here is a summary of them according to the Linux man pages:
NOTES
The vg_attr bits are:
1 Permissions: (w)riteable, (r)ead-only
2 Resi(z)eable
3 E(x)ported
4 (p)artial: one or more physical volumes belonging to the volume group are missing
from the system
5 Allocation policy: (c)ontiguous, c(l)ing, (n)ormal, (a)nywhere
6 (c)lustered, (s)hared
user1@rhel10-vm2:~$ sudo vgdisplay -v rhel
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <24.00 GiB
PE Size 4.00 MiB
Total PE 6143
Alloc PE / Size 6143 / <24.00 GiB
Free PE / Size 0 / 0
VG UUID 2QotKh-8w0L-I3Ns-I15u-nP0O-RigF-REpN5O
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID RtaZ91-Wyfi-g3Qb-6H5V-RYsq-N5Ww-n6mAi1
LV Write Access read/write
LV Creation host, time rhel10-vm1, 2025-11-15 12:18:32 +0100
LV Status available
# open 1
LV Size 2.04 GiB
Current LE 523
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID RvCTV5-NeOx-CZAL-7ijh-FxyF-oj8n-amqJpY
LV Write Access read/write
LV Creation host, time rhel10-vm1, 2025-11-15 12:18:32 +0100
LV Status available
# open 1
LV Size 21.95 GiB
Current LE 5620
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/vda3
PV UUID hzpR6U-8XIg-heCy-5Rca-Bmxx-ClO7-Cblxlg
PV Status allocatable
Total PE / Free PE 6143 / 0
user1@rhel10-vm2:~$
create#
Create a virtual group based on two existing physical volumes with vgcreate. Note the VSize field. It indicates the size of the virtual group, which is the sum of the sizes of the underlying physical volumes.
user1@rhel10-vm2:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 399.36m 399.36m
/dev/sdc lvm2 --- 399.36m 399.36m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgcreate myLVMvg /dev/sdb /dev/sdc
Volume group "myLVMvg" successfully created
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
myLVMvg 2 0 0 wz--n- 792.00m 792.00m
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb myLVMvg lvm2 a-- 396.00m 396.00m
/dev/sdc myLVMvg lvm2 a-- 396.00m 396.00m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
I create a virtual group out of two physical volumes that belong to two non-adjacent storage devices, /dev/sda1 (partition 1 on disk a) and /dev/sdc. I am combining a partition with a complete disk to form the storage pool of a virtual group:
user1@rhel10-vm2:~$ sudo parted /dev/sda mkpart primary 3 24m
Information: You may need to update /etc/fstab.
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
└─sda1 8:1 0 20M 0 part
sdb 8:16 0 399.4M 0 disk
sdc 8:32 0 399.4M 0 disk
sdd 8:48 0 399.4M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvcreate -v /dev/sda1 /dev/sdc
Wiping signatures on new PV /dev/sda1.
Wiping signatures on new PV /dev/sdc.
Found existing signature on /dev/sdc at offset 512: LABEL="(null)" UUID="(null)" TYPE="gpt" USAGE="partition table"
WARNING: gpt signature detected on /dev/sdc at offset 512. Wipe it? [y/n]: y
Accepted input: [y]
Wiping gpt signature on /dev/sdc.
Found existing signature on /dev/sdc at offset 418759168: LABEL="(null)" UUID="(null)" TYPE="gpt" USAGE="partition table"
WARNING: gpt signature detected on /dev/sdc at offset 418759168. Wipe it? [y/n]: y
Accepted input: [y]
Wiping gpt signature on /dev/sdc.
Found existing signature on /dev/sdc at offset 510: LABEL="(null)" UUID="(null)" TYPE="PMBR" USAGE="partition table"
WARNING: PMBR signature detected on /dev/sdc at offset 510. Wipe it? [y/n]: y
Accepted input: [y]
Wiping PMBR signature on /dev/sdc.
Set up physical volume for "/dev/sda1" with 40960 available sectors.
Zeroing start of device /dev/sda1.
Writing physical volume data to disk "/dev/sda1".
Physical volume "/dev/sda1" successfully created.
Set up physical volume for "/dev/sdc" with 817890 available sectors.
Zeroing start of device /dev/sdc.
Writing physical volume data to disk "/dev/sdc".
Physical volume "/dev/sdc" successfully created.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvs
[sudo] password for user1:
PV VG Fmt Attr PSize PFree
/dev/sda1 lvm2 --- 20.00m 20.00m
/dev/sdc lvm2 --- 399.36m 399.36m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgcreate XYZvg /dev/sda1 /dev/sdc
Volume group "XYZvg" successfully created
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
XYZvg 2 0 0 wz--n- 412.00m 412.00m
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgdisplay XYZvg
--- Volume group ---
VG Name XYZvg
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 412.00 MiB
PE Size 4.00 MiB
Total PE 103
Alloc PE / Size 0 / 0
Free PE / Size 103 / 412.00 MiB
VG UUID fgfzjE-xUHx-5kye-gezM-jnLF-l3Am-7vmiMf
user1@rhel10-vm2:~$
rename#
user1@rhel10-vm2:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
myLVMvg2 2 2 0 wz--n- 792.00m 688.00m
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$ sudo vgrename myLVMvg2 LVMvg01
Volume group "myLVMvg2" successfully renamed to "LVMvg01"
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
LVMvg01 2 2 0 wz--n- 792.00m 688.00m
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$
extend#
For that, I create a new partition, initialize it to LVM by making it a physical volume, then add it to a virtual group using vgextend:
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
├─sda1 8:1 0 20M 0 part
│ └─vg03-myLV2 253:4 0 6M 0 lvm
└─sda2 8:2 0 78.1M 0 part
sdb 8:16 0 399.4M 0 disk
sdc 8:32 0 399.4M 0 disk
├─vg03-myLV1 253:2 0 30M 0 lvm
└─vg03-lvol0 253:3 0 50M 0 lvm
sdd 8:48 0 399.4M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$ sudo pvcreate -v /dev/sda2
Wiping signatures on new PV /dev/sda2.
Set up physical volume for "/dev/sda2" with 159928 available sectors.
Zeroing start of device /dev/sda2.
Writing physical volume data to disk "/dev/sda2".
Physical volume "/dev/sda2" successfully created.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgextend vg03 /dev/sda2
Volume group "vg03" successfully extended
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
├─sda1 8:1 0 20M 0 part
│ └─vg03-myLV2 253:4 0 6M 0 lvm
└─sda2 8:2 0 78.1M 0 part
sdb 8:16 0 399.4M 0 disk
sdc 8:32 0 399.4M 0 disk
├─vg03-myLV1 253:2 0 30M 0 lvm
└─vg03-lvol0 253:3 0 50M 0 lvm
sdd 8:48 0 399.4M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$ sudo vgs vg03
VG #PV #LV #SN Attr VSize VFree
vg03 3 3 0 wz--n- 492.00m 406.00m
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgdisplay -v vg03
--- Volume group ---
VG Name vg03
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 492.00 MiB
PE Size 2.00 MiB
Total PE 246
Alloc PE / Size 43 / 86.00 MiB
Free PE / Size 203 / 406.00 MiB
VG UUID 2XQmnd-rFUF-9SHc-Ubv5-cR0j-IBWZ-3cwbYO
--- Logical volume ---
LV Path /dev/vg03/lvol0
LV Name lvol0
VG Name vg03
LV UUID opOs26-Pt1Z-4SVf-bpsY-Ez8P-Aj04-6t5uY9
LV Write Access read/write
LV Creation host, time rhel10-vm2, 2026-08-30 10:50:21 +0200
LV Status available
# open 0
LV Size 50.00 MiB
Current LE 25
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
--- Logical volume ---
LV Path /dev/vg03/myLV1
LV Name myLV1
VG Name vg03
LV UUID WkHG9j-Xx2o-HXoB-8RB3-NdTd-3Eds-a9AmK4
LV Write Access read/write
LV Creation host, time rhel10-vm2, 2026-08-30 10:54:17 +0200
LV Status available
# open 0
LV Size 30.00 MiB
Current LE 15
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/vg03/myLV2
LV Name myLV2
VG Name vg03
LV UUID n1menZ-urKI-rDsC-W9pv-URNa-KRfT-ENEsGj
LV Write Access read/write
LV Creation host, time rhel10-vm2, 2026-08-30 11:41:40 +0200
LV Status available
# open 0
LV Size 6.00 MiB
Current LE 3
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:4
--- Physical volumes ---
PV Name /dev/sda1
PV UUID 1Ymb1r-U1yS-MGWO-QI0V-dLqf-Jmvs-O8tLV0
PV Status allocatable
Total PE / Free PE 9 / 6
PV Name /dev/sdc
PV UUID A6OQWY-Sxj6-tIyz-Nf1q-QexU-wSaw-mmIM3e
PV Status allocatable
Total PE / Free PE 199 / 159
PV Name /dev/sda2
PV UUID eqDpMN-ArmQ-s8Xk-cSme-fad9-X6GG-VjcMuU
PV Status allocatable
Total PE / Free PE 38 / 38
user1@rhel10-vm2:~$
reduce#
Reducing a virtual group means removing one or more physical volumes from it. In this example, vg03 has initially three physical volumes. I reduced vg03 by one physical volume using vgreduce. Note that the number and size of the logical volumes have not been impacted:
user1@rhel10-vm2:~$ sudo vgdisplay vg03 -v
--- Volume group ---
VG Name vg03
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 13
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 492.00 MiB
PE Size 2.00 MiB
Total PE 246
Alloc PE / Size 57 / 114.00 MiB
Free PE / Size 189 / 378.00 MiB
VG UUID 2XQmnd-rFUF-9SHc-Ubv5-cR0j-IBWZ-3cwbYO
--- Logical volume ---
LV Path /dev/vg03/myLV1
LV Name myLV1
VG Name vg03
LV UUID WkHG9j-Xx2o-HXoB-8RB3-NdTd-3Eds-a9AmK4
LV Write Access read/write
LV Creation host, time rhel10-vm2, 2026-08-30 10:54:17 +0200
LV Status available
# open 0
LV Size 56.00 MiB
Current LE 28
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
--- Logical volume ---
LV Path /dev/vg03/myLV2
LV Name myLV2
VG Name vg03
LV UUID n1menZ-urKI-rDsC-W9pv-URNa-KRfT-ENEsGj
LV Write Access read/write
LV Creation host, time rhel10-vm2, 2026-08-30 11:41:40 +0200
LV Status available
# open 0
LV Size 58.00 MiB
Current LE 29
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:4
--- Physical volumes ---
PV Name /dev/sda1
PV UUID 1Ymb1r-U1yS-MGWO-QI0V-dLqf-Jmvs-O8tLV0
PV Status allocatable
Total PE / Free PE 9 / 0
PV Name /dev/sdd
PV UUID A6OQWY-Sxj6-tIyz-Nf1q-QexU-wSaw-mmIM3e
PV Status allocatable
Total PE / Free PE 199 / 151
PV Name /dev/sda2
PV UUID eqDpMN-ArmQ-s8Xk-cSme-fad9-X6GG-VjcMuU
PV Status allocatable
Total PE / Free PE 38 / 38
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgreduce vg03 /dev/sda2
Removed "/dev/sda2" from volume group "vg03"
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgs vg03
VG #PV #LV #SN Attr VSize VFree
vg03 2 2 0 wz--n- 416.00m 302.00m
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 vg03 lvm2 a-- 18.00m 0
/dev/sda2 lvm2 --- <78.09m <78.09m
/dev/sdd vg03 lvm2 a-- 398.00m 302.00m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
What happens when I continue reducing the virtual group to a point that its size becomes smaller than that of the logical volumes on it?
user1@rhel10-vm2:~$ sudo lvs vg03
[sudo] password for user1:
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
myLV1 vg03 -wi-a----- 56.00m
myLV2 vg03 -wi-a----- 58.00m
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo pvs | grep vg03
/dev/sda1 vg03 lvm2 a-- 18.00m 0
/dev/sdd vg03 lvm2 a-- 398.00m 302.00m
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgreduce -v vg03 /dev/sdd
Physical volume "/dev/sdd" still in use
user1@rhel10-vm2:~$
LVM throws a messages and exits the operation.
remove#
Removing a virtual group:
- does not delete the attached physical volumes,
- deletes any attached logical volumes.
Example 1:
user1@rhel10-vm2:~$ sudo vgremove myLVMvg
Volume group "myLVMvg" successfully removed
user1@rhel10-vm2:~$
The virtual group is deleted;
user1@rhel10-vm2:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$
The physical volumes that were attached to the delete virtual group are kept:
user1@rhel10-vm2:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 399.36m 399.36m
/dev/sdd lvm2 --- 399.36m 399.36m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
Example 2:
user1@rhel10-vm2:~$ sudo vgs
[sudo] password for user1:
VG #PV #LV #SN Attr VSize VFree
LVMvg01 2 2 0 wz--n- 792.00m 688.00m
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgremove LVMvg01
Do you really want to remove volume group "LVMvg01" containing 2 logical volumes? [y/n]: y
Do you really want to remove active logical volume LVMvg01/mylv01? [y/n]: y
Logical volume "mylv01" successfully removed.
Do you really want to remove active logical volume LVMvg01/lvol0? [y/n]: y
Logical volume "lvol0" successfully removed.
Volume group "LVMvg01" successfully removed
user1@rhel10-vm2:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 21.95g
swap rhel -wi-ao---- 2.04g
user1@rhel10-vm2:~$
Example 3: remove in verbose mode
user1@rhel10-vm2:~$ sudo vgs vg03
VG #PV #LV #SN Attr VSize VFree
vg03 2 2 0 wz--n- 416.00m 302.00m
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgremove -v vg03
Do you really want to remove volume group "vg03" containing 2 logical volumes? [y/n]: y
Accepted input: [y]
Do you really want to remove active logical volume vg03/myLV1? [y/n]: y
Accepted input: [y]
Removing vg03-myLV1 (253:3)
Releasing logical volume "myLV1"
Archiving volume group "vg03" metadata (seqno 14).
Logical volume "myLV1" successfully removed.
Do you really want to remove active logical volume vg03/myLV2? [y/n]: y
Accepted input: [y]
Removing vg03-myLV2 (253:4)
Releasing logical volume "myLV2"
Archiving volume group "vg03" metadata (seqno 15).
Logical volume "myLV2" successfully removed.
Removing physical volume "/dev/sda1" from volume group "vg03"
Removing physical volume "/dev/sdd" from volume group "vg03"
Volume group "vg03" successfully removed
Creating volume group backup "/etc/lvm/backup/vg03" (seqno 16).
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgs vg03
Volume group "vg03" not found
Cannot process volume group vg03
user1@rhel10-vm2:~$
logical volumes#
A logical volume (LV) is the resulting logical disk or partition that is carved from a Virtual Group.
Logical volumes have types: linear, raid, striping, etc.
verify#
To display a report of the existing logical volumes, use the lvdisplay command:
user1@rhel10-vm2:~$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID RtaZ91-Wyfi-g3Qb-6H5V-RYsq-N5Ww-n6mAi1
LV Write Access read/write
LV Creation host, time rhel10-vm1, 2025-11-15 12:18:32 +0100
LV Status available
# open 1
LV Size 2.04 GiB
Current LE 523
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID RvCTV5-NeOx-CZAL-7ijh-FxyF-oj8n-amqJpY
LV Write Access read/write
LV Creation host, time rhel10-vm1, 2025-11-15 12:18:32 +0100
LV Status available
# open 1
LV Size 21.95 GiB
Current LE 5620
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
user1@rhel10-vm2:~$
Also, like the other architecture elements of LVM, there is a scan command to display a brief output on logical volumes:
user1@rhel10-vm2:~$ lvs
WARNING: Running as a non-root user. Functionality may be unavailable.
/run/lock/lvm/P_global:aux: open failed: Permission denied
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 21.95g
swap rhel -wi-ao---- 2.04g
user1@rhel10-vm2:~$
To display logical volume scan information of a particular logical volume, I use the following syntax: lvs {virt_group}/{logi_volume}.
In the following example, I detected the presence of logical volumes with lsblk.
It seems that a fresh RHEL installation process created three partitions /dev/vda1, /dev/vda2, /dev/vda3 and two logical volumes root and swap in the rhel virtual group by default.
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
├─sda1 8:1 0 114M 0 part [SWAP]
└─sda2 8:2 0 238M 0 part
└─vgfs-swapvol 253:4 0 256M 0 lvm [SWAP]
sdb 8:16 0 409.6M 0 disk
├─vgfs-ext4vol 253:2 0 96M 0 lvm /ext4fs2
└─vgfs-xfsvol 253:3 0 360M 0 lvm /xfsfs2
sdc 8:32 0 409.6M 0 disk
├─sdc1 8:33 0 150M 0 part
├─sdc2 8:34 0 150M 0 part
└─sdc3 8:35 0 96M 0 part
├─vgfs-ext4vol 253:2 0 96M 0 lvm /ext4fs2
├─vgfs-xfsvol 253:3 0 360M 0 lvm /xfsfs2
└─vgfs-swapvol 253:4 0 256M 0 lvm [SWAP]
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$
I noted down the format in which the names of the logical volumes are displayed in the output of lsblk: {virtual group}-{logical volume}:
rhel-root 253:0 0 22G 0 lvm /
rhel-swap 253:1 0 2G 0 lvm [SWAP]
To my surprise, running ls -l /dev/rhel/root showed a symlink to some sort of device mapper:
user1@rhel10-vm2:~$ ls -l /dev/vda3/rhel-root
ls: cannot access '/dev/vda3/rhel-root': Not a directory
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ ls -l /dev/vda3/rhel/root
ls: cannot access '/dev/vda3/rhel/root': Not a directory
user1@rhel10-vm2:~$ ls -l /dev/rhel-root
ls: cannot access '/dev/rhel-root': No such file or directory
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ ls -l /dev/rhel/root
lrwxrwxrwx. 1 root root 7 Sep 15 05:18 /dev/rhel/root -> ../dm-0
user1@rhel10-vm2:~$
And when I looked for dm-0, I found another symlink that involves the logical volume:
user1@rhel10-vm2:~$ ls -l /dev/mapper | grep dm-0
lrwxrwxrwx. 1 root root 7 Sep 15 05:18 rhel-root -> ../dm-0
user1@rhel10-vm2:~$
So both /dev/mapper/rhel-root and /dev/rhel/root point to the same dm-0 file.
user1@rhel10-vm2:~$ ls -l /dev/rhel/root
lrwxrwxrwx. 1 root root 7 Sep 15 05:18 /dev/rhel/root -> ../dm-0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ ls -l /dev/mapper/rhel-root
lrwxrwxrwx. 1 root root 7 Sep 15 05:18 /dev/mapper/rhel-root -> ../dm-0
user1@rhel10-vm2:~$
So the virtual block device that represents a logical volume should have the following syntax:
- /dev/{vg_name}/{lv_name}, or
- /dev/mapper/{vg_name}-{lv_name}
Now I inspected the details of the filesystems installed on them with lsblk -f:
user1@rhel10-vm2:~$ lsblk -f /dev/rhel/root
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
rhel-root xfs 1cc2a0e5-8ea2-4b31-bbe7-a6d47a824276 17.8G 19% /
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ lsblk -f /dev/rhel/swap
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
rhel-swap swap 1 543756ba-806e-4129-bc0b-757fb1e4d832 [SWAP]
user1@rhel10-vm2:~$
and converted their names to the correct arguments for the lvs command: {virtual group}/{logical volume}:
user1@rhel10-vm2:~$ sudo lvs rhel/root
[sudo] password for user1:
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 21.95g
user1@rhel10-vm2:~$
Logical volumes are also assigned UUID values. Notice the UUID value of 13b32685-320b-4c45-9809-c929f8825b05 of the swapvol logical volume in the example:
user1@rhel10-vm2:~$ lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1 swap 1 59e98274-b212-4fa2-b6c4-8e10726302ec
└─sda2 LVM2_member LVM2 001 iv5SDH-Oiyn-uSdh-6BUW-ETvx-F1JP-BWvCeP
└─vgfs-swapvol swap 1 13b32685-320b-4c45-9809-c929f8825b05
sdb LVM2_member LVM2 001 jVGmEt-OfuX-siS4-cufB-ceN6-QNHO-KeycBX
├─vgfs-ext4vol ext4 1.0 5377d2bc-f963-4db5-b0dc-679481b8da82 78.2M 0% /ext4fs2
└─vgfs-xfsvol xfs 4f91a6a3-9dc1-480c-9467-379666ef7566 272M 8% /xfsfs2
sdc
├─sdc1 ext4 1.0 72cdbb05-64a5-4a91-982f-c80b873a9536
├─sdc2 vfat FAT16 454C-606D
└─sdc3 LVM2_member LVM2 001 OMg5Lu-N6qU-HfQF-iK5U-RPNe-Skbt-xen5JX
├─vgfs-ext4vol ext4 1.0 5377d2bc-f963-4db5-b0dc-679481b8da82 78.2M 0% /ext4fs2
├─vgfs-xfsvol xfs 4f91a6a3-9dc1-480c-9467-379666ef7566 272M 8% /xfsfs2
└─vgfs-swapvol swap 1 13b32685-320b-4c45-9809-c929f8825b05
sr0 iso9660 Joliet Extension RHEL-10-1-BaseOS-x86_64 2025-10-21-06-14-30-00
vda
├─vda1
├─vda2 xfs mybootFS aeaf7891-fb70-4df0-90b6-bbd996703b8d 634.3M 34% /boot
└─vda3 LVM2_member LVM2 001 hzpR6U-8XIg-heCy-5Rca-Bmxx-ClO7-Cblxlg
├─rhel-root xfs 1cc2a0e5-8ea2-4b31-bbe7-a6d47a824276 17.8G 19% /
└─rhel-swap swap 1 543756ba-806e-4129-bc0b-757fb1e4d832 [SWAP]
user1@rhel10-vm2:~$
create#
user1@rhel10-vm2:~$ sudo vgs
[sudo] password for user1:
VG #PV #LV #SN Attr VSize VFree
myLVMvg2 2 0 0 wz--n- 792.00m 792.00m
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$
I intend to create a logical volume with a size of 50 MiB, named ‘mylv01’, of type linear and from the the myLVMvg2 virtual group. Notice that LVM changed the size to 52 MiB because 50 is not a multiple of the extent size, which is 4 MiB in the example, whereas 52 is.
user1@rhel10-vm2:~$ sudo lvcreate -L 50m -n mylv01 --type linear myLVMvg2
Rounding up size to full physical extent 52.00 MiB
Logical volume "mylv01" created.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
myLVMvg2 2 1 0 wz--n- 792.00m 740.00m
rhel 1 2 0 wz--n- <24.00g 0
user1@rhel10-vm2:~$ sudo lvdisplay myLVMvg2
--- Logical volume ---
LV Path /dev/myLVMvg2/mylv01
LV Name mylv01
VG Name myLVMvg2
LV UUID gLHzNC-enaU-eL7f-FCuL-doeG-2oL0-kRH2yc
LV Write Access read/write
LV Creation host, time rhel10-vm2, 2026-08-30 06:56:05 +0200
LV Status available
# open 0
LV Size 52.00 MiB
Current LE 13
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
user1@rhel10-vm2:~$
I want to test the dynamic naming feature of lvcreate when I do not explicitely give a name to a logical volume during its creation:
user1@rhel10-vm2:~$ sudo lvcreate -L 50 --type linear myLVMvg2
Rounding up size to full physical extent 52.00 MiB
Logical volume "lvol0" created.
user1@rhel10-vm2:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvol0 myLVMvg2 -wi-a----- 52.00m
mylv01 myLVMvg2 -wi-a----- 52.00m
root rhel -wi-ao---- 21.95g
swap rhel -wi-ao---- 2.04g
user1@rhel10-vm2:~$
Indeed, LVM assigned a name automatically to the new logical volume, and the name follows the lvolX pattern, where X is an incremental numeric index.
Note that I specified the type of the logical volume, linear, because I did not find a way to display the type of logical volumes yet.
Creating a logical volume in verbose mode. Note that I intentionally omitted the size unit (-L 30), and LVM assumed it was Mebibytes:
user1@rhel10-vm2:~$ sudo lvcreate -L 30 -v --type linear vg03 -n myLV1
Creating logical volume myLV1
Archiving volume group "vg03" metadata (seqno 4).
Activating logical volume vg03/myLV1.
activation/volume_list configuration setting not defined: Checking only host tags for vg03/myLV1.
Creating vg03-myLV1
Loading table for vg03-myLV1 (253:2).
Resuming vg03-myLV1 (253:2).
Wiping known signatures on logical volume vg03/myLV1.
Initializing 4.00 KiB of logical volume vg03/myLV1 with value 0.
Logical volume "myLV1" created.
Creating volume group backup "/etc/lvm/backup/vg03" (seqno 5).
user1@rhel10-vm2:~$
To display information about a logical volume with lvs, both the logical volume name and its virtual group must be specified:
user1@rhel10-vm2:~$ sudo lvs -v myLV1
VG name on command line not found in list of VGs: myLV1
Volume group "myLV1" not found
Cannot process volume group myLV1
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvs -v vg03/myLV1
LV VG #Seg Attr LSize Maj Min KMaj KMin Pool Origin Data% Meta% Move Cpy%Sync Log Convert LV UUID LProfile
myLV1 vg03 1 -wi-a----- 30.00m -1 -1 253 2 WkHG9j-Xx2o-HXoB-8RB3-NdTd-3Eds-a9AmK4
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvdisplay -v vg03/myLV1
[sudo] password for user1:
--- Logical volume ---
LV Path /dev/vg03/myLV1
LV Name myLV1
VG Name vg03
LV UUID WkHG9j-Xx2o-HXoB-8RB3-NdTd-3Eds-a9AmK4
LV Write Access read/write
LV Creation host, time rhel10-vm2, 2026-08-30 10:54:17 +0200
LV Status available
# open 0
LV Size 30.00 MiB
Current LE 15
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
user1@rhel10-vm2:~$
I can create logical volumes with a size as a multiple of the extent size using the -l option. In the following example, I check the size of the extent with vgdisplay | grep PE before that.
user1@rhel10-vm2:~$ sudo vgdisplay vg03
--- Volume group ---
VG Name vg03
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 416.00 MiB
PE Size 2.00 MiB
Total PE 208
Alloc PE / Size 43 / 86.00 MiB
Free PE / Size 165 / 330.00 MiB
VG UUID 2XQmnd-rFUF-9SHc-Ubv5-cR0j-IBWZ-3cwbYO
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvcreate -l 3 --type linear -n myLV2 vg03
Logical volume "myLV2" created.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvs vg03/myLV2
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
myLV2 vg03 -wi-a----- 6.00m
user1@rhel10-vm2:~$ sudo lvdisplay -v vg03/myLV2
--- Logical volume ---
LV Path /dev/vg03/myLV2
LV Name myLV2
VG Name vg03
LV UUID n1menZ-urKI-rDsC-W9pv-URNa-KRfT-ENEsGj
LV Write Access read/write
LV Creation host, time rhel10-vm2, 2026-08-30 11:41:40 +0200
LV Status available
# open 0
LV Size 6.00 MiB
Current LE 3
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:4
user1@rhel10-vm2:~$
The command created a logical volume with a size three multiples of the physical extent size, ie 6 MiB.
I thought that a logical volume can have any size. I was wrong; The size of a new logical volume shall not exceed that of the virtual group it belongs to:
user1@rhel10-vm2:~$ sudo vgs vgfs
VG #PV #LV #SN Attr VSize VFree
vgfs 2 2 0 wz--n- 496.00m 40.00m
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvcreate --size 250m --name swapvol vgfs
Rounding up size to full physical extent 256.00 MiB
Volume group "vgfs" has insufficient free space (5 extents): 32 required.
user1@rhel10-vm2:~$
It appears to me then that I need to assign additional physical volumes to the virtual group, so that the storage pool size covers the intended size of new logical volumes.
The storage abstraction advantage of using logical volumes became real to me when I saw a logical volume, swapvol, spanning more than one disk partition:
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
├─sda1 8:1 0 114M 0 part
└─sda2 8:2 0 238M 0 part
└─vgfs-swapvol 253:4 0 256M 0 lvm
sdb 8:16 0 409.6M 0 disk
├─vgfs-ext4vol 253:2 0 96M 0 lvm /ext4fs2
└─vgfs-xfsvol 253:3 0 360M 0 lvm /xfsfs2
sdc 8:32 0 409.6M 0 disk
├─sdc1 8:33 0 150M 0 part
├─sdc2 8:34 0 150M 0 part
└─sdc3 8:35 0 96M 0 part
├─vgfs-ext4vol 253:2 0 96M 0 lvm /ext4fs2
├─vgfs-xfsvol 253:3 0 360M 0 lvm /xfsfs2
└─vgfs-swapvol 253:4 0 256M 0 lvm
sr0 11:0 1 9.5G 0 rom
<---- output omitted ---->
user1@rhel10-vm2:~$ sudo vgdisplay -v vgfs
[sudo] password for user1:
<---- output omitted ---->
--- Logical volume ---
LV Path /dev/vgfs/swapvol
LV Name swapvol
VG Name vgfs
LV UUID ZTaAHD-r1mQ-5MHH-fvGp-5aRN-eb2L-uOxzMr
LV Write Access read/write
LV Creation host, time rhel10-vm2, 2026-09-12 04:21:53 +0200
LV Status available
# open 0
LV Size 256.00 MiB
Current LE 32
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:4
--- Physical volumes ---
PV Name /dev/sdb
PV UUID jVGmEt-OfuX-siS4-cufB-ceN6-QNHO-KeycBX
PV Status allocatable
Total PE / Free PE 51 / 0
PV Name /dev/sdc3
PV UUID OMg5Lu-N6qU-HfQF-iK5U-RPNe-Skbt-xen5JX
PV Status allocatable
Total PE / Free PE 11 / 2
PV Name /dev/sda2
PV UUID iv5SDH-Oiyn-uSdh-6BUW-ETvx-F1JP-BWvCeP
PV Status allocatable
Total PE / Free PE 29 / 0
user1@rhel10-vm2:~$
extend#
One requirement is to have enough free extents in the virtual group that cover the intended extension of the size of the logical volume.
In the example, the virtual group has 406 MiB free. I want to extend the size of one of its LVs by 50 MiB:
user1@rhel10-vm2:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 21.95g
swap rhel -wi-ao---- 2.04g
lvol0 vg03 -wi-a----- 50.00m
myLV1 vg03 -wi-a----- 30.00m
myLV2 vg03 -wi-a----- 6.00m
user1@rhel10-vm2:~$ sudo lvextend -L +50m vg03/myLV2
Size of logical volume vg03/myLV2 changed from 6.00 MiB (3 extents) to 56.00 MiB (28 extents).
Logical volume vg03/myLV2 successfully resized.
user1@rhel10-vm2:~$ sudo lvs vg03/myLV2
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
myLV2 vg03 -wi-a----- 56.00m
user1@rhel10-vm2:~$
This reduces the size of the free storage capacity of the virtual group from 406 MiB to 356 MiB:
user1@rhel10-vm2:~$ sudo vgs vg03
VG #PV #LV #SN Attr VSize VFree
vg03 3 3 0 wz--n- 492.00m 356.00m
user1@rhel10-vm2:~$
reduce#
In this example I am reducing the size of the lvolinitial logical volume by 25 MiB:
user1@rhel10-vm2:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 21.95g
swap rhel -wi-ao---- 2.04g
lvolinitial vg03 -wi-a----- 50.00m
myLV1 vg03 -wi-a----- 30.00m
myLV2 vg03 -wi-a----- 56.00m
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvreduce -L -25m vg03/lvolinitial
Rounding size to boundary between physical extents: 24.00 MiB.
No file system found on /dev/vg03/lvolinitial.
Size of logical volume vg03/lvolinitial changed from 50.00 MiB (25 extents) to 26.00 MiB (13 extents).
Logical volume vg03/lvolinitial successfully resized.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 21.95g
swap rhel -wi-ao---- 2.04g
lvolinitial vg03 -wi-a----- 26.00m
myLV1 vg03 -wi-a----- 30.00m
myLV2 vg03 -wi-a----- 56.00m
user1@rhel10-vm2:~$
resize#
Resizing operations cover both the extension and the reduction of the capacity of a logical volume.
Example: I intend to resize the myLV2 logical volume by adding 1 MiB. But since the configured extent size for this virtual group is 2 MiB, LVM adjusts my configured value to the smallest allocatable storage size, which is the size of an extent.
user1@rhel10-vm2:~$ sudo lvs vg03
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
myLV1 vg03 -wi-a----- 56.00m
myLV2 vg03 -wi-a----- 56.00m
user1@rhel10-vm2:~$ sudo lvresize -L +1m vg03/myLV2
Rounding size to boundary between physical extents: 2.00 MiB.
Size of logical volume vg03/myLV2 changed from 56.00 MiB (28 extents) to 58.00 MiB (29 extents).
Logical volume vg03/myLV2 successfully resized.
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvs vg03
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
myLV1 vg03 -wi-a----- 56.00m
myLV2 vg03 -wi-a----- 58.00m
user1@rhel10-vm2:~$
Increasing or decreasing the size of a logical volume is incomplete unless the size of its filesystem is also increased or decrease. The latter can take place automatically with lvresize -r if a certain condition is not triggered (I discussed this topic here), or manually with the fsadm command.
remove#
user1@rhel10-vm2:~$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 21.95g
swap rhel -wi-ao---- 2.04g
lvolinitial vg03 -wi-a----- 26.00m
myLV1 vg03 -wi-a----- 30.00m
myLV2 vg03 -wi-a----- 56.00m
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvremove -v vg03/lvolinitial
Do you really want to remove active logical volume vg03/lvolinitial? [y/n]: y
Accepted input: [y]
Removing vg03-lvolinitial (253:2)
Releasing logical volume "lvolinitial"
Archiving volume group "vg03" metadata (seqno 11).
Logical volume "lvolinitial" successfully removed.
Creating volume group backup "/etc/lvm/backup/vg03" (seqno 12).
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvs vg03/lvolinitial
Failed to find logical volume "vg03/lvolinitial"
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo lvs vg03
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
myLV1 vg03 -wi-a----- 56.00m
myLV2 vg03 -wi-a----- 56.00m
user1@rhel10-vm2:~$
extents#
When a physical volume is added to a virtual group, LVM sees it as a collection of physical extents (PE). An extent is the smallest unit of storage capacity in an LVM virtual group. Since logical volumes are virtually constructed from the pool of physical volumes, a logical volume is also seen by LVM as a collection of logical extents (LE). An extent preserves the same size whether in the context of a physical volume or logical volume. And extents in a virtual group have the same size.
The size of an extent in a virtual group can be seen in the output of vgdisplay and focusing on the value of PE size:
user1@rhel10-vm2:~$ sudo vgdisplay
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <24.00 GiB
PE Size 4.00 MiB
Total PE 6143
Alloc PE / Size 6143 / <24.00 GiB
Free PE / Size 0 / 0
VG UUID 2QotKh-8w0L-I3Ns-I15u-nP0O-RigF-REpN5O
user1@rhel10-vm2:~$
The extent size can be controlled by specifying the physical extent size (PE size) during the virtual group creation phase using the -s option of vgcreate:
user1@rhel10-vm2:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 lvm2 --- 20.00m 20.00m
/dev/sdc lvm2 --- 399.36m 399.36m
/dev/vda3 rhel lvm2 a-- <24.00g 0
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ vgcreate --help
WARNING: Running as a non-root user. Functionality may be unavailable.
vgcreate - Create a volume group
vgcreate VG_new PV ...
[ -A|--autobackup y|n ]
[ -c|--clustered y|n ]
[ -l|--maxlogicalvolumes Number ]
[ -p|--maxphysicalvolumes Number ]
[ -M|--metadatatype lvm2 ]
[ -s|--physicalextentsize Size[m|UNIT] ]
<---- output omitted ---->
user1@rhel10-vm2:~$ sudo vgcreate vg03 /dev/sda1 /dev/sdc -s 2m
Volume group "vg03" successfully created
user1@rhel10-vm2:~$
user1@rhel10-vm2:~$ sudo vgdisplay vg03
--- Volume group ---
VG Name vg03
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 416.00 MiB
PE Size 2.00 MiB
Total PE 208
Alloc PE / Size 0 / 0
Free PE / Size 208 / 416.00 MiB
VG UUID 2XQmnd-rFUF-9SHc-Ubv5-cR0j-IBWZ-3cwbYO
user1@rhel10-vm2:~$
finding out disk usage#
I still did not find a single command to find out how much space is available on a used disk. I do a combination of lsblk and whatever commands suitable, depending on whether partitions or logical volumes are created out of the disk.
user1@rhel10-vm2:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 409.6M 0 disk
├─vgfs-ext4vol 253:2 0 96M 0 lvm /ext4fs2
└─vgfs-xfsvol 253:3 0 360M 0 lvm /xfsfs2
sdb 8:16 0 409.6M 0 disk
├─sdb1 8:17 0 150M 0 part
├─sdb2 8:18 0 150M 0 part
└─sdb3 8:19 0 96M 0 part
├─vgfs-ext4vol 253:2 0 96M 0 lvm /ext4fs2
└─vgfs-xfsvol 253:3 0 360M 0 lvm /xfsfs2
sdc 8:32 0 409.6M 0 disk
sr0 11:0 1 9.5G 0 rom
vda 252:0 0 25G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 24G 0 part
├─rhel-root 253:0 0 22G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
user1@rhel10-vm2:~$
In the example, the disk /dev/sda has a total storage capacity of 409.6 MiB. It was converted to physical volume, added to a virtual group vgfs and used to create two logical volumes ext4vol and xfsvol. The combined size of the logical volumes is 96 + 360 = 456 MiB, which clearly exceeds the storage capacity of /dev/sda. However this is not wrong because logical volumes take their capacity from the pool of physical volumes.
open topics #TBC#
lvrename- finding out free storage space without manual addition and substraction in the output of
parted print.
related posts#
References#
- lernme.com/1-2/
- binarytides.com/bios-uefi-and-boot-process-explained
- thewindowsclub.com/difference-between-bios-and-uefi
- redhat.com/en/blog/partitions-fdisk
- docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_storage_devices/
- redhat.com/en/blog/create-physical-volume
- redhat.com/en/blog/create-volume-group
- redhat.com/en/blog/creating-logical-volumes
- docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_storage_devices/persistent-naming-attributes
- docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/configuring_and_managing_logical_volumes/overview-of-logical-volume-management
- docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/system_design_guide/configuring_and_managing_logical_volumes
- docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/managing_file_systems/partition-operations-with-parted_managing-file-systems
- docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/volume_group_overview
- docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/html/installation_guide/sect-trouble-during-no-gpt
- digilent.com/blog/mib-vs-mb-whats-the-difference/
- linuxquestions.org/questions/linux-software-2/difference-between-partition-type-and-file-system-4175597151/
- linuxjunkies.org/glossary/devtmpfs
- RHCSA Red Hat Enterprise Linux 10: Training and Exam Prep Guide, 2nd Edition, Asghar Ghori