Skip to content

Commit 2776973

Browse files
authored
Merge pull request #221508 from cynthn/219358
219358 - srijan
2 parents ca9807a + 8410470 commit 2776973

File tree

1 file changed

+80
-48
lines changed

1 file changed

+80
-48
lines changed

articles/virtual-machines/linux/create-upload-generic.md

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: srijang
55
ms.service: virtual-machines
66
ms.collection: linux
77
ms.topic: how-to
8-
ms.date: 05/13/2022
8+
ms.date: 12/14/2022
99
ms.author: srijangupta
1010
ms.reviewer: mattmcinnes
1111
---
@@ -27,18 +27,27 @@ This article focuses on general guidance for running your Linux distribution on
2727

2828
2. Azure supports Gen1 (BIOS boot) & Gen2 (UEFI boot) Virtual machines.
2929

30-
3. The maximum size allowed for the VHD is 1,023 GB.
30+
3. The vfat kernel module must be enabled in the kernel
3131

32-
4. When installing the Linux system we recommend that you use standard partitions, rather than Logical Volume Manager (LVM) which is the default for many installations. Using standard partitions will avoid LVM name conflicts with cloned VMs, particularly if an OS disk is ever attached to another identical VM for troubleshooting. [LVM](/previous-versions/azure/virtual-machines/linux/configure-lvm) or [RAID](/previous-versions/azure/virtual-machines/linux/configure-raid) may be used on data disks.
32+
4. The maximum size allowed for the VHD is 1,023 GB.
3333

34-
5. Kernel support for mounting UDF file systems is necessary. At first boot on Azure the provisioning configuration is passed to the Linux VM by using UDF-formatted media that is attached to the guest. The Azure Linux agent must mount the UDF file system to read its configuration and provision the VM.
34+
5. When installing the Linux system we recommend that you use standard partitions, rather than Logical Volume Manager (LVM) which is the default for many installations. Using standard partitions will avoid LVM name conflicts with cloned VMs, particularly if an OS disk is ever attached to another identical VM for troubleshooting. [LVM](/previous-versions/azure/virtual-machines/linux/configure-lvm) or [RAID](/previous-versions/azure/virtual-machines/linux/configure-raid) may be used on data disks.
3535

36-
6. Linux kernel versions earlier than 2.6.37 don't support NUMA on Hyper-V with larger VM sizes. This issue primarily impacts older distributions using the upstream Red Hat 2.6.32 kernel, and was fixed in Red Hat Enterprise Linux (RHEL) 6.6 (kernel-2.6.32-504). Systems running custom kernels older than 2.6.37, or RHEL-based kernels older than 2.6.32-504 must set the boot parameter `numa=off` on the kernel command line in grub.conf. For more information, see [Red Hat KB 436883](https://access.redhat.com/solutions/436883).
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.
36+
6. Kernel support for mounting UDF file systems is necessary. At first boot on Azure the provisioning configuration is passed to the Linux VM by using UDF-formatted media that is attached to the guest. The Azure Linux agent must mount the UDF file system to read its configuration and provision the VM.
3837

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.
38+
7. Linux kernel versions earlier than 2.6.37 don't support NUMA on Hyper-V with larger VM sizes. This issue primarily impacts older distributions using the upstream Red Hat 2.6.32 kernel, and was fixed in Red Hat Enterprise Linux (RHEL) 6.6 (kernel-2.6.32-504). Systems running custom kernels older than 2.6.37, or RHEL-based kernels older than 2.6.32-504 must set the boot parameter `numa=off` on the kernel command line in grub.conf. For more information, see [Red Hat KB 436883](https://access.redhat.com/solutions/436883).
39+
40+
8. 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.
41+
42+
10. 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.
43+
44+
11. Use the most up-to-date distribution version, packages, and software.
45+
46+
12. Remove users and system accounts, public keys, sensitive data, unnecessary software and application.
47+
48+
49+
> [!NOTE]
50+
> **(_Cloud-init >= 21.2 removes the udf requirement._)** however without the udf module enabled the cdrom will not mount during provisioning preventing custom data from being applied. A workaround for this would be to apply custom data using user data however, unlike custom data user data is not encrypted. https://cloudinit.readthedocs.io/en/latest/topics/format.html
4251
4352

4453

@@ -62,7 +71,7 @@ The mechanism for rebuilding the initrd or initramfs image may vary depending on
6271
6372
### Resizing VHDs
6473
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.
65-
```outout
74+
```output
6675
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).
6776
```
6877
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.
@@ -171,8 +180,10 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
171180
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
172181
```
173182
1. Add Hyper-V modules both initrd and initramfs instructions (Dracut).
174-
1. Rebuild initrd or initramfs
183+
1. Rebuild `initrd` or `initramfs`.
184+
175185
**Initramfs**
186+
176187
```bash
177188
cp /boot/initramfs-$(uname -r).img /boot/initramfs-[latest kernel version ].img.bak
178189
dracut -f -v /boot/initramfs-[latest kernel version ].img [depending on the version of grub]
@@ -181,16 +192,22 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
181192
```
182193

183194
**Initrd**
195+
184196
```bash
185197
mv /boot/[initrd kernel] /boot/[initrd kernel]-old
186198
mkinitrd /boot/initrd.img-[initrd kernel]-generic /boot/[initrd kernel]-generic-old
187199
update-initramfs -c -k [initrd kernel]
188200
update-grub
189201
```
190202
1. Ensure that the SSH server is installed, and configured to start at boot time. This configuration is usually the default.
203+
191204
1. Install the Azure Linux Agent.
192205
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).
193206

207+
> [!NOTE]
208+
> Make sure 'udf' and 'vfat' modules are enable. Blocklisting or removing the udf module will cause a provisioning failure. Blocklisting or removing vfat module will cause both provisioning and boot failures. **(_Cloud-init >= 21.2 removes the udf requirement. Please read top of document for more detail)**
209+
210+
194211
Install the Azure Linux Agent, cloud-init and other necessary utilities by running the following command:
195212

196213
**Redhat/Centos**
@@ -211,15 +228,61 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
211228
sudo systemctl enable cloud-init.service
212229
```
213230

231+
1. Swap: Do not create swap space on the OS disk.
232+
233+
The Azure Linux Agent or Cloud-init can be used to configure swap space using the local resource disk. This resource disk 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. The following blocks show how to configure this swap.
234+
235+
Azure Linux Agent
236+
Modify the following parameters in /etc/waagent.conf
237+
238+
```
239+
ResourceDisk.Format=y
240+
ResourceDisk.Filesystem=ext4
241+
ResourceDisk.MountPoint=/mnt/resource
242+
ResourceDisk.EnableSwap=y
243+
ResourceDisk.SwapSizeMB=2048 ## NOTE: Set this to your desired size.
244+
```
245+
246+
Cloud-init
247+
Configure cloud-init to handle the provisioning:
248+
249+
```bash
250+
sed -i 's/Provisioning.Agent=auto/Provisioning.Agent=cloud-auto/g' /etc/waagent.conf
251+
sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
252+
sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
253+
```
254+
255+
Configure Cloud-init to create swap.
256+
257+
To format and create swap you have 2 options either:
258+
259+
1. Pass this in as a cloud-init config every time you create a VM through `customdata`. This is the recommended method.
260+
261+
2. Use a cloud-init directive baked into the image that will do this every time the VM is created.
262+
263+
Create cfg file to configure swap using Cloud-init:
214264

215-
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.
216265
```
217-
ResourceDisk.Format=y
218-
ResourceDisk.Filesystem=ext4
219-
ResourceDisk.MountPoint=/mnt/resource
220-
ResourceDisk.EnableSwap=y
221-
ResourceDisk.SwapSizeMB=2048 ## NOTE: Set this to your desired size.
266+
echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
267+
cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
268+
#cloud-config
269+
# Generated by Azure cloud image build
270+
disk_setup:
271+
ephemeral0:
272+
table_type: mbr
273+
layout: [66, [33, 82]]
274+
overwrite: True
275+
fs_setup:
276+
- device: ephemeral0.1
277+
filesystem: ext4
278+
- device: ephemeral0.2
279+
filesystem: swap
280+
mounts:
281+
- ["ephemeral0.1", "/mnt"]
282+
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service,x-systemd.device-timeout=2", "0", "0"]
283+
EOF
222284
```
285+
223286
224287
9. Configure cloud-init to handle the provisioning:
225288
1. Configure waagent for cloud-init:
@@ -266,37 +329,6 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
266329
EOF
267330
```
268331
269-
10. Swap configuration. Do not create swap space on the operating system disk.
270-
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:
271-
```
272-
ResourceDisk.Format=n
273-
ResourceDisk.EnableSwap=n
274-
```
275-
If you want to mount, format and create swap you can either:
276-
1. Pass this in as a cloud-init config every time you create a VM through `customdata`. This is the recommended method.
277-
2. Use a cloud-init directive baked into the image that will do this every time the VM is created.
278-
279-
```
280-
echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
281-
cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
282-
#cloud-config
283-
# Generated by Azure cloud image build
284-
disk_setup:
285-
ephemeral0:
286-
table_type: mbr
287-
layout: [66, [33, 82]]
288-
overwrite: True
289-
fs_setup:
290-
- device: ephemeral0.1
291-
filesystem: ext4
292-
- device: ephemeral0.2
293-
filesystem: swap
294-
mounts:
295-
- ["ephemeral0.1", "/mnt"]
296-
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service,x-systemd.device-timeout=2", "0", "0"]
297-
EOF
298-
299-
```
300332
301333
1. Deprovision.
302334
> [!CAUTION]

0 commit comments

Comments
 (0)