-
Notifications
You must be signed in to change notification settings - Fork 0
/
lvm.py
102 lines (100 loc) · 2.59 KB
/
lvm.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import os
os.system("clear")
os.system("tput setaf 3")
print("\t\t\tLocal > LVM")
os.system("tput setaf 7")
while True:
os.system("tput setaf 4")
print("""
1.Full configure LVM
2.create PV
3.PV display
4.create VG
5.VG display
6.create LV
7.increase LVM size
8.Mount
9.decrease LVM size
10.Back
""")
os.system("tput setaf 7")
cmd=int(input("Enter your choice \t"))
if cmd==1:
hdd=input("Enter name of Partition\t")
print("pvcreating...\n ")
cm="pvcreate {}".format(hdd)
os.system(cm)
vgname=input("Create name of vgname\t")
print("vgcreating...\n")
cm="vgcreate {} {}".format(vgname,hdd)
os.system(cm)
lvname=input("create name of lvname\t")
lvsize=input("size of lv *in G,M\t")
print("lvcreating...\n")
cm="lvcreate --size {} --name {} {}".format(lvsize,lvname,vgname)
os.system(cm)
print("formating... \n")
cm="mkfs.ext4 /dev/{}/{} ".format(vgname,lvname)
os.system(cm)
print("\n\n Done ")
elif cmd==2:
hdd=input("Enter name of Partition\t")
print("pvcreating...\n")
cm="pvcreate {}".format(hdd)
os.system(cm)
print("\n\n Done ")
elif cmd==3:
os.system("pvdisplay")
elif cmd==4:
hdd=input("Enter name of PV Partition\t")
vgname=input("Create name of vgname\t")
print("vgcreating...\n")
cm="vgcreate {} {}".format(vgname,hdd)
os.system(cm)
print("\n\n Done ")
elif cmd==5:
os.system("vgdisplay")
elif cmd==6:
vgname=input("Enter name of Vg\t")
lvname=input("create name of lvname\t")
lvsize=input("size of lv *in G,M\t")
print("lvcreating...\n")
cm="lvcreate --size {} --name {} {}".format(lvsize,lvname,vgname)
os.system(cm)
print("\n\n Done ")
elif cmd==7:
lvexsize=input("Enter Lv extend size *in G,M\t")
vgname=input("Enter name of VG\t")
lvname=input("Enter name of LV\t")
cm="lvextend --size {} /dev/{}/{} ".format(lvexsize,vgname,lvname)
os.system(cm)
cm="resize2fs /dev/{}/{}".format(vgname,lvname)
os.system(cm)
print("\n\n Done ")
elif cmd==8:
partition=input("Enter mount device name\t")
folder=input("Enter folder name\t")
cm="mount {} {} ".format(partition,folder)
os.system(cm)
print("\n\n Done ")
elif cmd==9:
folder=input("Enter Mounted folder name")
lv=input("Enter LVM name")
cm = "umount {}".format(folder)
os.system(cm)
cm = "e2fsck -f {}".format(lv)
os.system(cm)
resize=input("Enter new size *in G,M")
cm = "resize2fs {} {}".format(lv,resize)
os.system(cm)
cm = "lvreduce -L {} {}".format(resize,lv)
os.system(cm)
elif cmd==10:
exit()
else :
print("Not found")
input()
os.system("clear")
os.system("tput setaf 3")
print("\t\t\tLocal > docker")
os.system("tput setaf 7")