Skip to content

Commit ceb9e3b

Browse files
Merge pull request #232466 from msaenzbosupport/patch-5
[DOC-a_THon]Updating Generic upload VHD
2 parents 225ed24 + 7c19eb6 commit ceb9e3b

File tree

1 file changed

+66
-66
lines changed

1 file changed

+66
-66
lines changed

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

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This article focuses on general guidance for running your Linux distribution on
3131

3232
4. The maximum size allowed for the VHD is 1,023 GB.
3333

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

3636
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.
3737

@@ -58,20 +58,20 @@ The mechanism for rebuilding the initrd or initramfs image may vary depending on
5858

5959
1. Back up the existing initrd image:
6060

61-
```
62-
cd /boot
61+
```bash
62+
sudo cd /boot
6363
sudo cp initrd-`uname -r`.img initrd-`uname -r`.img.bak
6464
```
6565

6666
2. Rebuild the `initrd` with the `hv_vmbus` and `hv_storvsc` kernel modules:
6767

68-
```
68+
```bash
6969
sudo mkinitrd --preload=hv_storvsc --preload=hv_vmbus -v -f initrd-`uname -r`.img `uname -r`
7070
```
7171

7272
### Resizing VHDs
7373
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.
74-
```output
74+
```config
7575
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).
7676
```
7777
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.
@@ -82,11 +82,11 @@ In this case, resize the VM using either the Hyper-V Manager console or the [Res
8282

8383
1. Resizing the VHD directly using tools such as `qemu-img` or `vbox-manage` may result in an unbootable VHD. We recommend first converting the VHD to a RAW disk image. If the VM image was created as a RAW disk image (the default for some hypervisors such as KVM), then you may skip this step.
8484

85-
```
86-
qemu-img convert -f vpc -O raw MyLinuxVM.vhd MyLinuxVM.raw
85+
```bash
86+
sudo qemu-img convert -f vpc -O raw MyLinuxVM.vhd MyLinuxVM.raw
8787
```
8888

89-
1. Calculate the required size of the disk image so that the virtual size is aligned to 1 MB. The following bash shell script uses `qemu-img info` to determine the virtual size of the disk image, and then calculates the size to the next 1 MB.
89+
2. Calculate the required size of the disk image so that the virtual size is aligned to 1 MB. The following bash shell script uses `qemu-img info` to determine the virtual size of the disk image, and then calculates the size to the next 1 MB.
9090

