Skip to content

Commit e89a14d

Browse files
authored
Merge pull request #232649 from divargas-msft/patch-4
[Doc-a-thon] Updating cloudinit-configure-swapfile
2 parents d72805f + 329cc6f commit e89a14d

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

articles/virtual-machines/linux/cloudinit-configure-swapfile.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ author: mattmcinnes
55
ms.service: virtual-machines
66
ms.collection: linux
77
ms.topic: how-to
8-
ms.date: 11/29/2017
8+
ms.date: 03/29/2023
99
ms.author: mattmcinnes
1010
ms.subservice: cloud-init
1111
---
1212
# Use cloud-init to configure a swap partition on a Linux VM
1313

1414
**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
1515

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)
1717

1818
## Create swap partition for Ubuntu based images
19+
1920
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.
2021

2122
## Create swap partition for Red Hat and CentOS based images
2223

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.
2425

2526
```yaml
2627
#cloud-config
@@ -43,47 +44,52 @@ The mount is created with the `nofail` option to ensure that the boot will conti
4344

4445
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.
4546

46-
```azurecli-interactive
47+
```azurecli-interactive
4748
az group create --name myResourceGroup --location eastus
4849
```
4950

5051
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:
5152

52-
```azurecli-interactive
53+
```azurecli-interactive
5354
az vm create \
5455
--resource-group myResourceGroup \
55-
--name centos74 \
56-
--image OpenLogic:CentOS:7-CI:latest \
56+
--name vmName \
57+
--image imageCIURN \
5758
--custom-data cloud_init_swappart.txt \
5859
--generate-ssh-keys
5960
```
6061

62+
> [!NOTE]
63+
> Replace **myResourceGroup**, **vmName**, and **imageCIURN** values accordingly. Make sure an image with Cloud-init is chosen.
64+
6165
## 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:
6368

6469
```bash
65-
ssh <publicIpAddress>
70+
ssh <user>@<publicIpAddress>
6671
```
6772

6873
Once you have SSH'ed into the vm, check if the swap partition was created
6974

7075
```bash
71-
swapon -s
76+
sudo swapon -s
7277
```
7378

7479
The output from this command should look like this:
7580

76-
```text
81+
```output
7782
Filename Type Size Used Priority
7883
/dev/sdb2 partition 2494440 0 -1
7984
```
8085

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.
8388

8489
## Next steps
90+
8591
For additional cloud-init examples of configuration changes, see the following:
86-
92+
8793
- [Add an additional Linux user to a VM](cloudinit-add-user.md)
8894
- [Run a package manager to update existing packages on first boot](cloudinit-update-vm.md)
8995
- [Change VM local hostname](cloudinit-update-vm-hostname.md)

0 commit comments

Comments
 (0)