Skip to content

Commit 0d6f851

Browse files
Learn Editor: Update oracle-create-upload-vhd.md
1 parent 837165b commit 0d6f851

File tree

1 file changed

+96
-85
lines changed

1 file changed

+96
-85
lines changed

articles/virtual-machines/linux/oracle-create-upload-vhd.md

Lines changed: 96 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ms.date: 11/09/2021
1111
ms.author: srijangupta
1212
ms.reviewer: mattmcinnes
1313
---
14+
1415
# Prepare an Oracle Linux virtual machine for Azure
1516

1617
**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
@@ -29,15 +30,19 @@ This article assumes that you have already installed an Oracle Linux operating s
2930
* All VHDs on Azure must have a virtual size aligned to 1MB. When converting from a raw disk to VHD you must ensure that the raw disk size is a multiple of 1MB before conversion. See [Linux Installation Notes](create-upload-generic.md#general-linux-installation-notes) for more information.
3031
* Make sure that the `Addons` repository is enabled. Edit the file `/etc/yum.repos.d/public-yum-ol6.repo`(Oracle Linux 6) or `/etc/yum.repos.d/public-yum-ol7.repo`(Oracle Linux 7), and change the line `enabled=0` to `enabled=1` under **[ol6_addons]** or **[ol7_addons]** in this file.
3132

32-
## Oracle Linux 6.4 and later
33+
## Oracle Linux 6.X
34+
35+
> [!IMPORTANT]
36+
> Please note that Oracle Linux has reached its end of life and is [no longer supported by Oracle](https://www.oracle.com/a/ocom/docs/elsp-lifetime-069338.pdf). This means that no new updates or patches will be provided, and technical support may not be available. It is recommended that users migrate to a newer and supported version of Linux to ensure security and stability. We cannot be held responsible for any issues that may arise from continuing to use Oracle Linux after its end of life.
37+
3338
You must complete specific configuration steps in the operating system for the virtual machine to run in Azure.
3439

3540
1. In the center pane of Hyper-V Manager, select the virtual machine.
3641
2. Click **Connect** to open the window for the virtual machine.
3742
3. Uninstall NetworkManager by running the following command:
3843

39-
```console
40-
# sudo rpm -e --nodeps NetworkManager
44+
```bash
45+
sudo rpm -e --nodeps NetworkManager
4146
```
4247

4348
**Note:** If the package is not already installed, this command will fail with an error message. This is expected.
@@ -62,21 +67,21 @@ You must complete specific configuration steps in the operating system for the v
6267

6368
6. Modify udev rules to avoid generating static rules for the Ethernet interface(s). These rules can cause problems when cloning a virtual machine in Microsoft Azure or Hyper-V:
6469

65-
```console
66-
# sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
67-
# sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
70+
```bash
71+
sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
72+
sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
6873
```
6974

7075
7. Ensure the network service will start at boot time by running the following command:
7176

72-
```console
73-
# chkconfig network on
77+
```bash
78+
sudo chkconfig network on
7479
```
7580

7681
8. Install python-pyasn1 by running the following command:
7782

78-
```console
79-
# sudo yum install python-pyasn1
83+
```bash
84+
sudo yum install python-pyasn1
8085
```
8186

8287
9. Modify the kernel boot line in your grub configuration to include additional kernel parameters for Azure. To do this open "/boot/grub/menu.lst" in a text editor and ensure that the kernel includes the following parameters:
@@ -96,14 +101,18 @@ You must complete specific configuration steps in the operating system for the v
96101
Graphical and quiet boot are not useful in a cloud environment where we want all the logs to be sent to the serial port.
97102

98103
The `crashkernel` option may be left configured if desired, but note that this parameter will reduce the amount of available memory in the VM by 128MB or more, which may be problematic on the smaller VM sizes.
104+
99105
10. Ensure that the SSH server is installed and configured to start at boot time. This is usually the default.
100-
11. Install the Azure Linux Agent by running the following command. The latest version is 2.0.15.
106+
1. 11. Install the Azure Linux Agent by running the following command. The latest version is 2.0.15.
101107

102-
```console
103-
# sudo yum install WALinuxAgent
108+
109+
110+
111+
```bash
112+
sudo yum install WALinuxAgent
104113
```
105114

106-
Note that installing the WALinuxAgent package will remove the NetworkManager and NetworkManager-gnome packages if they were not already removed as described in step 2.
115+
Note that installing the WALinuxAgent package will remove the NetworkManager and NetworkManager-gnome packages if they were not already removed as described in step 2.
107116
12. Do not create swap space on the OS disk.
108117

109118
The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. Note that the local resource disk is a *temporary* disk, and might be emptied when the VM is deprovisioned. After installing the Azure Linux Agent (see previous step), modify the following parameters in /etc/waagent.conf appropriately:
@@ -118,10 +127,10 @@ You must complete specific configuration steps in the operating system for the v
118127

119128
13. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
120129

121-
```console
122-
# sudo waagent -force -deprovision
123-
# export HISTSIZE=0
124-
# logout
130+
```bash
131+
sudo waagent -force -deprovision
132+
sudo export HISTSIZE=0
133+
sudo logout
125134
```
126135

127136
14. Click **Action -> Shut Down** in Hyper-V Manager. Your Linux VHD is now ready to be [**uploaded to Azure**](./upload-vhd.md#option-1-upload-a-vhd).
@@ -162,27 +171,27 @@ Preparing an Oracle Linux 7 virtual machine for Azure is very similar to Oracle
162171

163172
5. Modify udev rules to avoid generating static rules for the Ethernet interface(s). These rules can cause problems when cloning a virtual machine in Microsoft Azure or Hyper-V:
164173

165-
```console
166-
# sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
174+
```bash
175+
sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
167176
```
168177

169178
6. Ensure the network service will start at boot time by running the following command:
170179

171-
```console
172-
# sudo chkconfig network on
180+
```bash
181+
sudo chkconfig network on
173182
```
174183

175184
7. Install the python-pyasn1 package by running the following command:
176185

177-
```console
178-
# sudo yum install python-pyasn1
186+
```bash
187+
sudo yum install python-pyasn1
179188
```
180189

181190
8. Run the following command to clear the current yum metadata and install any updates:
182191

183-
```console
184-
# sudo yum clean all
185-
# sudo yum -y update
192+
```bash
193+
sudo yum clean all
194+
sudo yum -y update
186195
```
187196

188197
9. Modify the kernel boot line in your grub configuration to include additional kernel parameters for Azure. To do this open "/etc/default/grub" in a text editor and edit the `GRUB_CMDLINE_LINUX` parameter, for example:
@@ -200,10 +209,10 @@ Preparing an Oracle Linux 7 virtual machine for Azure is very similar to Oracle
200209
Graphical and quiet boot are not useful in a cloud environment where we want all the logs to be sent to the serial port.
201210

202211
The `crashkernel` option may be left configured if desired, but note that this parameter will reduce the amount of available memory in the VM by 128MB or more, which may be problematic on the smaller VM sizes.
203-
10. Once you are done editing "/etc/default/grub" per above, run the following command to rebuild the grub configuration:
204212

205-
```console
206-
# sudo grub2-mkconfig -o /boot/grub2/grub.cfg
213+
10. Once you are done editing "/etc/default/grub" per above, run the following command to rebuild the grub configuration:
214+
1. ```bash
215+
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
207216
```
208217

209218
11. Ensure that the SSH server is installed and configured to start at boot time. This is usually the default.
@@ -216,28 +225,38 @@ Preparing an Oracle Linux 7 virtual machine for Azure is very similar to Oracle
216225

217226
13. Install cloud-init to handle the provisioning
218227

219-
```console
220-
yum install -y cloud-init cloud-utils-growpart gdisk hyperv-daemons
228+
```bash
229+
sudo yum install -y cloud-init cloud-utils-growpart gdisk hyperv-daemons
230+
```
221231

222-
# Configure waagent for cloud-init
223-
sed -i 's/Provisioning.UseCloudInit=n/Provisioning.UseCloudInit=y/g' /etc/waagent.conf
224-
sed -i 's/Provisioning.Enabled=y/Provisioning.Enabled=n/g' /etc/waagent.conf
232+
14. Configure waagent for cloud-init
225233

234+
```bash
235+
sudo sed -i 's/Provisioning.UseCloudInit=n/Provisioning.UseCloudInit=y/g' /etc/waagent.conf
236+
sudo sed -i 's/Provisioning.Enabled=y/Provisioning.Enabled=n/g' /etc/waagent.conf
237+
```
226238

227-
echo "Adding mounts and disk_setup to init stage"
228-
sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
229-
sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
230-
sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
231-
sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
239+
```bash
240+
sudo echo "Adding mounts and disk_setup to init stage"
241+
sudo sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
242+
sudo sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
243+
sudo sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
244+
sudo sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
245+
```
232246

247+
```bash
233248
echo "Allow only Azure datasource, disable fetching network setting via IMDS"
234-
cat > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg <<EOF
249+
```
250+
251+
```bash
252+
sudo cat > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg <<EOF
235253
datasource_list: [ Azure ]
236254
datasource:
237255
Azure:
238256
apply_network_config: False
239257
EOF
240258
259+
241260
if [[ -f /mnt/resource/swapfile ]]; then
242261
echo Removing swapfile - RHEL uses a swapfile by default
243262
swapoff /mnt/resource/swapfile
@@ -252,61 +271,53 @@ Preparing an Oracle Linux 7 virtual machine for Azure is very similar to Oracle
252271
# there without needing to look on the console.
253272
output: {all: '| tee -a /var/log/cloud-init-output.log'}
254273
EOF
255-
256274
```
257275
258-
14. Swap configuration
259-
Do not create swap space on the operating system disk.
276+
15. Swap configuration. Do not create swap space on the operating system disk.
260277
261-
Previously, the Azure Linux Agent was used automatically configure 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:
278+
Previously, the Azure Linux Agent was used automatically configure 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:
262279
263-
```console
264-
sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
265-
sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
280+
```bash
281+
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
282+
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
266283
```
267284
268-
If you want mount, format and create swap you can either:
269-
* Pass this in as a cloud-init config every time you create a VM
270-
* Use a cloud-init directive baked into the image that will do this every time the VM is created:
271-
272-
```console
273-
echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
274-
cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
275-
#cloud-config
276-
# Generated by Azure cloud image build
277-
disk_setup:
278-
ephemeral0:
279-
table_type: mbr
280-
layout: [66, [33, 82]]
281-
overwrite: True
282-
fs_setup:
283-
- device: ephemeral0.1
284-
filesystem: ext4
285-
- device: ephemeral0.2
286-
filesystem: swap
287-
mounts:
288-
- ["ephemeral0.1", "/mnt"]
289-
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service,x-systemd.device-timeout=2", "0", "0"]
290-
EOF
291-
```
285+
If you want mount, format and create swap you can either:
286+
* Pass this in as a cloud-init config every time you create a VM
287+
* Use a cloud-init directive baked into the image that will do this every time the VM is created:
292288
289+
```console
290+
echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
291+
cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
292+
#cloud-config
293+
# Generated by Azure cloud image build
294+
disk_setup:
295+
ephemeral0:
296+
table_type: mbr
297+
layout: [66, [33, 82]]
298+
overwrite: True
299+
fs_setup:
300+
- device: ephemeral0.1
301+
filesystem: ext4
302+
- device: ephemeral0.2
303+
filesystem: swap
304+
mounts:
305+
- ["ephemeral0.1", "/mnt"]
306+
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service,x-systemd.device-timeout=2", "0", "0"]
307+
EOF
308+
```
293309
294310
15. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
295311
296-
**Note:** if you are migrating a specific virtual machine and do not wish to create a generalized image,skip the deprovision step
297-
298-
```console
299-
# sudo cloud-init clean
300-
# sudo rm -f /var/log/waagent.log
301-
302-
# waagent -force -deprovision+user
303-
# rm -f ~/.bash_history
304-
305-
306-
# export HISTSIZE=0
312+
1. **Note:** if you are migrating a specific virtual machine and do not wish to create a generalized image, skip the deprovision step.
307313
308-
# logout
309-
```
314+
1. ```bash
315+
sudo cloud-init clean
316+
sudo rm -f /var/log/waagent.log
317+
sudo waagent -force -deprovision
318+
sudo rm -f ~/.bash_history
319+
sudo export HISTSIZE=0
320+
```
310321
311322
16. Click **Action -> Shut Down** in Hyper-V Manager. Your Linux VHD is now ready to be [**uploaded to Azure**](./upload-vhd.md#option-1-upload-a-vhd).
312323

0 commit comments

Comments
 (0)