How do I deploy a Linode using custom disk configurations?

Linode Staff

I would like to know a good way to deploy a Linode using the API that allows me to have a Linode that:

  1. Has no swap
  2. Has a disk that contains one of Linode's stock images but has a custom size
  3. Has an extra disk with a custom size

1 Reply

This is certainly possible. I'll propose two options that will basically go over the following workflow:

  1. Add an empty Linode
  2. Create the boot disk with the desired size
  3. Create the secondary disk with the desired size
  4. Create a Configuration Profile that contains both disks and the preferred kernel option

Using our Linode CLI(which is basically a wrapper of our API), I went through the workflow to create a test Linode. Here's how that looked like:

# Add empty Linode
linode-cli linodes create --region "ca-central" --label "API-Custom-Disk-Example" --type "g6-nanode-1" --private_ip true --group "API"

# Create the boot disk with the desired size 
linode-cli linodes disk-create --label "boot" --size 6000 --image "linode/ubuntu18.04" --root_pass "2HKH$^*llsa..." 19869124

# Create the secondary disk with the desired size
linodes disk-create --label "secondary" --size 3000  19869124

# Create a Configuration Profile that contains both disks and the preferred kernel option
linode-cli linodes config-create --label "boot_config" --kernel "linode/grub2" --devices.sda.disk_id 40616257 --devices.sdb.disk_id 40616264 --root_device "/dev/sda" 19869124

Just in case you need a quick reference, here are the API docs for each endpoint you are going to use when following the workflow above:

The second alternative is using Terraform. Terraform is a cool Infrastructure as Code (IaC) tool that allows you to deploy your infrastructure in a wide number of providers, including us. You simply define the specs needed for a Linode in a file and let Terraform handle the rest. We actually have a quick intro to Terraform in our Docs site that can give you a quick start on Terraform + Linode:

Use Terraform to Provision Linode Environments

Terraform also has a very good documentation on their Linode Provider. More specifically, I think the "linode_instance" resource is where you'll find most of the parameters needed to accomplish your use case:

Terraform linode_instance

So you can have a reference, I created the following Terraform file to create a Linode that fulfills the aforementioned requirements:

provider "linode" {
  token = "my_APIv4_token"
}

resource "linode_instance" "terraform-custom-disk" {
        label = "Terraform-Custom-Disk-Example"
        tags = ["Terraform"]
        region = "ca-central"
        type = "g6-nanode-1"
        private_ip = true

    disk {
        label = "boot"
        size = 6000
        image = "linode/ubuntu18.04"
        root_pass = "terr4form-test"
    }

    disk {
        label = "secondary"
        size = 3000
    }

    config {
        label = "boot_config"
        kernel = "linode/grub2"
        devices {
            sda {
                disk_label = "boot"
            }
            sdb {
                disk_label = "secondary"
            }
        }
        root_device = "/dev/sda"
    }

    boot_config_label = "boot_config"
}

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct