-
-
Save digitalresistor/5996243 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/sh | |
# PROVIDE: ec2_fetchkey | |
# REQUIRE: NETWORKING | |
# BEFORE: LOGIN ec2_firstboot | |
# Define ec2_fetchkey_enable=YES in /etc/rc.conf and create /root/firstboot | |
# to enable SSH key fetching when the system next boots. | |
# | |
: ${ec2_fetchkey_enable=NO} | |
. /etc/rc.subr | |
name="ec2_fetchkey" | |
rcvar=`set_rcvar` | |
start_cmd="ec2_fetchkey_run" | |
stop_cmd=":" | |
SSHKEYURL="http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key" | |
eval SSHKEYFILE="~${ec2_fetchkey_user}/.ssh/authorized_keys" | |
ec2_fetchkey_run() | |
{ | |
# If this is the first boot, we need to grab the provided SSH key. | |
if [ -f /root/firstboot ]; then | |
# Grab the provided SSH public key and add it to the | |
# right authorized_keys file to allow it to be used to | |
# log in as the specified user. | |
echo "Fetching SSH public key for ${ec2_fetchkey_user}" | |
mkdir -p `dirname ${SSHKEYFILE}` | |
chmod 700 `dirname ${SSHKEYFILE}` | |
ftp -o ${SSHKEYFILE}.ec2 -a ${SSHKEYURL} >/dev/null | |
if [ -f ${SSHKEYFILE}.ec2 ]; then | |
touch ${SSHKEYFILE} | |
sort -u ${SSHKEYFILE} ${SSHKEYFILE}.ec2 \ | |
> ${SSHKEYFILE}.tmp | |
mv ${SSHKEYFILE}.tmp ${SSHKEYFILE} | |
rm ${SSHKEYFILE}.ec2 | |
else | |
echo "Fetching SSH public key failed!" | |
fi | |
fi | |
} | |
load_rc_config $name | |
run_rc_command "$1" |
This file contains hidden or 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
#!/bin/sh | |
# PROVIDE: ec2_firstboot | |
# REQUIRE: FILESYSTEMS | |
# This script removes the /root/firstboot marker used by ec2_boot and | |
# ec2_ephemeralswap; as such, it doesn't make sense to have it not run. | |
: ${ec2_firstboot_enable=YES} | |
. /etc/rc.subr | |
name="ec2_firstboot" | |
rcvar=`set_rcvar` | |
start_cmd="ec2_firstboot_run" | |
stop_cmd=":" | |
ec2_firstboot_run() | |
{ | |
# The first boot has finished. | |
if [ -f /root/firstboot ]; then | |
rm /root/firstboot | |
fi | |
} | |
load_rc_config $name | |
run_rc_command "$1" |
This file contains hidden or 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
#!/bin/sh | |
# PROVIDE: ec2_loghostkey | |
# REQUIRE: sshd | |
# Define ec2_loghostkey_enable in /etc/rc.conf to enable printing of the | |
# SSH host keys in the EC2 console output format. | |
# | |
: ${ec2_loghostkey_enable=NO} | |
. /etc/rc.subr | |
name="ec2_loghostkey" | |
rcvar=`set_rcvar` | |
start_cmd="ec2_loghostkey_run" | |
stop_cmd=":" | |
ec2_loghostkey_run() | |
{ | |
# Print the SSH host keys in EC2-standard format. | |
echo '#############################################################' | logger -s -t 'ec2' | |
echo '-----BEGIN SSH HOST KEY FINGERPRINTS-----' | logger -s -t 'ec2' | |
for F in /etc/ssh/ssh_host_*key.pub; do | |
ssh-keygen -l -f $F | logger -s -t 'ec2' | |
done | |
echo '-----END SSH HOST KEY FINGERPRINTS-----' | logger -s -t 'ec2' | |
echo '#############################################################' | logger -s -t 'ec2' | |
} | |
load_rc_config $name | |
run_rc_command "$1" |
This file contains hidden or 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
http://dev.n0ll.com/2013/03/openstack-devstack-freebsd-image/ | |
http://www.daemonology.net/freebsd-on-ec2/ | |
# VirtIO drivers are required | |
Drivers: http://people.freebsd.org/~kuriyama/virtio/ | |
# /boot/loader.conf: | |
virtio_load="YES" | |
virtio_pci_load="YES" | |
virtio_blk_load="YES" | |
if_vtnet_load="YES" | |
virtio_balloon_load="YES" | |
boot_multicons="YES" | |
boot_serial="YES" | |
comconsole_speed="115200" | |
console="comconsole,vidconsole" | |
# serial console: edit /etc/ttys | |
# change this: | |
ttyu0 "/usr/libexec/getty std.9600" dialup off secure | |
# to this: | |
ttyu0 "/usr/libexec/getty std.9600" vt100 on secure | |
# Convert /etc/fstab to virtio disk devices: | |
$ sed -i.bak -Ee ‘s|/dev/ada?|/dev/vtbd|’ /etc/fstab | |
# Alias network virtio interfaces as e1000 interfaces, convenience? | |
# /etc/rc.conf: | |
ifconfig_vtnet0_name="em0" | |
ifconfig_em0="DHCP" | |
ec2_fetchkey_enable="YES" | |
ec2_fetchkey_user="root" | |
ec2_loghostkey_enable="YES" | |
sshd_enable="YES" | |
# allow root login with keys via ssh: | |
# /etc/ssh/sshd_config | |
PermitRootLogin without-password | |
# add ec2_fetchkey, ec2_loghostkey, and ec2_firstboot files to /etc/rc.d | |
# mark image for first boot (/etc/rc.d/ec2_* scripts) | |
$ touch /root/firstboot | |
# Convert a vmdk to a qcow2 image for upload to Openstack | |
$ qemu-img convert -O qcow2 FreeBSD_9.1-disk1.vmdk FreeBSD_9.1-disk1.qcow2 | |
# Start KVM with the image locally for testing | |
$ sudo qemu-system-x86_64 -drive file=FreeBSD_9.1-disk1.qcow2,if=virtio -net nic,model=virtio -net tap -k en-us | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment