0

Create a disk

by
Published Oct 17, 2025

Add a new disk to an existing Linode.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Create a disk
7
 * Add a new disk to an existing Linode.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  linodeId: string,
13
  body: {
14
    authorized_keys?: string[];
15
    authorized_users?: string[];
16
    filesystem?: "raw" | "swap" | "ext2" | "ext3" | "ext4" | "initrd";
17
    image?: string;
18
    label?: string;
19
    root_pass?: string;
20
    size?: number;
21
    stackscript_data?: {};
22
    stackscript_id?: number;
23
  },
24
) {
25
  const url = new URL(
26
    `https://api.linode.com/${apiVersion}/linode/instances/${linodeId}/disks`,
27
  );
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43