Skip to content

Commit 1e2434d

Browse files
zalonicDaniel Hansson
authored and
Daniel Hansson
committed
Support for Xen Hypervisors (#564)
1 parent 9a77f16 commit 1e2434d

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

static/format-sdb.sh

+25-13
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,27 @@ isDevMounted() { findmnt -rno SOURCE "$1" >/dev/null;} #device only
3030
isPathMounted() { findmnt -rno TARGET "$1" >/dev/null;} #path only
3131
isDevPartOfZFS() { zpool status | grep "$1" >/dev/null;} #device memeber of a zpool
3232

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+
3345
if isPathMounted "/mnt/ncdata"; #Spaces in path names are ok.
3446
then
3547
msg_box "/mnt/ncdata is mounted and need to be unmounted before you can run this script."
3648
exit 1
3749
fi
3850

39-
if isDevMounted "/dev/sdb";
51+
if isDevMounted "/dev/$DEVTYPE";
4052
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."
4254
exit 1
4355
fi
4456

@@ -49,23 +61,23 @@ msg_box "/mnt/ncdata is mounted and need to be unmounted before you can run this
4961
exit 1
5062
fi
5163

52-
if isMounted "/dev/sdb1";
64+
if isMounted "/dev/${DEVTYPE}1";
5365
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."
5567
exit 1
5668
fi
5769

58-
if isDevPartOfZFS "sdb";
70+
if isDevPartOfZFS "$DEVTYPE";
5971
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."
6173
exit 1
6274
fi
6375

6476
# 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" ]
6779
then
68-
msg_box "It seems like /dev/sdb does not exist.
80+
msg_box "It seems like /dev/$DEVTYPE does not exist.
6981
This script requires that you mount a second drive to hold the data.
7082
7183
Please shutdown the server and mount a second drive, then start this script again.
@@ -77,16 +89,16 @@ fi
7789

7890
if lsblk -l -n | grep -v mmcblk | grep disk | awk '{ print $1 }' | tail -1 > /dev/null
7991
then
80-
msg_box "Formatting $SDB when you hit OK.
92+
msg_box "Formatting $DISKTYPE when you hit OK.
8193
8294
*** WARNING: ALL YOUR DATA WILL BE ERASED! ***"
8395
if zpool list | grep "$LABEL_" > /dev/null
8496
then
8597
check_command zpool destroy "$LABEL_"
8698
fi
87-
check_command wipefs -a -f "$SDB"
99+
check_command wipefs -a -f "$DISKTYPE"
88100
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"
90102
check_command zpool set failmode=continue "$LABEL_"
91103
check_command zfs set mountpoint="$MOUNT_" "$LABEL_"
92104
check_command zfs set compression=lz4 "$LABEL_"
@@ -98,7 +110,7 @@ msg_box "Formatting $SDB when you hit OK.
98110
check_command zfs set logbias=latency "$LABEL_"
99111

100112
else
101-
msg_box "It seems like /dev/sdb does not exist.
113+
msg_box "It seems like /dev/$DEVTYPE does not exist.
102114
This script requires that you mount a second drive to hold the data.
103115
104116
Please shutdown the server and mount a second drive, then start this script again.

0 commit comments

Comments
 (0)