Squoggle

Mac's tech blog

Tag Archives: pvcreate

Logical Volume on Nvme disk

This blog post is how to configure a new Nvme SSD disk with Logical Volumes, format it and then mount it for use on your Linux system. The OS I’m doing this on is Linux Mint 22.0 but the steps are very similar on other Linux distros.

List Disks

The first step is to get information about the disks on your system. Do that with the lshw command:

$ sudo lshw -class disk
$ sudo lshw -class disk
  *-disk                    
       description: ATA Disk
       product: Samsung SSD 870
       physical id: 0
       bus info: scsi@0:0.0.0
       logical name: /dev/sda
       version: 3B6Q
       serial: S75BNL0X510488E
       size: 931GiB (1TB)
       capabilities: gpt-1.00 partitioned partitioned:gpt
       configuration: ansiversion=5 guid=0a659757-d6ef-4549-a6fe-ad2ca7f79fb2 logicalsectorsize=512 sectorsize=512
  *-cdrom
       description: DVD writer
       product: DVD+-RW DU-8A5LH
       vendor: PLDS
       physical id: 1
       bus info: scsi@1:0.0.0
       logical name: /dev/cdrom
       logical name: /dev/sr0
       version: 6D1M
       capabilities: removable audio cd-r cd-rw dvd dvd-r
       configuration: ansiversion=5 status=nodisc
  *-namespace:0
       description: NVMe disk
       physical id: 0
       logical name: hwmon1
  *-namespace:1
       description: NVMe disk
       physical id: 2
       logical name: /dev/ng0n1
  *-namespace:2
       description: NVMe disk
       physical id: 1
       bus info: nvme@0:1
       logical name: /dev/nvme0n1
       size: 1863GiB (2TB)
       configuration: logicalsectorsize=512 sectorsize=512 wwid=eui.0025384541a0abf0

The device I’m interested in here is logical name: /dev/nvme0n1which is a 2 TB device.

Physical Volumes

Check status of Physical Volumes on the system:

$ sudo pvdisplay

I only see the boot device. This means no Physical Volume has been created yet on the ss

$ sudo pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vgmint
PV Size 931.01 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 238338
Free PE 0
Allocated PE 238338
PV UUID kGgo6r-HbVW-R0H8-Z4Ll-fGTO-fMej-O0iREI

Create the new Physical Volume on /dev/nvme0n1:

$ sudo pvcreate /dev/nvme0n1
$ sudo pvcreate /dev/nvme0n1
Physical volume "/dev/nvme0n1" successfully created.

Check and confirm:

$ sudo pvdisplay
$ sudo pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vgmint
PV Size 931.01 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 238338
Free PE 0
Allocated PE 238338
PV UUID kGgo6r-HbVW-R0H8-Z4Ll-fGTO-fMej-O0iREI

"/dev/nvme0n1" is a new physical volume of "<1.82 TiB"
--- NEW Physical volume ---
PV Name /dev/nvme0n1
VG Name
PV Size <1.82 TiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID lda15M-nH4L-CEok-QDat-2A1O-dPBI-VeTeEK

We now have the new Physical Volume on /dev/nvme0n1

Volume Group

Check the status of existing Volume Groups:

$ sudo vgdisplay
$ sudo vgdisplay
--- Volume group ---
VG Name vgmint
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 <931.01 GiB
PE Size 4.00 MiB
Total PE 238338
Alloc PE / Size 238338 / <931.01 GiB
Free PE / Size 0 / 0
VG UUID 88rFXN-yf9R-epV4-msvR-5cRr-zl0v-qxFUEd

You see that there already exists a Volume Group named vgmint where the root filesystem is installed.

Create the new Volume Group named vgnvme on the newly created /dev/nvme0n1 physical volume like this:

$ sudo vgcreate vgnvme /dev/nvme0n1
$ sudo vgcreate vgnvme /dev/nvme0n1
Volume group "vgnvme" successfully created

Then confirm it was created correctly:

$ sudo vgdisplay vgnvme
$ sudo vgdisplay vgnvme
--- Volume group ---
VG Name vgnvme
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <1.82 TiB
PE Size 4.00 MiB
Total PE 476932
Alloc PE / Size 0 / 0
Free PE / Size 476932 / <1.82 TiB
VG UUID pH9fRB-QXRz-IGkL-t57V-xVXm-NP15-rf9vlA

Logical Volume

Now review the existing Logical Volumes on the system with the lvdisplay command:

$ sudo lvdisplay
$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/vgmint/root
LV Name root
VG Name vgmint
LV UUID Oq70Uf-b9zI-zQE1-134v-Zi0t-M6ee-jGYgD1
LV Write Access read/write
LV Creation host, time mint, 2024-08-27 18:47:19 -0400
LV Status available
# open 1
LV Size <929.10 GiB
Current LE 237849
Segments 1
Allocation inherit
Read ahead sectors auto
currently set to 256
Block device 252:0 

