Skip to content

Instantly share code, notes, and snippets.

@mgerdts
Last active October 8, 2018 14:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mgerdts/918a6e20384c243e5363a7281730d915 to your computer and use it in GitHub Desktop.
Fix console on ubuntu images

Redirect Ubuntu Console to First Serial Port

The cloud images that Canonical provides has the grub and linux console on the VGA port. This doesn't work so well for bhyve, where the graphical console only works with uefi. This document describes how to fix that using SmartOS.

Select a source image

The source image needs to include cloud-init 18.3 or later. Any Ubuntu 16.04 or later image produced by Canonical starting in July, 2018 should fit this criteria. The image in this example is described as Ubuntu 18.04.1 LTS (20180808 64-bit). Certified Ubuntu Server Cloud Image from Canonical..

src_uuid=96768413-88a7-43d6-867b-d74284d616d6

Import the source image

imgadm import $src_uuid

The following output is typical.

Importing 96768413-88a7-43d6-867b-d74284d616d6 (ubuntu-certified-18.04@20180808) from "https://images.joyent.com"
Gather image 96768413-88a7-43d6-867b-d74284d616d6 ancestry
Must download and install 1 image (330.0 MiB)
Download 1 image              [======================>] 100% 330.04MB   6.37MB/s    51s
Downloaded image 96768413-88a7-43d6-867b-d74284d616d6 (330.0 MiB)
...8a7-43d6-867b-d74284d616d6 [======================>] 100% 330.04MB  11.51MB/s    28s
Imported image 96768413-88a7-43d6-867b-d74284d616d6 (ubuntu-certified-18.04@20180808)

Create an instance from the source

vmadm create <<EOF
{
  "autoboot": false,
  "alias": "for-$src_uuid",
  "brand": "bhyve",
  "ram": "1024",
  "vcpus": "2",
  "disks": [
    {
      "image_uuid": "$src_uuid",
      "boot": true,
      "model": "virtio"
    }
  ]
}
EOF

Create a new image from the instance

This requires that prepare-image-ubuntu-console is in the current working directory.

inst_uuid=$(vmadm list -Ho uuid alias=for-$src_uuid)
desc=$(imgadm info "$src_uuid" | json manifest.description)
desc+=' For kvm and bhyve.'
version=$(date +%Y%m%d)
imgadm info $src_uuid | json manifest -e '
    this.manifest.uuid=undefined;
    this.manifest.state=undefined;
    this.manifest.public=undefined;
    this.manifest.version=undefined;
    this.manifest.published_at=undefined;
    this.manifest.requirements.brand=undefined;
    this.manifest.description=undefined;' |
    imgadm create $inst_uuid -c gzip -s prepare-image-ubuntu-console \
        -m - description="$desc" version="$version"

Import the image

# imgadm install -m ubuntu-certified-18.04-20181004.imgmanifest -f ubuntu-certified-18.04-20181004.zvol.gz
Installing image 24813a9f-0405-4ddf-819e-3e24bff1c180 (ubuntu-certified-18.04@20181004)
...819e-3e24bff1c180 [=======================>] 100% 340.28MB  26.48MB/s    12s
Installed image 24813a9f-0405-4ddf-819e-3e24bff1c180 (ubuntu-certified-18.04@20181004)

Test a deployment

new_uuid=$(json uuid < *.imgmanifest)
vmadm create <<EOF
{
  "autoboot": true,
  "alias": "test-$new_uuid",
  "brand": "bhyve",
  "ram": "1024",
  "vcpus": "2",
  "disks": [
    {
      "image_uuid": "$new_uuid",
      "boot": true,
      "model": "virtio"
    }
  ]
}
EOF
inst_uuid=$(vmadm list -Ho uuid alias=test-$new_uuid)
zlogin -C "$inst_uuid"
#! /bin/bash
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
cat >/etc/default/grub.d/50-cloudimg-settings.cfg <<EOF
# CLOUD_IMG: This file was created/modified by the Cloud Image build process
# Specific settings for the Joyent CLoud Images
# These settings are set by the Cloud Image build
# Set the default commandline
GRUB_CMDLINE_LINUX_DEFAULT="tsc=reliable earlyprintk"
# Set the recordfail timeout
GRUB_RECORDFAIL_TIMEOUT=5
# Do not wait on grub prompt
GRUB_TIMEOUT=5
GRUB_TERMINAL="serial console"
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
EOF
update-grub2
cloud-init clean -ls
mdata-put prepare-image:state success
shutdown -h now
@mgerdts
Copy link
Author

mgerdts commented Oct 4, 2018

after update-grub2 there should probably be cloud-init clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment