-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathlvm.txt
More file actions
63 lines (49 loc) · 1.87 KB
/
lvm.txt
File metadata and controls
63 lines (49 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#To see partitions
sudo fdisk -l (cat /proc/partitions) (lsblk)
(Let's say you see three devices)
/dev/xvdf, /dev/xvdj, /dev/xvdg
# To reread partitions
partprobe /dev/sdX (or just partprobe)
#If not already installed
sudo apt-get install lvm2
# Create an lvm partition.
gdisk -l /dev/loop0
n
(select size)
L (to lookup the codes)
8e00 (lvm type)
w
#sync
partprobe /dev/xxxx
#Create lvm
pvcreate /dev/xvdf /dev/xvdj /dev/xvdg (physical volume created)
vgcreate ghumVol /dev/xvdf /dev/xvdj /dev/xvdg (volume group created)
lvcreate -l 100%FREE -n devdisks ghumVol (logical volume created)
#Display logical volume
lvdisplay
(or) lvs
#Put filesystem
(Install ext4 if shrinking and growing is needed at a later stage)
(xfs doesn't allow shrinking of filesystem, it can only grow)
mkfs.ext4 /dev/ghumVol/devdisks
#Mount
mkidr /mnt/newvol
sudo mount /dev/ghumVol/devdisks /mnt/newvol
#Note
Just like encrypting partitions create /dev/mappers/xxxx, lvm also creates devices with symlink inside /dev/mappers and also /dev/vgdata/lvdata.
# change properties of filesystems which are already created use tune2fs
tune2fs -L lvdata /dev/vgdata/lvdata
#mounting using Labels in /etc/fstab
LABEL=lvdata /lvmount/point ext4 defaults 0 0
#mounting using UUID in /etc/fstab
#to find out uuid of filesystem, use "blkid" (can use with double quotes or without it)
UUID="xxxxxxxxxxxxxx" /lvmount/point ext4 defaults 0 0
# Resize LVM
pvs, vgs, lvs show size and free space
i) create new partition using gdisk/pdisk (using LVM partition)
ii) vgextend vgdata /dev/newlycreated
(above command detects that newly created partition is not physical volume so it converts it to physical volume and then adds it to vgdata volume group)
iii) lvextend -l +100%FREE -r /dev/vgdata/lvdata (r for resize)
# Shrink
lvreduce -L 800M -r /dev/vgnew/lvnew
(it will ask permission to unmount, then will resize and will mount it again)