3

I am learning linux system administration on ubuntu trusty and I had to create logical volumes from two partitions created off the disk in the ubuntu VM.

Now this is how it went:

sudo pvcreate /dev/sda3
sudo pvcreate /dev/sda4

sudo vgcreate myvg /dev/sda3 /dev/sda4

sudolvcreate -L 300M -n mylvm myvg

sudo mkdir mylvm

sudo mkfs.ext4 /dev/myvg/mylvm

sudo mount /dev/myvg/mylvm /mylvm

sudo lvextend -L 350M /dev/myvg/mylvm

Then added this to /etc/fstab

/dev/myvg/mylvm /mylvm ext4 defaults 0 0 

Now if I run lsblk I see this:

NAME                  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                     8:0    0    40G  0 disk 
├─sda1                  8:1    0    18G  0 part /
├─sda2                  8:2    0     1K  0 part 
├─sda3                  8:3    0   3.9G  0 part 
│ └─myvg-mylvm (dm-0) 252:0    0   352M  0 lvm  /mylvm
├─sda4                  8:4    0   4.8G  0 part 
└─sda5                  8:5    0     2G  0 part [SWAP]
sr0                    11:0    1  1024M  0 rom 

Now why is the /dev/sda3 the only physical volume with the assigned size, would have thought /dev/sda4 would also have a branch too. Perhaps I have not understood how LVM works. A good explanation would really clear me.

George Udosen
  • 36,677

1 Answers1

2

You have create two LVM physical volumes sda3 with 3.9 GB in size and sda4 with 4.8 GB in size.

After that you have created volume group myvg which spans across LVM physical volumes sda3 and sda4 to total of 7.7 GB size.

You continued with creating logical volume mylvm with 300 MB size. Currently mylvm is smaller than physical volume sda3, which means that logical volume mylvm resides only on pyhsical volume sda3.

Try to extend logical volume for a size larger than sda3 (for example 5 GB) and don't forget to resize ext4 file system after that with commands

sudo lvextend -L 5G /dev/myvg/mylvm
sudo resize2fs /dev/myvg/mylvm

Check output of command lsblk, logical volume myvg-mylvm should be spanned across sda3 and sda4 . There are other commands for LVM as well - for example vgs for volume group status and lvs for logical volume status.

iuuuuan
  • 224
  • Hi iuuuan, Thanks for the answer. Again why does the new output of lsblk give me same size for both/dev/sda3 and /dev/sda4 as seen as size 5G was expecting /dev/sda3 to be 3.9G and /dev/sda4 to be 1.1G. Since /dev/sda3 was 3.9G in size and /dev/sda4 was 4G. – George Udosen Aug 06 '16 at 09:21
  • Is there any myvg-mylvm under sda3 with size 3.9 GB and sda4 with size 1.1 GB ? sda3 and sda4 are physical volumes (lvm partitions) on which you add volume group which spans fully across physical volumes sda3 and sda4. You can create multiple logical volumes on volume group. Try some other commands like pvdisplay, vgdisplay, lvdisplay and pvs. – iuuuuan Aug 06 '16 at 11:13
  • excellent answer that explains it all. Thanks again – George Udosen Aug 06 '16 at 11:52