9191
```bash
9292
rawdisk="MyLinuxVM.raw"
@@ -104,19 +104,19 @@ In this case, resize the VM using either the Hyper-V Manager console or the [Res
104104
3. Resize the raw disk using `$rounded_size` as set above.
105105

106106
```bash
107-
qemu-img resize MyLinuxVM.raw $rounded_size
107+
sudo qemu-img resize MyLinuxVM.raw $rounded_size
108108
```
109109

110110
4. Now, convert the RAW disk back to a fixed-size VHD.
111111

112112
```bash
113-
qemu-img convert -f raw -o subformat=fixed,force_size -O vpc MyLinuxVM.raw MyLinuxVM.vhd
113+
sudo qemu-img convert -f raw -o subformat=fixed,force_size -O vpc MyLinuxVM.raw MyLinuxVM.vhd
114114
```
115115

116116
Or, with qemu versions before 2.6, remove the `force_size` option.
117117

118118
```bash
119-
qemu-img convert -f raw -o subformat=fixed -O vpc MyLinuxVM.raw MyLinuxVM.vhd
119+
sudo qemu-img convert -f raw -o subformat=fixed -O vpc MyLinuxVM.raw MyLinuxVM.vhd
120120
```
121121

122122
## Linux Kernel Requirements
@@ -166,11 +166,11 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
166166
## General Linux System Requirements
167167
168168
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.
169-
```
169+
```config
170170
GRUB_CMDLINE_LINUX="rootdelay=300 console=ttyS0 earlyprintk=ttyS0 net.ifnames=0"
171171
```
172172
We also recommend *removing* the following parameters if they exist.
173-
```
173+
```config
174174
rhgb quiet crashkernel=auto
175175
```
176176
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.
@@ -179,46 +179,46 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
179179
```bash
180180
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
181181
```
182-
1. Add Hyper-V modules both initrd and initramfs instructions (Dracut).
183-
1. Rebuild `initrd` or `initramfs`.
182+
3. Add Hyper-V modules both initrd and initramfs instructions using `dracut` or `mkinitramfs`.
184183

185184
**Initramfs**
186185

187186
```bash
188-
cp /boot/initramfs-$(uname -r).img /boot/initramfs-[latest kernel version ].img.bak
189-
dracut -f -v /boot/initramfs-[latest kernel version ].img [depending on the version of grub]
190-
grub-mkconfig -o /boot/grub/grub.cfg
191-
grub2-mkconfig -o /boot/grub2/grub.cfg
187+
sudo cd /boot
188+
sudo cp initramfs-<kernel-version>.img <kernel-version>.img.bak
189+
sudo dracut -f -v initramfs-<kernel-version>.img <kernel-version> --add-drivers "hv_vmbus hv_netvsc hv_storvsc"
190+
sudo grub-mkconfig -o /boot/grub/grub.cfg
191+
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
192192
```
193193

194194
**Initrd**
195195

196196
```bash
197-
mv /boot/[initrd kernel] /boot/[initrd kernel]-old
198-
mkinitrd /boot/initrd.img-[initrd kernel]-generic /boot/[initrd kernel]-generic-old
199-
update-initramfs -c -k [initrd kernel]
200-
update-grub
197+
sudo cd /boot
198+
sudo cp initrd.img-<kernel-version> initrd.img-<kernel-version>.bak
199+
sudo mkinitramfs -o initrd.img-<kernel-version> <kernel-version> --with=hv_vmbus,hv_netvsc,hv_storvsc
200+
sudo update-grub
201201
```
202-
1. Ensure that the SSH server is installed, and configured to start at boot time. This configuration is usually the default.
202+
4. Ensure that the SSH server is installed, and configured to start at boot time. This configuration is usually the default.
203203

204-
1. Install the Azure Linux Agent.
204+
5. Install the Azure Linux Agent.
205205
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).
206206

207207
> [!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)**
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)**
209209

210210

211211
Install the Azure Linux Agent, cloud-init and other necessary utilities by running the following command:
212212

213-
**Redhat/Centos**
213+
**Red Hat/Centos**
214214
```bash
215-
sudo yum install -y [waagent] cloud-init cloud-utils-growpart gdisk hyperv-daemons
215+
sudo yum install -y WALinuxAgent cloud-init cloud-utils-growpart gdisk hyperv-daemons
216216
```
217217
**Ubuntu/Debian**
218218
```bash
219219
sudo apt install walinuxagent cloud-init cloud-utils-growpart gdisk hyperv-daemons
220220
```
221-
**Suse**
221+
**SUSE**
222222
```bash
223223
sudo zypper install python-azure-agent cloud-init cloud-utils-growpart gdisk hyperv-daemons
224224
```
@@ -228,14 +228,14 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
228228
sudo systemctl enable cloud-init.service
229229
```
230230

231-
1. Swap: Do not create swap space on the OS disk.
231+
6. Swap: Do not create swap space on the OS disk.
232232

233233
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.
234234

235235
Azure Linux Agent
236236
Modify the following parameters in /etc/waagent.conf
237237

238-
```
238+
```config
239239
ResourceDisk.Format=y
240240
ResourceDisk.Filesystem=ext4
241241
ResourceDisk.MountPoint=/mnt/resource
@@ -247,9 +247,9 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
247247
Configure cloud-init to handle the provisioning:
248248

249249
```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
250+
sudo sed -i 's/Provisioning.Agent=auto/Provisioning.Agent=cloud-auto/g' /etc/waagent.conf
251+
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
252+
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
253253
```
254254

255255
Configure Cloud-init to create swap.
@@ -262,9 +262,9 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
262262

263263
Create cfg file to configure swap using Cloud-init:
264264

265-
```
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
265+
```bash
266+
sudo echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
267+
sudo cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
268268
#cloud-config
269269
# Generated by Azure cloud image build
270270
disk_setup:
@@ -284,43 +284,44 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
284284
```
285285
286286
287-
9. Configure cloud-init to handle the provisioning:
287+
7. Configure cloud-init to handle the provisioning:
288288
1. Configure waagent for cloud-init:
289289
```bash
290-
sed -i 's/Provisioning.Agent=auto/Provisioning.Agent=cloud-init/g' /etc/waagent.conf
291-
sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
292-
sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
290+
sudo sed -i 's/Provisioning.Agent=auto/Provisioning.Agent=cloud-init/g' /etc/waagent.conf
291+
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
292+
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
293293
```
294294
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.
295+
295296
1. Configure mounts:
296-
```
297-
echo "Adding mounts and disk_setup to init stage"
298-
sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
299-
sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
300-
sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
301-
sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
302-
2. Configure Azure datasource:
303-
```
304-
echo "Allow only Azure datasource, disable fetching network setting via IMDS"
305-
cat > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg <<EOF
297+
```bash
298+
sudo echo "Adding mounts and disk_setup to init stage"
299+
sudo sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
300+
sudo sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
301+
sudo sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
302+
sudo sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
303+
1. Configure Azure datasource:
304+
```bash
305+
sudo echo "Allow only Azure datasource, disable fetching network setting via IMDS"
306+
sudo cat > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg <<EOF
306307
datasource_list: [ Azure ]
307308
datasource:
308309
Azure:
309310
apply_network_config: False
310311
EOF
311312
```
312-
3. If configured, remove existing swapfile:
313-
```
313+
1. If configured, remove existing swapfile:
314+
```bash
314315
if [[ -f /mnt/resource/swapfile ]]; then
315316
echo "Removing swapfile" #RHEL uses a swapfile by defaul
316317
swapoff /mnt/resource/swapfile
317318
rm /mnt/resource/swapfile -f
318319
fi
319320
```
320-
4. Configure cloud-init logging:
321-
```
322-
echo "Add console log file"
323-
cat >> /etc/cloud/cloud.cfg.d/05_logging.cfg <<EOF
321+
1. Configure cloud-init logging:
322+
```bash
323+
sudo echo "Add console log file"
324+
sudo cat >> /etc/cloud/cloud.cfg.d/05_logging.cfg <<EOF
324325
325326
# This tells cloud-init to redirect its stdout and stderr to
326327
# 'tee -a /var/log/cloud-init-output.log' so the user can see output
@@ -330,25 +331,24 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
330331
```
331332
332333
333-
1. Deprovision.
334+
8. Deprovision.
334335
> [!CAUTION]
335336
> 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.
336337
337338
Run the following commands to deprovision the virtual machine.
338339
339-
```
340-
# sudo rm -f /var/log/waagent.log
341-
# sudo cloud-init clean
342-
# waagent -force -deprovision+user
343-
# rm -f ~/.bash_history
344-
# export HISTSIZE=0
345-
# logout
340+
```bash
341+
sudo rm -f /var/log/waagent.log
342+
sudo cloud-init clean
343+
sudo -force -deprovision+user
344+
sudo rm -f ~/.bash_history
345+
sudo export HISTSIZE=0
346346
```
347347
348348
> [!NOTE]
349349
> 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.
350350
351-
1. Shut down the virtual machine and upload the VHD to Azure.
351+
9. Shut down the virtual machine and upload the VHD to Azure.
352352
353353
## Next Steps
354354
[Create a Linux VM from a custom disk with the Azure CLI](upload-vhd.md).

0 commit comments

Comments
 (0)