Skip to content

Instantly share code, notes, and snippets.

@pgte
Last active June 4, 2018 23:25
Show Gist options
  • Save pgte/6246581 to your computer and use it in GitHub Desktop.
Save pgte/6246581 to your computer and use it in GitHub Desktop.

Recipe for customizing a SmartoOS image and cloning it

1. Create base image

1.1. Download and install the base image:

[root@00-0c-29-aa-24-ba ~]# imgadm list
UUID                                  NAME             VERSION  OS       PUBLISHED
9eac5c0c-a941-11e2-a7dc-57a6b041988f  base64           13.1.0   smartos  2013-04-26T15:17:57Z

1.2. Create a VM manifest

Something like:

{
  "autoboot": true,
  "brand": "joyent",
  "limit_priv": "default",
  "image_uuid": "9eac5c0c-a941-11e2-a7dc-57a6b041988f",
  "cpu_shares": 100,
  "zfs_io_priority": 100,
  "max_lwps": 2000,
  "max_physical_memory": 1024,
  "max_locked_memory": 1024,
  "max_swap": 1024,
  "tmpfs": 1024,
  "dns_domain": "local",
  "nics": [
    {
      "interface": "net0",
      "nic_tag": "admin",
      "gateway": "192.168.1.254",
      "primary": true,
      "ip": "dhcp"
    }
  ],
  "resolvers": ["192.168.1.254"]
}

1.3. Create a base zone using:

[root@00-0c-29-aa-24-ba ~]# vmadm create -f zone_manifest.json
Successfully created VM b79bbb1a-49c6-45b3-86a5-236351b5fadb

1.4. Log in to that zone

[root@00-0c-29-aa-24-ba ~]# zlogin b79bbb1a-49c6-45b3-86a5-236351b5fadb

1.5. Make some custom installations in that zone

1.6. Upgrade smtools

[root@b79bbb1a-49c6-45b3-86a5-236351b5fadb ~]# pkgin upgrade smtools

1.7. Prepare that image:

[root@b79bbb1a-49c6-45b3-86a5-236351b5fadb ~]# sm-prepare-image -y

(Now the zone is stopped and I'm back in the global zone)

1.8. Snapshot

[root@00-0c-29-aa-24-ba ~]# zfs snapshot zones/b79bbb1a-49c6-45b3-86a5-236351b5fadb@image

2. Install the Image

2.1. Save the snapshot image

[root@00-0c-29-aa-24-ba ~]# zfs send zones/b79bbb1a-49c6-45b3-86a5-236351b5fadb@image | bzip2 > /var/myimage.zfs.bz2

2.2. Create an image manifest image_manifest.json:

{
  "uuid": "b3f82236-04e9-11e3-8d1a-d70b21edc1ea",
  "name": "smartos-myimage",
  "version": "0.1.0",
  "description": "Base template",
  "os": "smartos",
  "type": "zone-dataset",
  "platform_type": "smartos",
  "cloud_name": "ntrace",
  "urn": "myimage:myimage:smartos:0.1.0",

  "creator_name": "ntrace",
  "creator_uuid": "7f1048c8-04d0-11e3-a69b-6350796da5e3",
  "vendor_uuid":  "7f1048c8-04d0-11e3-a69b-6350796da5e3",
  "created_at": "2013-08-14T08:45Z",
  "updated_at": "2013-08-14T08:45Z",
  "published_at": "2013-08-11T08:45Z",

  "files": [
    {
      "path": "myimage-0.1.0.zfs.bz2",
      "sha1": "8dccfba39cda8b8e5227fd2202aca1f0693fa98c",
      "size": 73869108,
      "url": "URL HERE"
    }
  ],
  "requirements": {
    "networks": [
      {
        "name": "net0",
        "description": "public"
      }
    ]
  }
}

2.3. Install that image:

[root@00-0c-29-aa-24-ba ~]# imgadm install -m image_manifest.json -f /var/myimage.zfs.bz2
b3f82236-04e9-11e3-8d1a-d70b21edc1ea                                 [=======================================================================================================================================================================>] 100%  70.45MB   1.41MB/s    49s
Installed image b3f82236-04e9-11e3-8d1a-d70b21edc1ea to "zones/b3f82236-04e9-11e3-8d1a-d70b21edc1ea".

3. Create a zone from that image

3.1. Create a zone manifest with the new image_uuid:

{
  "autoboot": true,
  "limit_priv": "default",
  "brand": "joyent",
  "image_uuid": "b3f82236-04e9-11e3-8d1a-d70b21edc1ea",
  "cpu_shares": 100,
  "zfs_io_priority": 100,
  "max_lwps": 2000,
  "max_physical_memory": 1024,
  "max_locked_memory": 1024,
  "max_swap": 1024,
  "tmpfs": 1024,
  "dns_domain": "local",
  "nics": [
    {
      "interface": "net0",
      "nic_tag": "admin",
      "gateway": "192.168.1.254",
      "primary": true,
      "ip": "dhcp"
    }
  ],
  "resolvers": ["192.168.1.254"]
}

3.2. Create an image from that zone manifest:

[root@00-0c-29-aa-24-ba ~]# vmadm create -f zone_manifest_2.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment