-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
diskcom
executable file
·153 lines (143 loc) · 3.88 KB
/
diskcom
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
# nvme-cli for ssd/nvme
# openseachest support
# mdadm
check="iselect cfdisk partprobe pvs lvs vgs disktype file badblocks screen lvmdiskscan"
for a in $check; do
if ! which "$a" >/dev/null; then
echo "$a not found, please install it."
exit 1
fi
done
# menu entries to setup md raid
# menu entries to setup lvm
# menu entries to create installer from img links
# http://lemon.debian.net/debian-unofficial-kfreebsd-amd64-NETINST-1.iso
# https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso
# https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.10.0-amd64-netinst.iso
# https://reactos.org/download/
# https://www.microsoft.com/en-us/software-download/windows10ISO
# https://github.com/corpnewt/gibMacOS
# http://dosdude1.com/catalina/
# menu entries to dump partition table (sfdisk)
# menu entries to dump disk image (whole disks only)
# integrate external file into script using say ##content
menu=diskcom.mainmenu
name="DISK COMMANDER"
while (sleep 0.1); do
dskro=$(screen -ls |grep DSKRO |wc -l)
dskrw=$(screen -ls |grep DSKRW |wc -l)
r=$(cat $0|grep ^## |sed s,^##,,g |sed s,PART,$pt,g |sed s,DISK,$d,g | sed s,DSKRO,$dskro,g | sed s,DSKRW,$dskrw,g | iselect -n "$name" -p 3)
case $r in
slct)
d=`echo -e "Select disk.\n\n$(ls -1 /dev/mmcblk? /dev/nvme?n? /dev/sd? /dev/md* 2>/dev/null | sed "s,.*,<s>&,g")" | iselect -p3 -n "$name"`
;;
s-pt)
pt=`echo -e "Select partition.\n\n$(ls -1 /dev/sd??* /dev/md* 2>/dev/null | sed "s,.*,<s>&,g")" | iselect -p3 -n "$name"`
;;
m-slct)
q="Select multiple disks with space.\n"
selectables=$(ls /dev/sd? | sed -E "s,/dev,\n<s>&,g")
md="`(echo -e $q;echo \"$selectables\") |iselect -m -p3`"
#echo $md
#read
;;
c-raid)
rl=`echo -e "Select RAID level.\n\n0\n1\n4\n5\n6\n10" |iselect -a -p3 -n "$name"`
echo $rl
read
;;
read)
partprobe
read -p "PRESS ENTER TO RETURN TO MENU"
;;
crea)
cfdisk ${d}
;;
lvm2)
lvmdiskscan
echo
pvs
echo
vgs
echo
lvs
read
;;
md)
if [ -f /proc/mdstat ]; then
echo MD found.
echo
cat /proc/mdstat
echo
mdadm --detail $d
else
echo No MD found.
fi
read
;;
info)
clear
disktype ${d}*
echo
file -s ${d}*
read
;;
bbro)
if [ "${d}x" != x ]; then
read -p "PRESS ENTER TO RUN badblocks RO on $d"
screen -dmS DSKRO$(basename ${d}) badblocks -sv $d
else
read -p "SELECT DISK FIRST"
fi
;;
bbrw)
if [ "${d}x" != x ]; then
read -p "PRESS ENTER TO RUN badblocks RW on $d"
screen -dmS DSKRW$(basename ${d}) badblocks -nsv $d
else
read -p "SELECT DISK FIRST"
fi
;;
mkfs)
ls -1 /usr/*/mkfs.* /*bin/mkfs.* | while read a; do
echo $(whatis `basename $a`)
#printf "%-12s %s\n" $(whatis `basename $a`)
done
read
;;
mnts)
cat /etc/fstab |grep -v ^# |column -t
read
;;
exit)
exit;
;;
esac
done
exit 0
##Main Menu.
##
##<s:slct>Select disk to operate on. [DISK]
##<s:crea>Create partitions on disk [DISK].
##<s:s-pt>Select partition to operate on. [PART]
##<s:c-fs>Create filesystem on partition [PART].
##<s:read>Re-read partition table changes.
##
##<s:m-slct>Select multiple disks to operate on. [MDSK]
##<s:c-raid>Create RAID with multiple disks. [MDSK]
##
##<s:mkfs>List available filesystems.
##<s:mnts>List configured filesystems with mount points (/etc/fstab).
##<s:info>Information about disk [DISK].
##<s:lvm2>Information about LVM2 (Logical Volume Manager).
##<s:md>Information about Linux MD (multi disk) arrays.
##
##<s:bbro>Run RO (read only) check on disk [DISK]. [DSKRO]
##<s:bbrw>Run RW (read write) check on disk [DISK]. [DSKRW]
##
##Convert filesystem live between jfs/xfs/reiser/ext2/ext3/ext4 using fstransform.
##Convert filesystem ntfs2btrfs using ntfs2btrfs.
##Defrag filesystem. https://github.com/vbmacher/defrag
##
##<s:exit>Exit.