@@ -30,15 +30,27 @@ isDevMounted() { findmnt -rno SOURCE "$1" >/dev/null;} #device only
30
30
isPathMounted () { findmnt -rno TARGET " $1 " > /dev/null; } # path only
31
31
isDevPartOfZFS () { zpool status | grep " $1 " > /dev/null; } # device memeber of a zpool
32
32
33
+ # Check what Hypervisor disks are available
34
+ if partprobe /dev/sdb & > /dev/null; # HyperV, VMware, VirtualBox Hypervisors
35
+ then
36
+ DEVTYPE=sdb
37
+ elif partprobe /dev/xvdb & > /dev/null; # Xen Hypervisors
38
+ then
39
+ DEVTYPE=xvdb
40
+ elif partprobe /dev/vdb & > /dev/null; # KVM Hypervisor
41
+ then
42
+ DEVTYPE=vdb
43
+ fi
44
+
33
45
if isPathMounted " /mnt/ncdata" ; # Spaces in path names are ok.
34
46
then
35
47
msg_box " /mnt/ncdata is mounted and need to be unmounted before you can run this script."
36
48
exit 1
37
49
fi
38
50
39
- if isDevMounted " /dev/sdb " ;
51
+ if isDevMounted " /dev/$DEVTYPE " ;
40
52
then
41
- msg_box " /dev/sdb is mounted and need to be unmounted before you can run this script."
53
+ msg_box " /dev/$DEVTYPE is mounted and need to be unmounted before you can run this script."
42
54
exit 1
43
55
fi
44
56
@@ -49,23 +61,23 @@ msg_box "/mnt/ncdata is mounted and need to be unmounted before you can run this
49
61
exit 1
50
62
fi
51
63
52
- if isMounted " /dev/sdb1 " ;
64
+ if isMounted " /dev/${DEVTYPE} 1 " ;
53
65
then
54
- msg_box " /dev/sdb1 is mounted and need to be unmounted before you can run this script."
66
+ msg_box " /dev/${DEVTYPE} 1 is mounted and need to be unmounted before you can run this script."
55
67
exit 1
56
68
fi
57
69
58
- if isDevPartOfZFS " sdb " ;
70
+ if isDevPartOfZFS " $DEVTYPE " ;
59
71
then
60
- msg_box " /dev/sdb is a member of a ZFS pool and needs to be removed from any zpool before you can run this script."
72
+ msg_box " /dev/$DEVTYPE is a member of a ZFS pool and needs to be removed from any zpool before you can run this script."
61
73
exit 1
62
74
fi
63
75
64
76
# Get the name of the drive
65
- SDB =$( fdisk -l | grep sdb | awk ' {print $2}' | cut -d " :" -f1 | head -1)
66
- if [ " $SDB " != " /dev/sdb " ]
77
+ DISKTYPE =$( fdisk -l | grep $DEVTYPE | awk ' {print $2}' | cut -d " :" -f1 | head -1)
78
+ if [ " $DISKTYPE " != " /dev/$DEVTYPE " ]
67
79
then
68
- msg_box " It seems like /dev/sdb does not exist.
80
+ msg_box " It seems like /dev/$DEVTYPE does not exist.
69
81
This script requires that you mount a second drive to hold the data.
70
82
71
83
Please shutdown the server and mount a second drive, then start this script again.
77
89
78
90
if lsblk -l -n | grep -v mmcblk | grep disk | awk ' { print $1 }' | tail -1 > /dev/null
79
91
then
80
- msg_box " Formatting $SDB when you hit OK.
92
+ msg_box " Formatting $DISKTYPE when you hit OK.
81
93
82
94
*** WARNING: ALL YOUR DATA WILL BE ERASED! ***"
83
95
if zpool list | grep " $LABEL_ " > /dev/null
84
96
then
85
97
check_command zpool destroy " $LABEL_ "
86
98
fi
87
- check_command wipefs -a -f " $SDB "
99
+ check_command wipefs -a -f " $DISKTYPE "
88
100
sleep 0.5
89
- check_command zpool create -f -o ashift=12 " $LABEL_ " " $SDB "
101
+ check_command zpool create -f -o ashift=12 " $LABEL_ " " $DISKTYPE "
90
102
check_command zpool set failmode=continue " $LABEL_ "
91
103
check_command zfs set mountpoint=" $MOUNT_ " " $LABEL_ "
92
104
check_command zfs set compression=lz4 " $LABEL_ "
@@ -98,7 +110,7 @@ msg_box "Formatting $SDB when you hit OK.
98
110
check_command zfs set logbias=latency " $LABEL_ "
99
111
100
112
else
101
- msg_box " It seems like /dev/sdb does not exist.
113
+ msg_box " It seems like /dev/$DEVTYPE does not exist.
102
114
This script requires that you mount a second drive to hold the data.
103
115
104
116
Please shutdown the server and mount a second drive, then start this script again.
0 commit comments