basic LVM

Linux Logical Volume Manager --LVM basic notes

the system
# cat /etc/issue
Debian GNU/Linux 7 \n \l
# uname -r
3.2.0-4-amd64


Install the LVM, the Linux Kernel Device Mapper userspace library and the partition manipulator.
# apt-get install lvm2 dmsetup parted


Prepare physical volume /dev/sdc for use by the LVM.
Remove MBR and partition table ( most of my drives are used )
# dd if=/dev/zero of=/dev/sdc bs=512 count=1


Initialize sdc for use as an LVM Physical Volume.
# pvcreate /dev/sdc
  Can't open /dev/sdc exclusively.  Mounted filesystem?
# pvcreate -f /dev/sdc
  Can't open /dev/sdc exclusively.  Mounted filesystem?
nope, it's not mounted --not even partitioned ... 5 minutes of looking around ... fakit
# shutdown -r now


...

initialize sdc for use as an LVM Physical Volume.
# pvcreate /dev/sdc
  Writing physical volume data to disk "/dev/sdc"
  Physical volume "/dev/sdc" successfully created


View LVM Physical Volumes
# pvdisplay 
  "/dev/sdc" is a new physical volume of "1.82 TiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name               
  PV Size               1.82 TiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               LY8rp6-IxmV-Cd4Z-AalR-ZN45-6cp5-U2iiVM
   



Create LVM Volume Group 'insigdato'
# vgcreate insigdato /dev/sdc
  Volume group "insigdato" successfully created


display volume groups and their attributes
# vgdisplay
  --- Volume group ---
  VG Name               insigdato
  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               2j2iVB-ugas-kQyT-5AC1-RcIk-1Lju-sY39Ec



Add LVM logical volume "movies" to the LVM volume group "insigdato"
# lvcreate --name movies --size 150G insigdato
  Logical volume "movies" created


Add LVM logical volume "mp3" to LVM VG insigdato
# lvcreate --name mp3 --size 50G insigdato


Add LVM logical volume "OS.iso" to LVM VG insigdato
# lvcreate --name OS.iso --size 50G insigdato


Display logical volumes
# lvdisplay


format the mp3 logical volume
# mkfs.ext3 /dev/insigdato/mp3


format the movies LVM logical volume
# mkfs.xfs -f /dev/insigdato/movies


format /dev/insigato/OS.iso
# mkfs.ext4 /dev/insigdato/OS.iso


create mount points, adjust fstab and mount
# mkdir /insigdato
# mkdir /insigdato/movies
# mkdir /insigdato/OS.iso
# mkdir /insigdato/mp3
# echo "/dev/insigdato/movies  /insigdato/movies  xfs   rw,noatime   0 0" >> /etc/fstab   
# echo "/dev/insigdato/OS.iso  /insigdato/OS.iso  ext4   rw,noatime   0 0" >> /etc/fstab   
# echo "/dev/insigdato/mp3  /insigdato/mp3  ext3   rw,noatime   0 0" >> /etc/fstab   
# for i in `ls /dev/insigdato`;do mount /dev/insigdato/$i /insigdato/$i;done


Check the LVM physical volume
# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sdc
  VG Name               insigdato
  PV Size               1.82 TiB / not usable 1.09 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              476932
  Free PE               412932
  Allocated PE          64000
  PV UUID               LY8rp6-IxmV-Cd4Z-AalR-ZN45-6cp5-U2iiVM



hmm, 150GiB for movies? ... need more

extend the movies LVM logical volume
# lvextend -L165G /dev/insigdato/movies
  Extending logical volume movies to 165.00 GiB
  Logical volume movies successfully resized


Extend the xfs filesystem used by movies
# xfs_growfs /dev/insigdato/movies
meta-data=/dev/mapper/insigdato-movies isize=256    agcount=16, agsize=2457600 blks
         =                       sectsz=512   attr=2
data     =                       bsize=4096   blocks=39321600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal               bsize=4096   blocks=19200, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 39321600 to 43253760
while mounted and without affecting its contents ...

LVM introduction notes