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
The following instructions only cover setting the VM to generalized. We recommend you follow the distro specific instructions for production workloads.
37
+
24
38
First you'll deprovision the VM by using the Azure VM agent to delete machine-specific files and data. Use the `waagent` command with the `-deprovision+user` parameter on your source Linux VM. For more information, see the [Azure Linux Agent user guide](./extensions/agent-linux.md). This process can't be reversed.
25
39
26
40
1. Connect to your Linux VM with an SSH client.
@@ -51,7 +65,7 @@ az vm generalize \
51
65
--name myVM
52
66
```
53
67
54
-
## Windows
68
+
## Windows
55
69
56
70
Sysprep removes all your personal account and security information, and then prepares the machine to be used as an image. For information about Sysprep, see [Sysprep overview](/windows-hardware/manufacture/desktop/sysprep--system-preparation--overview).
If you plan to run Sysprep before uploading your virtual hard disk (VHD) to Azure for the first time, make sure you have [prepared your VM](./windows/prepare-for-upload-vhd-image.md).
63
+
46
64
## Community gallery (preview)
47
65
48
66
> [!IMPORTANT]
@@ -54,7 +72,7 @@ When working through this article, replace the resource names where needed.
54
72
55
73
If you will be sharing your images using a [community gallery (preview)](azure-compute-gallery.md#community), make sure that you create your gallery, image definitions, and image versions in the same region.
56
74
57
-
When users search for community gallery images, only the latest version of an image are shown.
75
+
When users search for community gallery images, only the latest version of an image is shown.
58
76
59
77
60
78
## Create an image
@@ -110,7 +128,7 @@ You can also capture an existing VM as an image, from the portal. For more infor
110
128
111
129
Image definitions create a logical grouping for images. They are used to manage information about the image versions that are created within them.
112
130
113
-
Create an image definition in a gallery using [az sig image-definition create](/cli/azure/sig/image-definition#az-sig-image-definition-create). Make sure your image definition is the right type. If you have generalized the VM (using Sysprep for Windows, or waagent -deprovision for Linux) then you should create a generalized image definition using `--os-state generalized`. If you want to use the VM without removing existing user accounts, create a specialized image definition using `--os-state specialized`.
131
+
Create an image definition in a gallery using [az sig image-definition create](/cli/azure/sig/image-definition#az-sig-image-definition-create). Make sure your image definition is the right type. If you have [generalized](generalize.md) the VM (using `waagent -deprovision`for Linux, or Sysprep for Windows) then you should create a generalized image definition using `--os-state generalized`. If you want to use the VM without removing existing user accounts, create a specialized image definition using `--os-state specialized`.
114
132
115
133
For more information about the parameters you can specify for an image definition, see [Image definitions](shared-image-galleries.md#image-definitions).
description: Learn to create and upload an Azure virtual hard disk (VHD) that contains a Linux operating system.
2
+
title: Prepare Linux for imaging
3
+
description: Learn to prepare a Linux system to be used for an image in Azure.
4
4
author: srijang
5
5
ms.service: virtual-machines
6
6
ms.collection: linux
7
7
ms.topic: how-to
8
-
ms.date: 11/17/2021
8
+
ms.date: 05/13/2022
9
9
ms.author: srijangupta
10
10
11
11
---
12
-
# Information for Non-endorsed Distributions
12
+
# Information for community supported and non-endorsed distributions
13
13
14
14
**Applies to:**:heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
15
15
@@ -18,17 +18,7 @@ The Azure platform SLA applies to virtual machines running the Linux OS only whe
18
18
*[Linux on Azure - Endorsed Distributions](endorsed-distros.md)
19
19
*[Support for Linux images in Microsoft Azure](https://support.microsoft.com/kb/2941892)
20
20
21
-
All distributions running on Azure have a number of prerequisites. This article can't be comprehensive, as every distribution is different. Even if you meet all the criteria below, you may need to significantly tweak your Linux system for it to run properly.
22
-
23
-
We recommend that you start with one of the [Linux on Azure Endorsed Distributions](endorsed-distros.md). The following articles show you how to prepare the various endorsed Linux distributions that are supported on Azure:
-[Red Hat Enterprise Linux](redhat-create-upload-vhd.md)
30
-
-[SLES & openSUSE](suse-create-upload-vhd.md)
31
-
-[Ubuntu](create-upload-ubuntu.md)
21
+
All other, non-Azure Marketplace, distributions running on Azure have a number of prerequisites. This article can't be comprehensive, as every distribution is different. Even if you meet all the criteria below, you may need to significantly tweak your Linux system for it to run properly.
32
22
33
23
This article focuses on general guidance for running your Linux distribution on Azure.
34
24
@@ -47,10 +37,9 @@ This article focuses on general guidance for running your Linux distribution on
47
37
7. Don't configure a swap partition on the OS disk. The Linux agent can be configured to create a swap file on the temporary resource disk, as described in the following steps.
48
38
49
39
8. All VHDs on Azure must have a virtual size aligned to 1 MB (1024 × 1024 bytes). When converting from a raw disk to VHD you must ensure that the raw disk size is a multiple of 1 MB before conversion, as described in the following steps.
40
+
9. Use the most up-to-date distribution version, packages, and software.
41
+
8. Remove users and system accounts, public keys, sensitive data, unnecessary software and application.
50
42
51
-
> [!NOTE]
52
-
> Make sure **'udf'** (cloud-init >= 21.2) and **'vfat'** modules are enable. Blocklisting the udf module will cause a provisioning failure and backlisting vfat module will cause both provisioning and boot failures. **_Cloud-init < 21.2 are not affected and does not require this change._**
53
-
>
54
43
55
44
56
45
### Installing kernel modules without Hyper-V
@@ -73,9 +62,9 @@ The mechanism for rebuilding the initrd or initramfs image may vary depending on
73
62
74
63
### Resizing VHDs
75
64
VHD images on Azure must have a virtual size aligned to 1 MB. Typically, VHDs created using Hyper-V are aligned correctly. If the VHD isn't aligned correctly, you may receive an error message similar to the following when you try to create an image from your VHD.
76
-
77
-
* The VHD http:\//\<mystorageaccount>.blob.core.windows.net/vhds/MyLinuxVM.vhd has an unsupported virtual size of 21475270656 bytes. The size must be a whole number (in MBs).
78
-
65
+
```outout
66
+
The VHD http:\//\<mystorageaccount>.blob.core.windows.net/vhds/MyLinuxVM.vhd has an unsupported virtual size of 21475270656 bytes. The size must be a whole number (in MBs).
67
+
```
79
68
In this case, resize the VM using either the Hyper-V Manager console or the [Resize-VHD](/powershell/module/hyper-v/resize-vhd) PowerShell cmdlet. If you aren't running in a Windows environment, we recommend using `qemu-img` to convert (if needed) and resize the VHD.
80
69
81
70
> [!NOTE]
@@ -160,42 +149,171 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
160
149
* In some cases, the Azure Linux Agent may not be compatible with NetworkManager. Many of the RPM/deb packages provided by distributions configure NetworkManager as a conflict to the waagent package. In these cases, it will uninstall NetworkManager when you install the Linux agent package.
161
150
* The Azure Linux Agent must be at or above the [minimum supported version](https://support.microsoft.com/en-us/help/4049215/extensions-and-virtual-machine-agent-minimum-version-support).
162
151
152
+
> [!NOTE]
153
+
> Make sure **'udf'** (cloud-init >= 21.2) and **'vfat'** modules are enable. Blocklisting the udf module will cause a provisioning failure and backlisting vfat module will cause both provisioning and boot failures. **_Cloud-init < 21.2 are not affected and does not require this change._**
154
+
>
155
+
163
156
## General Linux System Requirements
164
157
165
158
1. Modify the kernel boot line in GRUB or GRUB2 to include the following parameters, so that all console messages are sent to the first serial port. These messages can assist Azure support with debugging any issues.
We also recommend *removing* the following parameters if they exist.
170
163
```
171
164
rhgb quiet crashkernel=auto
172
165
```
173
166
Graphical and quiet boot isn't useful in a cloud environment, where we want all logs sent to the serial port. The `crashkernel` option may be left configured if needed, but note that this parameter reduces the amount of available memory in the VM by at least 128 MB, which may be problematic for smaller VM sizes.
174
167
168
+
2. After you are done editing /etc/default/grub, run the following command to rebuild the grub configuration:
169
+
```bash
170
+
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
171
+
```
172
+
1. Add Hyper-V modules both initrd and initramfs instructions (Dracut).
173
+
1. Rebuild initrd or initramfs
174
+
**Initramfs**
175
+
```bash
176
+
cp /boot/initramfs-$(uname -r).img /boot/initramfs-[latest kernel version ].img.bak
177
+
dracut -f -v /boot/initramfs-[latest kernel version ].img [depending on the version of grub]
1. Ensure that the SSH server is installed, and configured to start at boot time. This configuration is usually the default.
175
190
1. Install the Azure Linux Agent.
176
-
177
-
The Azure Linux Agent is required for provisioning a Linux image on Azure. Many distributions provide the agent as an RPM or .deb package (the package is typically called WALinuxAgent or walinuxagent). The agent can also be installed manually by following the steps in the [Linux Agent Guide](../extensions/agent-linux.md).
178
-
179
-
1. Ensure that the SSH server is installed, and configured to start at boot time. This configuration is usually the default.
180
-
181
-
1. Don't create swap space on the OS disk.
182
-
183
-
The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. The local resource disk is a *temporary* disk, and might be emptied when the VM is deprovisioned. After installing the Azure Linux Agent (step 2 above), modify the following parameters in /etc/waagent.conf as needed.
184
-
```
185
-
ResourceDisk.Format=y
186
-
ResourceDisk.Filesystem=ext4
187
-
ResourceDisk.MountPoint=/mnt/resource
188
-
ResourceDisk.EnableSwap=y
189
-
ResourceDisk.SwapSizeMB=2048 ## NOTE: Set this to your desired size.
191
+
The Azure Linux Agent is required for provisioning a Linux image on Azure. Many distributions provide the agent as an RPM or .deb package (the package is typically called WALinuxAgent or walinuxagent). The agent can also be installed manually by following the steps in the [Linux Agent Guide](../extensions/agent-linux.md).
192
+
193
+
Install the Azure Linux Agent, cloud-init and other necessary utilities by running the following command:
Then enable the agent and cloud-init on all distributions using:
208
+
```bash
209
+
sudo systemctl enable waagent.service
210
+
sudo systemctl enable cloud-init.service
211
+
```
212
+
213
+
214
+
1. Don't create swap space on the OS disk. The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. The local resource disk is a temporary disk, and might be emptied when the VM is deprovisioned. After installing the Azure Linux Agent, modify the following parameters in /etc/waagent.conf as needed.
190
215
```
191
-
1. Run the following commands to deprovision the virtual machine.
192
-
216
+
ResourceDisk.Format=y
217
+
ResourceDisk.Filesystem=ext4
218
+
ResourceDisk.MountPoint=/mnt/resource
219
+
ResourceDisk.EnableSwap=y
220
+
ResourceDisk.SwapSizeMB=2048 ## NOTE: Set this to your desired size.
221
+
```
222
+
223
+
9. Configure cloud-init to handle the provisioning:
224
+
1. Configure waagent for cloud-init:
225
+
```bash
226
+
sed -i 's/Provisioning.Agent=auto/Provisioning.Agent=cloud-init/g' /etc/waagent.conf
227
+
sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
228
+
sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
229
+
```
230
+
If you are migrating a specific virtual machine and do not wish to create a generalized image, set `Provisioning.Agent=disabled` in the `/etc/waagent.conf` config.
231
+
1. Configure mounts:
232
+
```
233
+
echo "Adding mounts and disk_setup to init stage"
234
+
sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
235
+
sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
236
+
sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
237
+
sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
238
+
2. Configure Azure datasource:
239
+
```
240
+
echo "Allow only Azure datasource, disable fetching network setting via IMDS"
# This tells cloud-init to redirect its stdout and stderr to
262
+
# 'tee -a /var/log/cloud-init-output.log' so the user can see output
263
+
# there without needing to look on the console.
264
+
output: {all: '| tee -a /var/log/cloud-init-output.log'}
265
+
EOF
266
+
```
267
+
268
+
10. Swap configuration. Do not create swap space on the operating system disk.
269
+
Previously, the Azure Linux Agent automatically configured swap space by using the local resource disk that is attached to the virtual machine after the virtual machine is provisioned on Azure. However, this is now handled by cloud-init, you must not use the Linux Agent to format the resource disk create the swap file, modify the following parameters in /etc/waagent.conf appropriately:
270
+
```
271
+
ResourceDisk.Format=n
272
+
ResourceDisk.EnableSwap=n
193
273
```
194
-
sudo waagent -force -deprovision
195
-
export HISTSIZE=0
196
-
logout
197
-
```
274
+
If you want to mount, format and create swap you can either:
275
+
1. Pass this in as a cloud-init config every time you create a VM through `customdata`. This is the recommended method.
276
+
2. Use a cloud-init directive baked into the image that will do this every time the VM is created.
> If you are migrating a specific virtual machine and do not wish to create a generalized image, skip the deprovision step. Running the command waagent -force -deprovision+user will render the source machine unusable, this step is intended only to create a generalized image.
301
+
302
+
Run the following commands to deprovision the virtual machine.
303
+
304
+
```
305
+
# sudo rm -f /var/log/waagent.log
306
+
# sudo cloud-init clean
307
+
# waagent -force -deprovision+user
308
+
# rm -f ~/.bash_history
309
+
# export HISTSIZE=0
310
+
# logout
311
+
```
312
+
198
313
> [!NOTE]
199
314
> On Virtualbox you may see the following error after running `waagent -force -deprovision` that says `[Errno 5] Input/output error`. This error message is not critical and can be ignored.
200
315
201
-
* Shut down the virtual machine and upload the VHD to Azure.
316
+
1. Shut down the virtual machine and upload the VHD to Azure.
317
+
318
+
## Next Steps
319
+
[Create a Linux VM from a custom disk with the Azure CLI](upload-vhd.md).
0 commit comments