-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-boot
executable file
·38 lines (31 loc) · 1.15 KB
/
check-boot
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
#!/bin/bash
# This script is used for checking a bootable usb sticks by starting a qemu virtual machine.
# It can save your time while preparing a stick because you do not need waiting real hardware reboots.
print_usage () {
echo -e "Usage:\n${0##*/} <device> <b|u>
device - a device which is checked, for example, /dev/sdd. Also it can be image file.
b - for legacy bios boot check
u - for uefi boot check"
}
if [[ "$1" == "--help" || $# != 2 ]]; then
print_usage
exit
fi
if df --output=source,target | grep "$1" 1>&2; then
>&2 echo -e "Warning: Probably a partition of $1 in mounted. You should unmount it to prevent corruption of your fs. Booting refused."
exit 1
fi
if [[ "$2" == "u" ]]; then
if [ -f /etc/os-release ]; then . /etc/os-release; fi
if [[ $ID_LIKE == "ubuntu debian" ]]; then
BIOS_STR="-bios /usr/share/OVMF/OVMF_CODE.fd";
else
BIOS_STR="-bios /usr/share/ovmf/x64/OVMF_CODE.fd"
fi
fi
if [[ "$1" == *.iso ]]; then
MEDIA_STR="-cdrom $1"
else
MEDIA_STR="-drive file=$1,format=raw,index=0,media=disk"
fi
sudo qemu-system-x86_64 $BIOS_STR -m 1G -enable-kvm $MEDIA_STR -display sdl,show-cursor=on