--- Logical volume ---
LV Path /dev/vgmint/swap_1
LV Name swap_1
VG Name vgmint
LV UUID 82mxHk-oqhS-I1DF-HsRo-OaBs-S5la-lG70HE
LV Write Access read/write
LV Creation host, time mint, 2024-08-27 18:47:19 -0400
LV Status available open 2 LV Size 1.91 GiB
Current LE 489
Segments 1
Allocation inherit
Read ahead sectors auto
currently set to 256
Block device 252:1

You see that I have en existing Logical Volume named root for the root filesystem and another named swap_1 for the swap space. Both Logical Volumes reside on the vgmint Volume Group.

Now create a new Logical Volume named volnvme on the newly created vgnvme Volume Group. Create it using the maximum space allowed on the Volume Group:

$ sudo lvcreate -n volnvme -l 100%FREE vgnvme
$ sudo lvcreate -n volnvme -l 100%FREE vgnvme
Logical volume "volnvme" created.

Then confirm it was created correctly. Use volume_group/volume_name format when displaying:

$ sudo lvdisplay vgnvme/volnvme
$ sudo lvdisplay vgnvme/volnvme
--- Logical volume ---
LV Path /dev/vgnvme/volnvme
LV Name volnvme
VG Name vgnvme
LV UUID v2DC8Q-XQPk-aFUU-X8wR-XWCq-RCYx-i80TFB
LV Write Access read/write
LV Creation host, time Gob, 2024-09-01 16:43:52 -0400
LV Status available
# open 0
LV Size <1.82 TiB
Current LE 476932
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2

This shows the correctly created Logical Volume that is associated with the Volume Group.

Create Filesystem

Before we can use it we need to create a filesystem on the Logical volume. I’m going to create a ext4 filesystem:

$ sudo mkfs.ext4 /dev/vgnvme/volnvme
$ sudo mkfs.ext4 /dev/vgnvme/volnvme
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 488378368 4k blocks and 122101760 inodes
Filesystem UUID: 74388657-077d-46ca-adb4-44e986ff6c47
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

Mount the Logical Volume

Now that you have the file system created you are ready to mount it somewhere. I want to mount it within my own user’s home directory. I need to create a mount point for this:

$ mkdir -p ~/mnt/nvme

Notice I did not use sudo. I want this directory structure and all files own by my user.

Now test mount the new Logical volume on the location you created for it like this:

$ sudo mount /dev/vgnvme/volnvme /home/mac/mnt/nvme

If everything went as expected you should not get any response to the above command.

Verify that the Logical Volume is mounted:

$ mount | grep /dev/mapper/vgnvme-volnvme
$ mount | grep /dev/mapper/vgnvme-volnvme
/dev/mapper/vgnvme-volnvme on /home/mac/mnt/nvme type ext4 (rw,relatime)

If you check file and group ownership of the /home/mac/mnt/nvme directory at this point you will see that it is owned by root even though we created it without sudo. This is because we had to mount it as root and it took on root ownership. Now that is is mounted you can change this ownership:

$ cd ~/mnt
$ sudo chown -R mac:mac ~/mnt/nvme/

Now un-mount the filesystem:

$ sudo umount /home/mac/mnt/nvme

Automatically mount this filesystem when booting

I want this filesystem to always be automatically mounted when the system boots. This means there needs to be an entry in the /etc/fstab file that directs the system to mount it.

First you will need to see what the mapper for this filesystem is. You can find it by doing a listing in /dev/mapper:

$ ll /dev/mapper

I see the following:

$ ll /dev/mapper
total 0
crw------- 1 root root 10, 236 Aug 30 17:54 control
lrwxrwxrwx 1 root root 7 Aug 30 17:54 vgmint-root -> ../dm-0
lrwxrwxrwx 1 root root 7 Aug 30 17:54 vgmint-swap_1 -> ../dm-1
lrwxrwxrwx 1 root root 7 Sep 1 16:43 vgnvme-volnvme -> ../dm-2

It looks like my mapper device is /dev/mapper/vgnvme-volnvme

Now, edit the /etc/fstab file as root user and add a section that looks like this:

# Internal NVME Disk
/dev/mapper/vgnvme-volnvme /home/mac/mnt/nvme ext4 errors=remount-ro 0 1

Tell the systemctl daemon to reload:

$ sudo systemctl daemon-reload

Now tell the system to mount that filesystem:

$ sudo mount /dev/mapper/vgnvme-volnvme

Confirm the file system is mounted:

$ mount | grep /dev/mapper/vgnvme-volnvme

Once you have confirmed you can reboot the system and confirm that the new filesystem automatically mounts on a reboot.