Skip to content

Instantly share code, notes, and snippets.

@ctompkinson
Last active March 6, 2022 23:08
Show Gist options
  • Save ctompkinson/30f570882af38879b36fc7bffe3d1a60 to your computer and use it in GitHub Desktop.
Save ctompkinson/30f570882af38879b36fc7bffe3d1a60 to your computer and use it in GitHub Desktop.

Revisions

  1. ctompkinson revised this gist Dec 13, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mount_nvme.sh
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,6 @@ if ! $(mount | grep -q /mnt) ; then
    mount /dev/xvdb
    fi
    else
    echo "detected drive already mounted to /mnt, skipping mount˝..."
    echo "detected drive already mounted to /mnt, skipping mount..."
    lsblk | grep mnt
    fi
  2. ctompkinson created this gist Jun 28, 2019.
    36 changes: 36 additions & 0 deletions mount_nvme.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    set -o pipefail
    set -o errtrace
    set -o nounset
    set -o errexit
    set -a

    # Scratch mount is the device which will be mounted on /mnt
    # and generally used for logs, core dumps etc.
    if ! $(mount | grep -q /mnt) ; then
    # Detected NVME drives
    # They do not always have a consistent drive number, this will scan for the drives slot in the hypervisor
    # and mount the correct ones, with sda1 always being the base disk and sdb being the extra, larger, disk
    if lshw | grep nvme &>/dev/null; then
    for blkdev in $(nvme list | awk '/^\/dev/ { print $1 }'); do
    mapping=$(nvme id-ctrl --raw-binary "${blkdev}" | cut -c3073-3104 | tr -s ' ' | sed 's/ $//g')
    if [[ ${mapping} == "sda1" ]]; then
    echo "$blkdev is $mapping skipping..."
    elif [[ ${mapping} == "sdb" ]]; then
    echo "$blkdev is $mapping formatting and mounting..."
    mkfs -t ext4 ${blkdev}
    echo "${blkdev} /mnt ext4 defaults,comment=cloudconfig 0 2" >> /etc/fstab
    mount ${blkdev}
    else
    echo "detected unknown drive letter $blkdev: $mapping. Skipping..."
    fi
    done
    else
    echo "Configuring /dev/xvdb..."
    mkfs -t ext4 /dev/xvdb
    echo "/dev/xvdb /mnt ext4 defaults,comment=cloudconfig 0 2" >> /etc/fstab
    mount /dev/xvdb
    fi
    else
    echo "detected drive already mounted to /mnt, skipping mount˝..."
    lsblk | grep mnt
    fi