Skip to content

Instantly share code, notes, and snippets.

@chadcatlett
Created January 23, 2019 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadcatlett/b1cda84fe6c14bbb8c328bd005b5b6be to your computer and use it in GitHub Desktop.
Save chadcatlett/b1cda84fe6c14bbb8c328bd005b5b6be to your computer and use it in GitHub Desktop.
# Usage: convert os_device
# Convert an OS device to the corresponding GRUB drive.
# This part is OS-specific.
convert () {
# First, check if the device file exists.
if test -e "$1"; then
:
else
echo "$1: Not found or not a block device." 1>&2
exit 1
fi
# Break the device name into the disk part and the partition part.
case "$host_os" in
linux*)
tmp_disk=`echo "$1" | grep -v '/mapper/control$' |
grep -v '/mapper/[[:alnum:]]\+-[[:alnum:]]\+$' | uniq |
sed -e 's%\([shv]d[a-z]\)[0-9]*$%\1%' \
-e 's%\(d[0-9]*\)p[0-9]*$%\1%' \
-e 's%\(fd[0-9]*\)$%\1%' \
-e 's%/part[0-9]*$%/disc%' \
-e 's%\(c[0-7]d[0-9]*\).*$%\1%' \
-e 's%\(/mapper/[[:alpha:]]\+[[:digit:]]*\)p[[:digit:]]\+$%\1%' \
-e 's%\(/mapper/isw_[[:alpha:]_]\+[[:alpha:]]\+[[:digit:]]\+\)p[[:digit:]]\+$%\1%' \
-e 's%\(/mapper/[[:alpha:]]\+_[[:alpha:]]\+\)[[:digit:]]\+$%\1%' \
-e 's%\(nvme[0-9]*n[0-9]*\)p[0-9]*$%\1%'`
tmp_part=`echo "$1" | grep -v '/mapper/control$' |
grep -v '/mapper/[[:alnum:]]\+-[[:alnum:]]\+$' | uniq |
sed -e 's%.*/[shv]d[a-z]\([0-9]*\)$%\1%' \
-e 's%.*d[0-9]*p%%' \
-e 's%.*/fd[0-9]*$%%' \
-e 's%.*/floppy/[0-9]*$%%' \
-e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
-e 's%.*c[0-7]d[0-9]*%%' \
-e 's%.*/mapper/[[:alpha:]]\+[[:digit:]]*p\([[:digit:]]\+\)$%\1%' \
-e 's%.*/mapper/isw_[[:alpha:]_]\+[[:alpha:]]\+[[:digit:]]\+p\([[:digit:]]\+\)$%\1%' \
-e 's%.*/mapper/[[:alpha:]]\+_[[:alpha:]]\+\([[:digit:]]\+\)$%\1%' \
-e 's%.*/nvme[0-9]*n[0-9]*p\([0-9]*\)%\1%' |
grep -v '.*/mapper/.*'`
<snip>
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment