项目作者: ajacoutot

项目描述 :
AWS OpenBSD image builder (AMI) and cloud-init replacement
高级语言: Shell
项目地址: git://github.com/ajacoutot/aws-openbsd.git
创建时间: 2015-12-12T20:22:54Z
项目社区:https://github.com/ajacoutot/aws-openbsd

开源协议:

下载


AWS-OpenBSD

AWS playground for OpenBSD kids.
Running whatever is in this repo will propably end up destroying a kitten factory.

Prerequisites for obsd-img-builder.sh (OpenBSD AMI builder)

  • shell access to OpenBSD current >6.5 with vmm(4) support and Internet access
  • 3.5GB of free space in ${TMPDIR}
  • awscli and vmdktool packages installed
  • AWS IAM user with enough permissions (AmazonEC2FullAccess, AmazonS3FullAccess, IAMFullAccess)
    • AWS environment variables properly set (when not use root’s awscli configuration):
      • AWS_CONFIG_FILE
      • AWS_DEFAULT_PROFILE (when not using the default profile)
      • AWS_SHARED_CREDENTIALS_FILE

Script usage

  1. usage: obsd-img-builder.sh
  2. -a "architecture" -- default to "amd64"
  3. -d "description" -- AMI description; defaults to "openbsd-$release-$timestamp"
  4. -i "path to RAW image" -- use image at path instead of creating one
  5. -m "install mirror" -- defaults to installurl(5) or "https://cdn.openbsd.org/pub/OpenBSD"
  6. -n -- only create a RAW image (don't convert to an AMI nor push to AWS)
  7. -r "release" -- e.g "6.5"; default to "snapshots"
  8. -s "image size in GB" -- default to "12"

TODO

  • arm64 support
  • MP support

Misc

While a newly built image/AMI will contain a randomized kernel, it is advised
to add user-data at first boot that will reboot the instance once the first
randomization is done. This is so that every instance will indeed run a
different relinked kernel.

ENI hotplug

  1. # cat <<-'EOF' >/etc/hotplug/attach
  2. #!/bin/sh
  3. case $1 in
  4. 3) echo "!/sbin/dhclient -i routers $2" >/etc/hostname.$2
  5. /bin/sh /etc/netstart $i
  6. ;;
  7. esac
  8. EOF
  9. # chmod 0555 /etc/hotplug/attach
  10. # rcctl enable hotplugd && rcctl start hotplugd

