--- wikisrc/amazon_ec2.mdwn 2011/02/19 02:42:58 1.21 +++ wikisrc/amazon_ec2.mdwn 2011/02/19 03:42:54 1.22 @@ -105,7 +105,6 @@ Under */mnt/ec2*, edit the files to add [[!template id=filecontent name=etc/rc.conf text=""" rc_configured=YES -hostname=NetBSD-EC2-$(uname -m) sshd=YES # for remote shell access to instance """]] @@ -114,7 +113,7 @@ sshd=YES # for remote shell access to in PermitRootLogin without-password """]] -This file is needed if you want to login via the SSH key pair created previously: +This file is needed if you want to login via the EC2 SSH key pair created previously: [[!template id=filecontent name=etc/rc.d/ec2-init text=""" #!/bin/sh @@ -129,7 +128,10 @@ name="ec2_init" start_cmd="ec2_init" stop_cmd=":" -SSH_KEY_URL="http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key" +METADATA_URL="http://169.254.169.254/latest/meta-data/" +SSH_KEY_URL="public-keys/0/openssh-key" +HOSTNAME_URL="hostname" + SSH_KEY_FILE="/root/.ssh/authorized_keys" ec2_init() @@ -137,23 +139,33 @@ ec2_init() ( umask 022 # fetch the key pair from Amazon Web Services - EC2_SSH_KEY=$(ftp -o - "$SSH_KEY_URL") + EC2_SSH_KEY=$(ftp -o - "${METADATA_URL}${SSH_KEY_URL}") if [ -n "$EC2_SSH_KEY" ]; then # A key pair is associated with this instance, add it # to root 'authorized_keys' file mkdir -p $(dirname "$SSH_KEY_FILE") + touch "$SSH_KEY_FILE" cd $(dirname "$SSH_KEY_FILE") - grep "$EC2_SSH_KEY" "$SSH_KEY_FILE" - if [ $? -eq 0 ]; then - echo "Setting associated SSH key pair." + grep -q "$EC2_SSH_KEY" "$SSH_KEY_FILE" + if [ $? -ne 0 ]; then + echo "Setting EC2 SSH key pair: ${EC2_SSH_KEY##* }" echo "$EC2_SSH_KEY" >> "$SSH_KEY_FILE" fi fi + + # set hostname + HOSTNAME=$(ftp -o - "${METADATA_URL}${HOSTNAME_URL}") + echo "Setting EC2 hostname: ${HOSTNAME}" + echo "$HOSTNAME" > /etc/myname + hostname "$HOSTNAME" ) } + +load_rc_config $name +run_rc_command "$1" """]] Create various files and directories: @@ -161,13 +173,13 @@ Create various files and directories: [[!template id=programlisting text=""" cd /mnt/ec2 # Add proc and kern directories -mkdir proc kern +mkdir grub kern proc # EC2 network configuration, via DHCP echo "dhcp" > etc/ifconfig.xennet0 # Basic fstab entries cat > etc/fstab << EOF /dev/xbd1a / ffs rw 1 1 -/dev/xbd0a /grub ext2 rw 2 2 +/dev/xbd0a /grub ext2fs rw 2 2 kernfs /kern kernfs rw ptyfs /dev/pts ptyfs rw procfs /proc procfs rw