Skip to content

Instantly share code, notes, and snippets.

@Cat-Ion
Created September 1, 2012 15:23
Show Gist options
  • Save Cat-Ion/3577047 to your computer and use it in GitHub Desktop.
Save Cat-Ion/3577047 to your computer and use it in GitHub Desktop.
useful stuff

vim

Join paragraphs into single lines

`:g/^./ .,/^$/-1 join`

mdadm

Hotswap a drive

Set variables...

md="/dev/mdX"
sd="/dev/sdYZ"

Make a backup of the partition table. This won't work with GPT!

sfdisk -d $sd > partitiontable

Mark as faulty and remove the partition from the RAID:

mdadm -f $md $sd
mdadm -r $md $sd

Get the scsi data

scsi="$(lsscsi | grep $sd | awk '{print $1;}' | sed -e 's/[][]//g' -e 's/:/ /g')"

Tell Linux to get rid of the device

echo "scsi remove-single-device $scsi" > /proc/scsi/scsi

Physically remove the old drive and insert the new one at this point, then tell Linux to add it:

echo "scsi add-single-device $scsi" > /proc/scsi/scsi

Copy the partition table back:

sfdisk $sd < partitiontable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment