ILWC What is loading Privacy Statement About ILWC
Registreer
111
Creating a filesystem under LVM control
martijn
linux lvm shell
The recipe for creating a Filesystem on a system with Logical Volume Management. This recipe let's you create a a new Volume Group. Ofcourse you can also add Logical Volumes/FS's to an existing VG.
  1. Create devices on the disk (fdisk)
  2. Create Physical Volumes (pvcreate)
  3. Create a colume group (vgcreate)
  4. Create Logical Volumes (lvcreate)
  5. Create a File System (mkfs)
  6. Mount the FS (mount)
  7. Use the FS


Create devices on the disk (fdisk)
[root@localhost /]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.32).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p    -- Print the current layout on the disk
Disk /dev/sda: 4.1 TiB, 4497636065280 bytes, 8784445440 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 7C88ED82-0394-48E0-B21A-DF06AD854875

Device         Start        End    Sectors   Size Type
/dev/sda1       2048       4095       2048     1M BIOS boot
/dev/sda2       4096    2101247    2097152     1G Linux filesystem
/dev/sda3    2101248  769126399  767025152 365.8G Linux LVM
/dev/sda4  769126400 2916610047 2147483648     1T Linux filesystem

Command (m for help): n -- Create a new device
Partition number (5-128, default 5): -- Accept default device number (enter)
First sector (2916610048-8784445406, default 2916610048): -- Accept the default starting sector (enter)
Last sector, +sectors or +size{K,M,G,T,P} (2916610048-8784445406, default 8784445406): +5G-- Supply the desired size

Created a new partition 5 of type 'Linux filesystem' and of size 5 GiB.

Command (m for help): n -- Again (I create two devices)
Partition number (6-128, default 6): 
First sector (2927095808-8784445406, default 2927095808): 
Last sector, +sectors or +size{K,M,G,T,P} (2927095808-8784445406, default 8784445406): +5G

Created a new partition 6 of type 'Linux filesystem' and of size 5 GiB.

Command (m for help): p -- Let's see what the layout is after creating the new devices
Disk /dev/sda: 4.1 TiB, 4497636065280 bytes, 8784445440 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 7C88ED82-0394-48E0-B21A-DF06AD854875

Device          Start        End    Sectors   Size Type
/dev/sda1        2048       4095       2048     1M BIOS boot
/dev/sda2        4096    2101247    2097152     1G Linux filesystem
/dev/sda3     2101248  769126399  767025152 365.8G Linux LVM
/dev/sda4   769126400 2916610047 2147483648     1T Linux filesystem
/dev/sda5  2916610048 2927095807   10485760     5G Linux filesystem -- There is the first new device
/dev/sda6  2927095808 2937581567   10485760     5G Linux filesystem -- And the second one

Command (m for help): w
The partition table has been altered.
Syncing disks.


Create Physical Volumes (pvcreate)
[root@localhost /]# pvcreate /dev/sda5 -- Create a Physical Volume (PV) from the first device
  Physical volume "/dev/sda5" successfully created.
[root@localhost /]# pvcreate /dev/sda6 -- And also from the second new device
  Physical volume "/dev/sda6" successfully created.
[root@localhost /]# 


Create a volume group (vgcreate)
[root@localhost /]# vgcreate practicevg /dev/sda5 /dev/sda6 -- Both new PV's are added to the new VG
  Volume group "practicevg" successfully created
[root@localhost /]# 


Create a Logical Volume (lvcreate)
[root@localhost /]# lvcreate -L +6G -n practivelv practicevg -- The LV is just a little bigger then one PV
  Logical volume "practivelv" created.
[root@localhost /]# 


Create a File System (mkfs)
[root@localhost /]# mkfs.ext4 /dev/practicevg/practivelv -- The FS is created on top of the LV
mke2fs 1.43.8 (1-Jan-2018)
Creating filesystem with 1572864 4k blocks and 393216 inodes
Filesystem UUID: 67e4f73b-f0c3-4496-9bbf-9919ff36b8b1
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

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

[root@localhost /]#


Mount the FS (mount)
[root@localhost /]# mkdir /practice -- First we need a mountpoint
[root@localhost /]# mount /dev/practicevg/practivelv /practice -- Do the actual mount
[root@localhost /]# mount | grep practive -- Is it really there?
/dev/mapper/practicevg-practivelv on /practice type ext4 (rw,relatime,seclabel)
[root@localhost /]# 


Use the FS
[root@localhost /]# cd practice/
[root@localhost practice]# touch practive_file -- Yes...I can write on the FS
[root@localhost practice]# df -h ./
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/practicevg-practivelv  5.9G   24M  5.6G   1% /practice
[root@localhost practice]#


If you want to know how to remove all of this have a look here.