<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pedromussato.com/index.php?action=history&amp;feed=atom&amp;title=Linux_LVM</id>
	<title>Linux LVM - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pedromussato.com/index.php?action=history&amp;feed=atom&amp;title=Linux_LVM"/>
	<link rel="alternate" type="text/html" href="https://wiki.pedromussato.com/index.php?title=Linux_LVM&amp;action=history"/>
	<updated>2026-04-08T10:28:10Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://wiki.pedromussato.com/index.php?title=Linux_LVM&amp;diff=10&amp;oldid=prev</id>
		<title>413vhcu1lq0463ob: Created page with &quot;=== Finding the volumes wanted === Use the command lsblk to find what devices you want to use (if it isn&#039;t partitioned yet).  sdb                         8:16   0  32G  0 disk   sdc                         8:32   0  32G  0 disk   sdd                         8:48   0  32G  0 disk   sde                         8:64   0  32G  0 disk   sdf                         8:80   0  32G  0 disk   In my case I&#039;ll use sdb, sdc, sdd, sde and sdf.  === Formating the partition === To forma...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.pedromussato.com/index.php?title=Linux_LVM&amp;diff=10&amp;oldid=prev"/>
		<updated>2024-10-06T22:26:53Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;=== Finding the volumes wanted === Use the command lsblk to find what devices you want to use (if it isn&amp;#039;t partitioned yet).  sdb                         8:16   0  32G  0 disk   sdc                         8:32   0  32G  0 disk   sdd                         8:48   0  32G  0 disk   sde                         8:64   0  32G  0 disk   sdf                         8:80   0  32G  0 disk   In my case I&amp;#039;ll use sdb, sdc, sdd, sde and sdf.  === Formating the partition === To forma...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=== Finding the volumes wanted ===&lt;br /&gt;
Use the command lsblk to find what devices you want to use (if it isn&amp;#039;t partitioned yet).&lt;br /&gt;
 sdb                         8:16   0  32G  0 disk &lt;br /&gt;
 sdc                         8:32   0  32G  0 disk &lt;br /&gt;
 sdd                         8:48   0  32G  0 disk &lt;br /&gt;
 sde                         8:64   0  32G  0 disk &lt;br /&gt;
 sdf                         8:80   0  32G  0 disk &lt;br /&gt;
&lt;br /&gt;
In my case I&amp;#039;ll use sdb, sdc, sdd, sde and sdf.&lt;br /&gt;
&lt;br /&gt;
=== Formating the partition ===&lt;br /&gt;
To format the partitions I&amp;#039;ll use the fdisk command, to use it you can do the following:&lt;br /&gt;
 fdisk /dev/YOUR-DISK&lt;br /&gt;
(e.g.)&lt;br /&gt;
 fdisk /dev/sdb&lt;br /&gt;
And I&amp;#039;ll do the following for each disk.&lt;br /&gt;
&lt;br /&gt;
==== Create a primary partition ====&lt;br /&gt;
To create a primary partition we can use the letter &amp;#039;n&amp;#039; select &amp;#039;p&amp;#039; to primary and everything else can be just enter, enter, enter.&lt;br /&gt;
 Command (m for help): n&lt;br /&gt;
 Partition type&lt;br /&gt;
    p   primary (0 primary, 0 extended, 4 free)&lt;br /&gt;
    e   extended (container for logical partitions)&lt;br /&gt;
 Select (default p): &lt;br /&gt;
 &lt;br /&gt;
 Using default response p.&lt;br /&gt;
 Partition number (1-4, default 1): &lt;br /&gt;
 First sector (2048-67108863, default 2048): &lt;br /&gt;
 Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-67108863,  default 67108863): &lt;br /&gt;
 &lt;br /&gt;
 Created a new partition 1 of type &amp;#039;Linux&amp;#039; and of size 32 GiB.&lt;br /&gt;
&lt;br /&gt;
==== Change the partition type to Linux LVM ====&lt;br /&gt;
Now to change the partition type to Linux LVM we click &amp;#039;t&amp;#039; and then list all partitions type with the command L, usually Linux LVM can be configured using &amp;#039;Linux LVM&amp;#039;, &amp;#039;8e&amp;#039; or &amp;#039;44&amp;#039;. In my case I wrote Linux LVM&lt;br /&gt;
 Command (m for help): t&lt;br /&gt;
 Selected partition 1&lt;br /&gt;
 Hex code or alias (type L to list all): Linux LVM&lt;br /&gt;
 Changed type of partition &amp;#039;Linux&amp;#039; to &amp;#039;Linux LVM&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
==== Save and exit ====&lt;br /&gt;
To save our work and exit the fdisk we click &amp;#039;w&amp;#039; and it&amp;#039;s done.&lt;br /&gt;
 Command (m for help): w&lt;br /&gt;
 The partition table has been altered.&lt;br /&gt;
 Calling ioctl() to re-read partition table.&lt;br /&gt;
 Syncing disks.&lt;br /&gt;
&lt;br /&gt;
Now we have the /dev/sdb formated let&amp;#039;s just reply the same to all other drives wanted.&lt;br /&gt;
&lt;br /&gt;
This is what looks like formating a disk to be an LVM:&lt;br /&gt;
 # fdisk /dev/sdd&lt;br /&gt;
 &lt;br /&gt;
 Welcome to fdisk (util-linux 2.39.3).&lt;br /&gt;
 Changes will remain in memory only, until you decide to write them.&lt;br /&gt;
 Be careful before using the write command.&lt;br /&gt;
 &lt;br /&gt;
 Device does not contain a recognized partition table.&lt;br /&gt;
 Created a new DOS (MBR) disklabel with disk identifier 0x51929328.&lt;br /&gt;
 &lt;br /&gt;
 Command (m for help): n&lt;br /&gt;
 Partition type&lt;br /&gt;
    p   primary (0 primary, 0 extended, 4 free)&lt;br /&gt;
    e   extended (container for logical partitions)&lt;br /&gt;
 Select (default p): p&lt;br /&gt;
 Partition number (1-4, default 1): &lt;br /&gt;
 First sector (2048-67108863, default 2048): &lt;br /&gt;
 Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-67108863, default 67108863): &lt;br /&gt;
 &lt;br /&gt;
 Created a new partition 1 of type &amp;#039;Linux&amp;#039; and of size 32 GiB.&lt;br /&gt;
 &lt;br /&gt;
 Command (m for help): t&lt;br /&gt;
 Selected partition 1&lt;br /&gt;
 Hex code or alias (type L to list all): Linux LVM&lt;br /&gt;
 Changed type of partition &amp;#039;Linux&amp;#039; to &amp;#039;Linux LVM&amp;#039;.&lt;br /&gt;
 &lt;br /&gt;
 Command (m for help): w&lt;br /&gt;
 The partition table has been altered.&lt;br /&gt;
 Calling ioctl() to re-read partition table.&lt;br /&gt;
 Syncing disks.&lt;br /&gt;
 &lt;br /&gt;
=== Creating the PV (Physical volume) ===&lt;br /&gt;
Now we have all partitions created we need to create all PVs, this is just simple, use the command pvcreate and the partition created like that:&lt;br /&gt;
 pvcreate /dev/sdb1&lt;br /&gt;
Then the output should be like&lt;br /&gt;
 Physical volume &amp;quot;/dev/sdb1&amp;quot; successfully created.&lt;br /&gt;
We can check using the command pvs, like:&lt;br /&gt;
 # pvs&lt;br /&gt;
   PV         VG        Fmt  Attr PSize   PFree  &lt;br /&gt;
   /dev/sdb1  myvg      lvm2 a--  &amp;lt;32.00g &amp;lt;32.00g&lt;br /&gt;
   /dev/sdc1  myvg      lvm2 a--  &amp;lt;32.00g &amp;lt;32.00g&lt;br /&gt;
   /dev/sdd1  myvg      lvm2 a--  &amp;lt;32.00g &amp;lt;32.00g&lt;br /&gt;
   /dev/sde1  myvg      lvm2 a--  &amp;lt;32.00g &amp;lt;32.00g&lt;br /&gt;
   /dev/sdf1  myvg      lvm2 a--  &amp;lt;32.00g &amp;lt;32.00g&lt;br /&gt;
&lt;br /&gt;
=== Creating the VG (Volume group) ===&lt;br /&gt;
Now that all our PVs is created we can create a volume group with the command vgcreate and pass all our PVs to the VG&lt;br /&gt;
 vgcreate VG_NAME pv1 pv2 ...&lt;br /&gt;
(e.g.)&lt;br /&gt;
 vgcreate myvg /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1&lt;br /&gt;
And we should see a message like that&lt;br /&gt;
 Volume group &amp;quot;myvg&amp;quot; successfully created&lt;br /&gt;
We can check using the command vgs, like:&lt;br /&gt;
 # vgs&lt;br /&gt;
   VG        #PV #LV #SN Attr   VSize   VFree  &lt;br /&gt;
   myvg        5   0   0 wz--n- 159.98g 159.98g&lt;br /&gt;
&lt;br /&gt;
=== Adding PVs to the VG ===&lt;br /&gt;
To add a new PV on the VG we can use the command vgextend passing the vg name and the pv wanted, like:&lt;br /&gt;
 vgextend VG_NAME pv3&lt;br /&gt;
(e.g.)&lt;br /&gt;
 vgextend myvg /dev/sdf1&lt;br /&gt;
And we should have a response like that:&lt;br /&gt;
 Volume group &amp;quot;myvg&amp;quot; successfully extended&lt;br /&gt;
&lt;br /&gt;
=== Removing PVs from the VG ===&lt;br /&gt;
To remove a pv from a vg we can use the command vgreduce passing the vg name and the pv wanted, like: &lt;br /&gt;
 vgreduce myvg pv3&lt;br /&gt;
(e.g.)&lt;br /&gt;
 vgreduce myvg /dev/sdf1&lt;br /&gt;
And we should have a response like that:&lt;br /&gt;
 Removed &amp;quot;/dev/sdf1&amp;quot; from volume group &amp;quot;myvg&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Updating changes ===&lt;br /&gt;
After any change run the command partprobe just to update all configurations. Shouldn&amp;#039;t get any response from the shell.&lt;br /&gt;
&lt;br /&gt;
=== Verifying the VG created ===&lt;br /&gt;
To check all informations about our VG we can use the command vgdisplay, like:&lt;br /&gt;
 # vgdisplay myvg&lt;br /&gt;
   --- Volume group ---&lt;br /&gt;
   VG Name               myvg&lt;br /&gt;
   System ID             &lt;br /&gt;
   Format                lvm2&lt;br /&gt;
   Metadata Areas        5&lt;br /&gt;
   Metadata Sequence No  5&lt;br /&gt;
   VG Access             read/write&lt;br /&gt;
   VG Status             resizable&lt;br /&gt;
   MAX LV                0&lt;br /&gt;
   Cur LV                0&lt;br /&gt;
   Open LV               0&lt;br /&gt;
   Max PV                0&lt;br /&gt;
   Cur PV                5&lt;br /&gt;
   Act PV                5&lt;br /&gt;
   VG Size               159.98 GiB&lt;br /&gt;
   PE Size               4.00 MiB&lt;br /&gt;
   Total PE              40955&lt;br /&gt;
   Alloc PE / Size       0 / 0   &lt;br /&gt;
   Free  PE / Size       40955 / 159.98 GiB&lt;br /&gt;
   VG UUID               2yqVka-ysy3-9Adj-lc6v-3P0f-8a3w-dDb0IH&lt;br /&gt;
&lt;br /&gt;
=== Creating the LV ===&lt;br /&gt;
To create the LV we can choose use the size or the PE units.&lt;br /&gt;
&lt;br /&gt;
To create using the PE we can use the command:&lt;br /&gt;
 lvcreate -L SIZE -n LV_NAME VG_NAME&lt;br /&gt;
(e.g.)&lt;br /&gt;
 lvcreate -L 150G -n mylv myvg&lt;br /&gt;
And we should have a response like that:&lt;br /&gt;
 Logical volume &amp;quot;mylv&amp;quot; created.&lt;br /&gt;
We can check using the command lvs, like:&lt;br /&gt;
 # lvs&lt;br /&gt;
   LV        VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert&lt;br /&gt;
   mylv      myvg      -wi-a----- 150.00g&lt;br /&gt;
&lt;br /&gt;
==== Adding volume to the lv ====&lt;br /&gt;
First add check if you have volume avail on the vg, if yes you can do in 2 ways percentage or size:&lt;br /&gt;
&lt;br /&gt;
Percentage:&lt;br /&gt;
 lvextend -l X%FREE /dev/myvg/mylv&lt;br /&gt;
(e.g.)&lt;br /&gt;
 lvextend -l 100%FREE /dev/myvg/mylv&lt;br /&gt;
That way all the avail volume on the vg will be added to the LV.&lt;br /&gt;
&lt;br /&gt;
Fixed size:&lt;br /&gt;
 lvextend -L +NG /dev/myvg/mylv&lt;br /&gt;
(e.g.)&lt;br /&gt;
 lvextend -L +1G /dev/myvg/mylv&lt;br /&gt;
That way the lv will extend in 1G.&lt;br /&gt;
&lt;br /&gt;
===== Resize =====&lt;br /&gt;
After these changes always run&lt;br /&gt;
 resize2fs /dev/myvg/mylv&lt;br /&gt;
Than the values will be formatted and the lv will assume the actual total volume.&lt;br /&gt;
&lt;br /&gt;
=== Formating the LV and mounting on the OS ===&lt;br /&gt;
To create a file system on the LV we can use the command mkfs.ext4 or mkfs.xfs or other types of FS, like&lt;br /&gt;
 mkfs.ext4 /dev/VG_NAME/LV_NAME&lt;br /&gt;
(e.g.)&lt;br /&gt;
&lt;br /&gt;
 # mkfs.ext4 /dev/myvg/mylv&lt;br /&gt;
We should get something like that from the shell:&lt;br /&gt;
 &lt;br /&gt;
 mke2fs 1.47.0 (5-Feb-2023)&lt;br /&gt;
 Discarding device blocks: done                            &lt;br /&gt;
 Creating filesystem with 39321600 4k blocks and 9830400 inodes&lt;br /&gt;
 Filesystem UUID: 0d1418be-f4f7-4ea9-a309-245c618c9d5a&lt;br /&gt;
 Superblock backups stored on blocks: &lt;br /&gt;
 	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, &lt;br /&gt;
 	4096000, 7962624, 11239424, 20480000, 23887872&lt;br /&gt;
 &lt;br /&gt;
 Allocating group tables: done                            &lt;br /&gt;
 Writing inode tables: done                            &lt;br /&gt;
 Creating journal (262144 blocks): done&lt;br /&gt;
 Writing superblocks and filesystem accounting information: done&lt;br /&gt;
To mount this FS on the OS we can use the command mount&lt;br /&gt;
 mount /dev/VG_NAME/LV_NAME OS_MOUNTING_POINT&lt;br /&gt;
(e.g.)&lt;br /&gt;
 mount /dev/myvg/mylv /mnt&lt;br /&gt;
With the command df -h we can check the mounting points, like that:&lt;br /&gt;
 Filesystem                         Size  Used Avail Use% Mounted on&lt;br /&gt;
 /dev/mapper/nfs-nfs                147G   28K  140G   1% /mnt&lt;br /&gt;
&lt;br /&gt;
=== Auto mounting the LV on the OS on boot ===&lt;br /&gt;
We can do it in two ways, just write the mount command on the /etc/rc.local and the mount command will be executed on boot ([[Executing scripts on Linux boot|link]]) or we can use the /etc/fstab to mount on boot (link).&lt;/div&gt;</summary>
		<author><name>413vhcu1lq0463ob</name></author>
	</entry>
</feed>