You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-machines/linux/cloudinit-configure-swapfile.md
+20-14Lines changed: 20 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,22 +5,23 @@ author: mattmcinnes
5
5
ms.service: virtual-machines
6
6
ms.collection: linux
7
7
ms.topic: how-to
8
-
ms.date: 11/29/2017
8
+
ms.date: 03/29/2023
9
9
ms.author: mattmcinnes
10
10
ms.subservice: cloud-init
11
11
---
12
12
# Use cloud-init to configure a swap partition on a Linux VM
13
13
14
14
**Applies to:**:heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
15
15
16
-
This article shows you how to use [cloud-init](https://cloudinit.readthedocs.io) to configure the swap partition on various Linux distributions. The swap partition was traditionally configured by the Linux Agent (WALA) based on which distributions required one. This document will outline the process for building the swap partition on demand during provisioning time using cloud-init. For more information about how cloud-init works natively in Azure and the supported Linux distros, see [cloud-init overview](using-cloud-init.md)
16
+
This article shows you how to use [cloud-init](https://cloudinit.readthedocs.io) to configure the swap partition on various Linux distributions. The swap partition was traditionally configured by the Linux Agent (WALA) based on which distributions required one. This document outlines the process for building the swap partition on demand during provisioning time using cloud-init. For more information about how cloud-init works natively in Azure and the supported Linux distros, see [cloud-init overview](using-cloud-init.md)
17
17
18
18
## Create swap partition for Ubuntu based images
19
+
19
20
By default on Azure, Ubuntu gallery images do not create swap partitions. To enable swap partition configuration during VM provisioning time using cloud-init - please see the [AzureSwapPartitions document](https://wiki.ubuntu.com/AzureSwapPartitions) on the Ubuntu wiki.
20
21
21
22
## Create swap partition for Red Hat and CentOS based images
22
23
23
-
Create a file in your current shell named *cloud_init_swappart.txt* and paste the following configuration. For this example, create the file in the Cloud Shell not on your local machine. You can use any editor you wish. Enter `sensible-editor cloud_init_swappart.txt` to create the file and see a list of available editors. Choose #1 to use the **nano** editor. Make sure that the whole cloud-init file is copied correctly, especially the first line.
24
+
Create a file in your current shell named *cloud_init_swappart.txt* and paste the following configuration. For this example, create the file in the Cloud Shell not on your local machine. You can use any editor you wish. Make sure that the whole cloud-init file is copied correctly, especially the first line.
24
25
25
26
```yaml
26
27
#cloud-config
@@ -43,47 +44,52 @@ The mount is created with the `nofail` option to ensure that the boot will conti
43
44
44
45
Before deploying this image, you need to create a resource group with the [az group create](/cli/azure/group) command. An Azure resource group is a logical container into which Azure resources are deployed and managed. The following example creates a resource group named *myResourceGroup* in the *eastus* location.
45
46
46
-
```azurecli-interactive
47
+
```azurecli-interactive
47
48
az group create --name myResourceGroup --location eastus
48
49
```
49
50
50
51
Now, create a VM with [az vm create](/cli/azure/vm) and specify the cloud-init file with `--custom-data cloud_init_swappart.txt` as follows:
51
52
52
-
```azurecli-interactive
53
+
```azurecli-interactive
53
54
az vm create \
54
55
--resource-group myResourceGroup \
55
-
--name centos74 \
56
-
--image OpenLogic:CentOS:7-CI:latest \
56
+
--name vmName \
57
+
--image imageCIURN \
57
58
--custom-data cloud_init_swappart.txt \
58
59
--generate-ssh-keys
59
60
```
60
61
62
+
> [!NOTE]
63
+
> Replace **myResourceGroup**, **vmName**, and **imageCIURN** values accordingly. Make sure an image with Cloud-init is chosen.
64
+
61
65
## Verify swap partition was created
62
-
SSH to the public IP address of your VM shown in the output from the preceding command. Enter your own **publicIpAddress** as follows:
66
+
67
+
SSH to the public IP address of your VM shown in the output from the preceding command. Enter your own **user** and **publicIpAddress** as follows:
63
68
64
69
```bash
65
-
ssh <publicIpAddress>
70
+
ssh <user>@<publicIpAddress>
66
71
```
67
72
68
73
Once you have SSH'ed into the vm, check if the swap partition was created
69
74
70
75
```bash
71
-
swapon -s
76
+
sudo swapon -s
72
77
```
73
78
74
79
The output from this command should look like this:
75
80
76
-
```text
81
+
```output
77
82
Filename Type Size Used Priority
78
83
/dev/sdb2 partition 2494440 0 -1
79
84
```
80
85
81
-
> [!NOTE]
82
-
> If you have an existing Azure image that has a swap partition configured and you want to change the swap partition configuration for new images, you should remove the existing swap partition. Please see 'Customize Images to provision by cloud-init' document for more details.
86
+
> [!NOTE]
87
+
> If you have an existing Azure image that has a swap partition configured and you want to change the swap partition configuration for new images, you should remove the existing swap partition. Please see [Customize Images to provision by cloud-init](/azure/virtual-machines/linux/tutorial-automate-vm-deployment) document for more details.
83
88
84
89
## Next steps
90
+
85
91
For additional cloud-init examples of configuration changes, see the following:
86
-
92
+
87
93
- [Add an additional Linux user to a VM](cloudinit-add-user.md)
88
94
- [Run a package manager to update existing packages on first boot](cloudinit-update-vm.md)
89
95
- [Change VM local hostname](cloudinit-update-vm-hostname.md)
0 commit comments