Skip to content

Commit 0bfbc59

Browse files
[DOC-a_THon]Updating Generic upload VHD
-Changed the code block from console to bash -Added the code block output or bash for some empty block codes - Modified a few lines for the creation of the initramfs and initrd. -Modified the name os suse to SUSE -Fix a typo on command line : 213 .. Must be : WALinuxAgent
1 parent 2ae0fe9 commit 0bfbc59

File tree

1 file changed

+63
-65
lines changed

1 file changed

+63
-65
lines changed

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

Lines changed: 63 additions & 65 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,14 +58,14 @@ 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

@@ -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+
```output
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+
```output
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,44 @@ 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 cp /boot/initramfs-<kernel-version>.img <kernel-version>.img.bak
188+
sudo dracut -f -v /boot/initramfs-<kernel-version>.img <kernel-version> --add-drivers "hv_vmbus hv_netvsc hv_storvsc"
189+
sudo grub-mkconfig -o /boot/grub/grub.cfg
190+
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
192191
```
193192

194193
**Initrd**
195194

196195
```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
196+
sudo mv /boot/initrd.img-<kernel-version> <kernel-version>.old
197+
sudo mkinitramfs -o /boot/initrd.img-<kernel-version> <kernel-version> --with=hv_vmbus,hv_netvsc,hv_storvsc
198+
sudo update-grub
201199
```
202-
1. Ensure that the SSH server is installed, and configured to start at boot time. This configuration is usually the default.
200+
4. Ensure that the SSH server is installed, and configured to start at boot time. This configuration is usually the default.
203201

204-
1. Install the Azure Linux Agent.
202+
5. Install the Azure Linux Agent.
205203
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).
206204

207205
> [!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)**
206+
> 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)**
209207

210208

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

213-
**Redhat/Centos**
211+
**Red Hat/Centos**
214212
```bash
215-
sudo yum install -y [waagent] cloud-init cloud-utils-growpart gdisk hyperv-daemons
213+
sudo yum install -y WALinuxAgent cloud-init cloud-utils-growpart gdisk hyperv-daemons
216214
```
217215
**Ubuntu/Debian**
218216
```bash
219217
sudo apt install walinuxagent cloud-init cloud-utils-growpart gdisk hyperv-daemons
220218
```
221-
**Suse**
219+
**SUSE**
222220
```bash
223221
sudo zypper install python-azure-agent cloud-init cloud-utils-growpart gdisk hyperv-daemons
224222
```
@@ -228,14 +226,14 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
228226
sudo systemctl enable cloud-init.service
229227
```
230228

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

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

235233
Azure Linux Agent
236234
Modify the following parameters in /etc/waagent.conf
237235

238-
```
236+
```output
239237
ResourceDisk.Format=y
240238
ResourceDisk.Filesystem=ext4
241239
ResourceDisk.MountPoint=/mnt/resource
@@ -247,9 +245,9 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
247245
Configure cloud-init to handle the provisioning:
248246

249247
```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
248+
sudo sed -i 's/Provisioning.Agent=auto/Provisioning.Agent=cloud-auto/g' /etc/waagent.conf
249+
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
250+
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
253251
```
254252

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

263261
Create cfg file to configure swap using Cloud-init:
264262

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
263+
```bash
264+
sudo echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
265+
sudo cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
268266
#cloud-config
269267
# Generated by Azure cloud image build
270268
disk_setup:
@@ -284,43 +282,44 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
284282
```
285283
286284
287-
9. Configure cloud-init to handle the provisioning:
285+
7. Configure cloud-init to handle the provisioning:
288286
1. Configure waagent for cloud-init:
289287
```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
288+
sudo sed -i 's/Provisioning.Agent=auto/Provisioning.Agent=cloud-init/g' /etc/waagent.conf
289+
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
290+
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
293291
```
294292
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.
293+
295294
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
295+
```bash
296+
sudo echo "Adding mounts and disk_setup to init stage"
297+
sudo sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
298+
sudo sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
299+
sudo sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
300+
sudo sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
301+
1. Configure Azure datasource:
302+
```bash
303+
sudo echo "Allow only Azure datasource, disable fetching network setting via IMDS"
304+
sudo cat > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg <<EOF
306305
datasource_list: [ Azure ]
307306
datasource:
308307
Azure:
309308
apply_network_config: False
310309
EOF
311310
```
312-
3. If configured, remove existing swapfile:
313-
```
311+
1. If configured, remove existing swapfile:
312+
```bash
314313
if [[ -f /mnt/resource/swapfile ]]; then
315314
echo "Removing swapfile" #RHEL uses a swapfile by defaul
316315
swapoff /mnt/resource/swapfile
317316
rm /mnt/resource/swapfile -f
318317
fi
319318
```
320-
4. Configure cloud-init logging:
321-
```
322-
echo "Add console log file"
323-
cat >> /etc/cloud/cloud.cfg.d/05_logging.cfg <<EOF
319+
1. Configure cloud-init logging:
320+
```bash
321+
sudo echo "Add console log file"
322+
sudo cat >> /etc/cloud/cloud.cfg.d/05_logging.cfg <<EOF
324323
325324
# This tells cloud-init to redirect its stdout and stderr to
326325
# 'tee -a /var/log/cloud-init-output.log' so the user can see output
@@ -330,25 +329,24 @@ The [Azure Linux Agent](../extensions/agent-linux.md) `waagent` provisions a Lin
330329
```
331330
332331
333-
1. Deprovision.
332+
8. Deprovision.
334333
> [!CAUTION]
335334
> 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.
336335
337336
Run the following commands to deprovision the virtual machine.
338337
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
338+
```bash
339+
sudo rm -f /var/log/waagent.log
340+
sudo cloud-init clean
341+
sudo -force -deprovision+user
342+
sudo rm -f ~/.bash_history
343+
sudo export HISTSIZE=0
346344
```
347345
348346
> [!NOTE]
349347
> 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.
350348
351-
1. Shut down the virtual machine and upload the VHD to Azure.
349+
9. Shut down the virtual machine and upload the VHD to Azure.
352350
353351
## Next Steps
354352
[Create a Linux VM from a custom disk with the Azure CLI](upload-vhd.md).

0 commit comments

Comments
 (0)