Skip to content

Instantly share code, notes, and snippets.

@smalot
Created September 25, 2013 09:31
Show Gist options
  • Save smalot/6697253 to your computer and use it in GitHub Desktop.
Save smalot/6697253 to your computer and use it in GitHub Desktop.
Script found on dedibox rescue mode to amount all DD. Could be useful
#!/bin/sh
if [ $( whoami ) != "root" ]; then
echo "Ce script doit être exécuter en tant que root."
exit 1
fi
is_inlist () {
OIFS=$IFS
IFS=:
for i in $2; do
if [ "$i" -a "$1" = "$i" ]; then
IFS=$OIFS
echo 1
return
fi
done
IFS=$OIFS
echo 0
}
is_swap () {
magic=$(/bin/dd if="$1" bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null)
if [ "$magic" = "SWAPSPACE2" -o "$magic" = "SWAP-SPACE" ]; then
echo 1
return
fi
echo 0
}
mdlist=""
rdlist=""
sdlist=""
for mddev in $( ls /dev/md[0-9]* ); do
mdlist="${mdlist} ${mddev}"
for line in $( mdadm --detail $mddev ); do
rddev=$( echo $line | awk '/\/dev\/sd/ {print $1}' )
if [ -n "$rddev" ]; then
rdlist="${rddev}:${rdlist}"
fi
done
done
for sddev in $( ls /dev/sd[a-z][0-9]* ); do
if [ $( is_inlist $sddev $rdlist ) -eq 0 ]; then
if [ $( is_swap $sddev ) -eq 0 ]; then
sdlist="${sdlist} ${sddev}"
else
echo "$sddev ressemble à un espace de SWAP et ne sera donc pas monté."
fi
else
echo "$sddev fait parti d'un chaînage RAID et ne sera donc pas monté."
fi
done
for part in ${mdlist} ${sdlist}; do
mkdir -p /mnt/${part#/dev/} 2>/dev/null
mount -t auto ${part} /mnt/${part#/dev/} 2>/dev/null
if [ $? -eq 0 ]; then
echo "${part} vient d'être monté dans /mnt/${part#/dev/}"
else
echo "${part} ne peut être monté."
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment