Skip to content

Instantly share code, notes, and snippets.

@andreas-wilm andreas-wilm/nvmraid.sh
Last active Jan 23, 2019

Embed
What would you like to do?
Combine all NVMs on AWS instance (e.g. i3) as raid0 and mount as data
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/raid-config.html
nvmes=$(sudo lsblk | awk '/^nvme/ {printf "/dev/%s ", $1}')
sudo mdadm --create --verbose /dev/md0 --level=0 --name=my_raid --raid-devices=$(echo $nvmes | wc -w) $nvmes
sleep 10# crutch
sudo mkfs.ext4 -L my_raid /dev/md0
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.conf
sudo dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)
sudo mkdir /data
sudo mount LABEL=my_raid /data
sudo chown ec2-user:ec2-user /data/
@andreas-wilm

This comment has been minimized.

Copy link
Owner Author

andreas-wilm commented Nov 2, 2018

  • Careful not to use root dev NVMes
  • The sleep 10 line is missing a semicolon
@andreas-wilm

This comment has been minimized.

Copy link
Owner Author

andreas-wilm commented Jan 23, 2019

Slightly better approach to get all unused disks:

lsblk -J | grep '"type": "disk"' | grep '"mountpoint": null' | grep -o '"name": [^,]*' | cut -f4 -d'"'

Output lsblk in json, get unmounted disks (ignore parts), spit out block device name (without /dev/)

@andreas-wilm

This comment has been minimized.

Copy link
Owner Author

andreas-wilm commented Jan 23, 2019

Python code to determine unused blockdevices (fixing above issues):

import json
import subprocess

res = subprocess.check_output(['lsblk', '-J'], stderr=subprocess.STDOUT)
jd = json.loads(res.decode())
for bd in jd['blockdevices']:
    if not bd['mountpoint'] and not 'children' in bd:
        print("/dev/{}".format(bd["name"]))
@andreas-wilm

This comment has been minimized.

Copy link
Owner Author

andreas-wilm commented Jan 23, 2019

Full Python version at rpd-aws-tools.git/batch-ami/raid0.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.