====== Creating a LVM ======
Source: [[https://doc.ubuntu-fr.org/lvm|doc Ubuntu-fr - LVM]] \\ \\
In this example we will create a LVM placed on 2 partitions: sda10 and sdb1 \\
All the command are done with root permissions => ''su'' or ''sudo'' \\
- if not present, create (with fdisk od gparted or...) the both partitions. \\ __**Be careful:**__all the data stored on these partition will be lost!
- create the both physical volumes:
pvcreate /dev/sda10
pvcreate /dev/sdb1
''pvdisplay'' or ''pvscan'' to get info.
- create the volume group "vgBackupPC":
vgcreate vgBackupPC /dev/sda10 /dev/sdb1
''vgdisplay'' to get info.
- create the logical volume "lvBackupPC" on the entire space of the volume group:
lvcreate -n lvBackupPC -l 100%FREE vgBackupPC
''lvdisplay'' to get info. \\ ''-n'' is to give the name and ''-l'' to deal with the storage space => see the man for more details.
- create an ext4 file system on the logical volum:
mkfs -t ext4 /dev/vgBackupPC/lvBackupPC
- mounting the LVM
* with the name of the LVM
mount -t ext4 /dev/vgBackupPC/lvBackupPC /mount/point
* with the UUID \\ This is a little bit tricky: the UUID to be used is __**NOT**__ the UUID of the LV given by ''lvdisplay''! \\ For the mounting, we have to use the UUID of the file system:
* getting the UUID of the file system:
$ blkid
/dev/sda1: UUID=....
/dev/sda2: UUID=....
/dev/sda3: UUID=....
....
/dev/mapper/vgBackupPC-lvBackupPC: UUID="521489ca-ba67-49e9-a3c6-fa62b0eeeb2f" TYPE="ext4"
* mounting:
mount -t ext4 UUID=521489ca-ba67-49e9-a3c6-fa62b0eeeb2f /mount/point
====== Removing a disk from a LVM ======
In this example we want to remove the disk (= the physical volume more exactly) ''dev/sdb1'' from the LVM.
* Have a look at the general situation:
# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda8 vgBackupPC lvm2 a-- 363,51g 0 363,51g
/dev/sdb1 vgBackupPC lvm2 a-- 931,51g 0 931,51g
* Check if there is enough place on the other physical volume to get sdb1 out of the LVM:
# df -h /mnt/dd_affa/
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
/dev/mapper/vgBackupPC-lvBackupPC 1,3T 287M 1,2T 1% /mnt/dd_affa
So only 287MB are used, so the volume /dev/sda8 can contain all the data.
* Unmount the LVM # umount /mnt/dd_affa
* Reduce the size of the file system, a bit more that would be necessary the remove sdb1 => 1,1TB
# lvresize --resizefs --size -1,1T /dev/mapper/vgBackupPC-lvBackupPC
* Empty sdb1 of the LVM (=transfer the data to the remaining volumes) # pvmove /dev/sdb1
* Remove sdb1 from the LVM: # vgreduce vgBackupPC /dev/sdb1
* Delete the physical volume: # pvremove /dev/sdb1
* Grow the remaining file system of the LVM to the maximal size again: # resize2fs /dev/mapper/vgBackupPC-lvBackupPC