Build sample output

  1. # export AWS_CONFIG_FILE=/home/myuser/.aws/config
  2. # export AWS_DEFAULT_PROFILE=builder
  3. # export AWS_SHARED_CREDENTIALS_FILE=/home/myuser/.aws/credentials
  1. # ./obsd-img-builder.sh
  2. ================================================================================
  3. | creating install.site
  4. ================================================================================
  5. ================================================================================
  6. | creating sd1 and storing siteXX.tgz
  7. ================================================================================
  8. vmctl: raw imagefile created
  9. Writing MBR at offset 0.
  10. Label editor (enter '?' for help at any prompt)
  11. > offset: [128] size: [2096972] FS type: [4.2BSD] > > No label changes.
  12. /dev/rvnd0a: 1023.9MB in 2096960 sectors of 512 bytes
  13. 6 cylinder groups of 202.47MB, 12958 blocks, 25984 inodes each
  14. super-block backups (for fsck -b #) at:
  15. 32, 414688, 829344, 1244000, 1658656, 2073312,
  16. ================================================================================
  17. | creating auto_install.conf
  18. ================================================================================
  19. ================================================================================
  20. | creating modified bsd.rd for autoinstall
  21. ================================================================================
  22. SHA256.sig 100% |******************************************************| 2141 00:00
  23. bsd.rd 100% |******************************************************| 9971 KB 00:01
  24. checking signature: /etc/signify/openbsd-65-base.pub
  25. ================================================================================
  26. | starting autoinstall inside vmm(4)
  27. ================================================================================
  28. vmctl: raw imagefile created
  29. Connected to /dev/ttyp5 (speed 115200)
  30. Copyright (c) 1982, 1986, 1989, 1991, 1993
  31. The Regents of the University of California. All rights reserved.
  32. Copyright (c) 1995-2019 OpenBSD. All rights reserved. https://www.OpenBSD.org
  33. OpenBSD 6.5-beta (RAMDISK_CD) #783: Thu Mar 21 21:42:12 MDT 2019
  34. deraadt@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/RAMDISK_CD
  35. real mem = 520093696 (496MB)
  36. avail mem = 500412416 (477MB)
  37. mainbus0 at root
  38. bios0 at mainbus0
  39. acpi at bios0 not configured
  40. cpu0 at mainbus0: (uniprocessor)
  41. cpu0: Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz, 2295.72 MHz, 06-3d-04
  42. cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,SSE3,PCLMUL,SSSE3,FMA3,CX16,SSE4.1,SSE4.2,MOVBE,POPCNT,AES,XSAVE,AVX,F16C,RDRAND,HV,NXE,PAGE1GB,LONG,LAHF,ABM,3DNOWP,ITSC,FSGSBASE,BMI1,AVX2,SMEP,BMI2,ERMS,RDSEED,ADX,SMAP,MELTDOWN
  43. cpu0: 256KB 64b/line 8-way L2 cache
  44. pvbus0 at mainbus0: OpenBSD
  45. pci0 at mainbus0 bus 0
  46. pchb0 at pci0 dev 0 function 0 "OpenBSD VMM Host" rev 0x00
  47. virtio0 at pci0 dev 1 function 0 "Qumranet Virtio RNG" rev 0x00
  48. viornd0 at virtio0
  49. virtio0: irq 3
  50. virtio1 at pci0 dev 2 function 0 "Qumranet Virtio Network" rev 0x00
  51. vio0 at virtio1: address fe:e1:bb:d1:44:83
  52. virtio1: irq 5
  53. virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Storage" rev 0x00
  54. vioblk0 at virtio2
  55. scsibus0 at vioblk0: 2 targets
  56. sd0 at scsibus0 targ 0 lun 0: <VirtIO, Block Device, > SCSI3 0/direct fixed
  57. sd0: 12288MB, 512 bytes/sector, 25165824 sectors
  58. virtio2: irq 6
  59. virtio3 at pci0 dev 4 function 0 "Qumranet Virtio Storage" rev 0x00
  60. vioblk1 at virtio3
  61. scsibus1 at vioblk1: 2 targets
  62. sd1 at scsibus1 targ 0 lun 0: <VirtIO, Block Device, > SCSI3 0/direct fixed
  63. sd1: 1024MB, 512 bytes/sector, 2097152 sectors
  64. virtio3: irq 7
  65. virtio4 at pci0 dev 5 function 0 "OpenBSD VMM Control" rev 0x00
  66. vmmci0 at virtio4
  67. virtio4: irq 9
  68. isa0 at mainbus0
  69. com0 at isa0 port 0x3f8/8 irq 4: ns16450, no fifo
  70. com0: console
  71. softraid0 at root
  72. scsibus2 at softraid0: 256 targets
  73. root on rd0a swap on rd0b dump on rd0b
  74. erase ^?, werase ^W, kill ^U, intr ^C, status ^T
  75. Welcome to the OpenBSD/amd64 6.5 installation program.
  76. Starting non-interactive mode in 5 seconds...
  77. (I)nstall, (U)pgrade, (A)utoinstall or (S)hell? waiting for vm openbsd-current-amd64-20190322T091544Z:
  78. Performing non-interactive install...
  79. Terminal type? [vt220] vt220
  80. System hostname? (short form, e.g. 'foo') openbsd
  81. Available network interfaces are: vio0 vlan0.
  82. Which network interface do you wish to configure? (or 'done') [vio0] vio0
  83. IPv4 address for vio0? (or 'dhcp' or 'none') [dhcp] dhcp
  84. IPv6 address for vio0? (or 'autoconf' or 'none') [none] none
  85. Available network interfaces are: vio0 vlan0.
  86. Which network interface do you wish to configure? (or 'done') [done] done
  87. DNS domain name? (e.g. 'example.com') [my.domain] my.domain
  88. Using DNS nameservers at 100.64.11.2
  89. Password for root account? <provided>
  90. Public ssh key for root account? [none] none
  91. Start sshd(8) by default? [yes] yes
  92. Change the default console to com0? [yes] yes
  93. Available speeds are: 9600 19200 38400 57600 115200.
  94. Which speed should com0 use? (or 'done') [115200] 115200
  95. Setup a user? (enter a lower-case loginname, or 'no') [no] ec2-user
  96. Full name for user ec2-user? [ec2-user] EC2 Default User
  97. Password for user ec2-user? <provided>
  98. Public ssh key for user ec2-user [none] none
  99. WARNING: root is targeted by password guessing attacks, pubkeys are safer.
  100. Allow root ssh login? (yes, no, prohibit-password) [no] no
  101. What timezone are you in? ('?' for list) [UTC] UTC
  102. Available disks are: sd0 sd1.
  103. Which disk is the root disk? ('?' for details) [sd0] sd0
  104. No valid MBR or GPT.
  105. Use (W)hole disk MBR, whole disk (G)PT or (E)dit? [whole] whole
  106. Setting OpenBSD MBR partition to whole sd0...done.
  107. URL to autopartitioning template for disklabel? [none] none
  108. The auto-allocated layout for sd0 is:
  109. # size offset fstype [fsize bsize cpg]
  110. a: 255.1M 64 4.2BSD 2048 16384 1 # /
  111. b: 290.2M 522496 swap
  112. c: 12288.0M 0 unused
  113. d: 288.2M 1116832 4.2BSD 2048 16384 1 # /tmp
  114. e: 353.2M 1706976 4.2BSD 2048 16384 1 # /var
  115. f: 1005.1M 2430432 4.2BSD 2048 16384 1 # /usr
  116. g: 447.0M 4488864 4.2BSD 2048 16384 1 # /usr/X11R6
  117. h: 1339.3M 5404416 4.2BSD 2048 16384 1 # /usr/local
  118. i: 1342.0M 8147296 4.2BSD 2048 16384 1 # /usr/src
  119. j: 5204.1M 10895776 4.2BSD 2048 16384 1 # /usr/obj
  120. k: 1759.8M 21553728 4.2BSD 2048 16384 1 # /home
  121. Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout? [a] a
  122. newfs: reduced number of fragments per cylinder group from 32648 to 32512 to enlarge last cylinder group
  123. /dev/rsd0a: 255.1MB in 522432 sectors of 512 bytes
  124. 5 cylinder groups of 63.50MB, 4064 blocks, 8192 inodes each
  125. /dev/rsd0k: 1759.8MB in 3604032 sectors of 512 bytes
  126. 9 cylinder groups of 202.47MB, 12958 blocks, 25984 inodes each
  127. newfs: reduced number of fragments per cylinder group from 36880 to 36728 to enlarge last cylinder group
  128. /dev/rsd0d: 288.2MB in 590144 sectors of 512 bytes
  129. 5 cylinder groups of 71.73MB, 4591 blocks, 9216 inodes each
  130. /dev/rsd0f: 1005.1MB in 2058432 sectors of 512 bytes
  131. 5 cylinder groups of 202.47MB, 12958 blocks, 25984 inodes each
  132. newfs: reduced number of fragments per cylinder group from 57216 to 56992 to enlarge last cylinder group
  133. /dev/rsd0g: 447.0MB in 915552 sectors of 512 bytes
  134. 5 cylinder groups of 111.31MB, 7124 blocks, 14336 inodes each
  135. /dev/rsd0h: 1339.3MB in 2742880 sectors of 512 bytes
  136. 7 cylinder groups of 202.47MB, 12958 blocks, 25984 inodes each
  137. /dev/rsd0j: 5204.1MB in 10657952 sectors of 512 bytes
  138. 26 cylinder groups of 202.47MB, 12958 blocks, 25984 inodes each
  139. /dev/rsd0i: 1342.0MB in 2748480 sectors of 512 bytes
  140. 7 cylinder groups of 202.47MB, 12958 blocks, 25984 inodes each
  141. /dev/rsd0e: 353.2MB in 723456 sectors of 512 bytes
  142. 4 cylinder groups of 88.31MB, 5652 blocks, 11392 inodes each
  143. Available disks are: sd1.
  144. Which disk do you wish to initialize? (or 'done') [done] done
  145. /dev/sd0a (9861f4b2a79df4f4.a) on /mnt type ffs (rw, asynchronous, local)
  146. /dev/sd0k (9861f4b2a79df4f4.k) on /mnt/home type ffs (rw, asynchronous, local, nodev, nosuid)
  147. /dev/sd0d (9861f4b2a79df4f4.d) on /mnt/tmp type ffs (rw, asynchronous, local, nodev, nosuid)
  148. /dev/sd0f (9861f4b2a79df4f4.f) on /mnt/usr type ffs (rw, asynchronous, local, nodev)
  149. /dev/sd0g (9861f4b2a79df4f4.g) on /mnt/usr/X11R6 type ffs (rw, asynchronous, local, nodev)
  150. /dev/sd0h (9861f4b2a79df4f4.h) on /mnt/usr/local type ffs (rw, asynchronous, local, nodev)
  151. /dev/sd0j (9861f4b2a79df4f4.j) on /mnt/usr/obj type ffs (rw, asynchronous, local, nodev, nosuid)
  152. /dev/sd0i (9861f4b2a79df4f4.i) on /mnt/usr/src type ffs (rw, asynchronous, local, nodev, nosuid)
  153. /dev/sd0e (9861f4b2a79df4f4.e) on /mnt/var type ffs (rw, asynchronous, local, nodev, nosuid)
  154. Let's install the sets!
  155. Location of sets? (disk http or 'done') [disk] http
  156. HTTP proxy URL? (e.g. 'http://proxy:8080', or 'none') [none] none
  157. HTTP Server? (hostname, list#, 'done' or '?') [cdn.openbsd.org] cdn.openbsd.org
  158. Server directory? [pub/OpenBSD/snapshots/amd64] pub/OpenBSD/snapshots/amd64
  159. Select sets by entering a set name, a file name pattern or 'all'. De-select
  160. sets by prepending a '-', e.g.: '-game*'. Selected sets are labelled '[X]'.
  161. [X] bsd [X] comp65.tgz [X] xbase65.tgz [X] xserv65.tgz
  162. [X] bsd.rd [X] man65.tgz [X] xshare65.tgz
  163. [X] base65.tgz [X] game65.tgz [X] xfont65.tgz
  164. Set name(s)? (or 'abort' or 'done') [done] done
  165. Get/Verify SHA256.sig 100% |**************************| 2141 00:00
  166. Signature Verified
  167. Get/Verify bsd 100% |**************************| 15492 KB 00:02
  168. Get/Verify bsd.rd 100% |**************************| 9971 KB 00:01
  169. Get/Verify base65.tgz 100% |**************************| 191 MB 00:27
  170. Get/Verify comp65.tgz 100% |**************************| 93001 KB 00:12
  171. Get/Verify man65.tgz 100% |**************************| 7383 KB 00:01
  172. Get/Verify game65.tgz 100% |**************************| 2740 KB 00:00
  173. Get/Verify xbase65.tgz 100% |**************************| 20664 KB 00:03
  174. Get/Verify xshare65.tgz 100% |**************************| 4448 KB 00:01
  175. Get/Verify xfont65.tgz 100% |**************************| 39342 KB 00:05
  176. Get/Verify xserv65.tgz 100% |**************************| 16684 KB 00:02
  177. Installing bsd 100% |**************************| 15492 KB 00:00
  178. Installing bsd.rd 100% |**************************| 9971 KB 00:00
  179. Installing base65.tgz 100% |**************************| 191 MB 00:18
  180. Extracting etc.tgz 100% |**************************| 256 KB 00:00
  181. Installing comp65.tgz 100% |**************************| 93001 KB 00:14
  182. Installing man65.tgz 100% |**************************| 7383 KB 00:01
  183. Installing game65.tgz 100% |**************************| 2740 KB 00:00
  184. Installing xbase65.tgz 100% |**************************| 20664 KB 00:02
  185. Extracting xetc.tgz 100% |**************************| 6935 00:00
  186. Installing xshare65.tgz 100% |**************************| 4448 KB 00:01
  187. Installing xfont65.tgz 100% |**************************| 39342 KB 00:03
  188. Installing xserv65.tgz 100% |**************************| 16684 KB 00:01
  189. Location of sets? (disk http or 'done') [done] disk
  190. Is the disk partition already mounted? [yes] no
  191. Available disks are: sd0 sd1.
  192. Which disk contains the install media? (or 'done') [sd1] sd1
  193. Pathname to the sets? (or 'done') [6.5/amd64] 6.5/amd64
  194. INSTALL.amd64 not found. Use sets found here anyway? [no] yes
  195. Select sets by entering a set name, a file name pattern or 'all'. De-select
  196. sets by prepending a '-', e.g.: '-game*'. Selected sets are labelled '[X]'.
  197. [ ] site65.tgz
  198. Set name(s)? (or 'abort' or 'done') [done] site*
  199. [X] site65.tgz
  200. Set name(s)? (or 'abort' or 'done') [done] done
  201. Directory does not contain SHA256.sig. Continue without verification? [no] yes
  202. Installing site65.tgz 100% |**************************| 372 00:00
  203. Location of sets? (disk http or 'done') [done] done
  204. Saving configuration files... done.
  205. Making all device nodes... done.
  206. Relinking to create unique kernel... done.
  207. CONGRATULATIONS! Your OpenBSD install has been successfully completed!
  208. When you login to your new system the first time, please read your mail
  209. using the 'mail' command.
  210. syncing disks... done
  211. vmmci0: powerdown
  212. rebooting...
  213. terminated vm 11
  214. stopping vm openbsd-current-amd64-20190322T091544Z: forced to terminate vm 11
  215. [SIGTERM]
  216. ================================================================================
  217. | creating IAM role
  218. ================================================================================
  219. {
  220. "Role": {
  221. "AssumeRolePolicyDocument": {
  222. "Version": "2012-10-17",
  223. "Statement": [
  224. {
  225. "Action": "sts:AssumeRole",
  226. "Effect": "Allow",
  227. "Condition": {
  228. "StringEquals": {
  229. "sts:Externalid": "vmimport"
  230. }
  231. },
  232. "Principal": {
  233. "Service": "vmie.amazonaws.com"
  234. }
  235. }
  236. ]
  237. },
  238. "RoleId": "AROAJ724UC5U3JGJ5EZ7C",
  239. "CreateDate": "2019-03-22T09:18:45Z",
  240. "RoleName": "openbsd-current-amd64-20190322T091544Z",
  241. "Path": "/",
  242. "Arn": "arn:aws:iam::360116137065:role/openbsd-current-amd64-20190322T091544Z"
  243. }
  244. }
  245. ================================================================================
  246. | converting image to stream-based VMDK
  247. ================================================================================
  248. ================================================================================
  249. | uploading image to S3
  250. ================================================================================
  251. {
  252. "Location": "http://openbsd-current-amd64-20190322t091544z-29476.s3.amazonaws.com/"
  253. }
  254. upload: ./openbsd-current-amd64-20190322T091544Z.vmdk to s3://openbsd-current-amd64-20190322t091544z-29476/openbsd-current-amd64-20190322T091544Z.vmdk
  255. ================================================================================
  256. | converting VMDK to snapshot
  257. ================================================================================
  258. Progress: None%
  259. ================================================================================
  260. | removing bucket openbsd-current-amd64-20190322t091544z-29476
  261. ================================================================================
  262. delete: s3://openbsd-current-amd64-20190322t091544z-29476/openbsd-current-amd64-20190322T091544Z.vmdk
  263. remove_bucket: openbsd-current-amd64-20190322t091544z-29476
  264. ================================================================================
  265. | registering AMI
  266. ================================================================================
  267. {
  268. "ImageId": "ami-0d1cf7bb6f969621f"
  269. }
  270. ================================================================================
  271. | removing IAM role
  272. ================================================================================
  273. ================================================================================
  274. | work directory: /tmp/aws-ami.p0MJZxjBcr
  275. ================================================================================

Instanciate the AMI and connect to it using SSH:

  1. $ ssh ec2-user@${IPADDR}