Created
October 1, 2009 02:54
-
-
Save dehowell/198672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fix_networking.sh | |
# | |
# This script automates the steps outlined at: | |
# | |
# http://weblog.jamisbuck.org/2008/8/15/cloning-ubuntu-hardy-image-in-vmware-fusion | |
# | |
# for fixing the networking on a copied Ubuntu VMWare image. | |
usage() { | |
cat <<EOF | |
$0 [new hostname] | |
Changes the hostname on the guest OS and fixes the udev rule screwed up by | |
VMWare assigning a new MAC address to the copied image. | |
EOF | |
} | |
if [ -n "$1" ]; then | |
NEW_NAME=$1 | |
OLD_NAME=`hostname | sed 's/\([\.]*\)\..*/\1/'` | |
if [ $NEW_NAME = $OLD_NAME ]; then | |
echo "Warning: new name identical to current hostname." | |
fi | |
else | |
usage | |
exit | |
fi | |
echo "Change current hostname." | |
sudo hostname $NEW_NAME | |
echo "Changing hostname in /etc/hostname and /etc/hosts" | |
sudo sed -i -e"s/$OLD_NAME/$NEW_NAME/" /etc/hostname | |
sudo sed -i -e"s/$OLD_NAME/$NEW_NAME/g" /etc/hosts | |
echo "Fixing udev rule for eth0." | |
UDEV_RULES=70-persistent-net.rules | |
# Ubuntu will just add a new rule when it detects the new MAC address. | |
# I'm just making a backup of the original udev file and replacing it with | |
# the last rule, making the substitution eth1 -> eth0. | |
sudo mv /etc/udev/rules.d/$UDEV_RULES /tmp/$UDEV_RULES | |
sudo sh -c "grep '^SUBSYSTEM' /tmp/$UDEV_RULES | tail -n 1 | sed 's/eth1/eth0/' > /etc/udev/rules.d/$UDEV_RULES" | |
echo "Please restart ('sudo reboot')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment