<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Azure Linux Support Team</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/linuxonazure/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/linuxonazure/feed.xml</link>
    <description>Support for Linux on Azure</description>
    <lastBuildDate>Fri, 14 Dec 2018 09:09:25 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Why proactively ensuring you have access to GRUB and sysrq in your Linux VM could save you lots of down time?</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/why-proactively-ensuring-you-have-access-to-grub-and-sysrq-in-your-linux-vm-could-save-you-lots-of-down-time</link>
      <pubDate>Tue, 23 Oct 2018 10:25:15 GMT</pubDate>
      <dc:creator><![CDATA[Vittorio Franco Libertucci]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=505</guid>
      <description><![CDATA[Quite simply, to speed up the recovery time of your IaaS Linux Virtual Machine most recovery options...]]></description>
      <content:encoded><![CDATA[<h2>Quite simply, to speed up the recovery time of your IaaS Linux Virtual Machine most recovery options will be possible if GRUB is configured.</h2>
<h2><strong>Recovering Linux Virtual Machines in Azure</strong></h2>
You will, at some point have to perform some type of recovery in your Linux VM unless you are very lucky, this inevitable.

The reasons for performing a VM recovery are numerous and can be anything such as:
<p style="padding-left: 30px">• corrupt file systems/kernel/MBR
• failed kernel upgrades
• incorrect fstab configurations
• firewall configurations
• lost password
• mangled sshd configurations files
• Networking configurations
• Many others</p>
You should take some time and verify if you can access <strong>GRUB</strong> on your VM's deployed in Azure. Official  <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/troubleshooting/serial-console-linux">Microsoft docs  </a>

Ensure you take backups of files before making changes.

Watch <a href="https://youtu.be/KevOc3d_SG4">this </a>video to see how you can quickly recover you Linux VM once you have access to GRUB

There are a number of methods to aid recovery however in a Cloud environment this has been challenging and time is of the essence we understand you need to restore services at lightning speed.

With the introduction of the <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/troubleshooting/serial-console-grub-single-user-mode">Azure Serial Console</a> you have the power to interact with your Linux VM and manipulate many aspects including how the kernel will boot. The more experienced Linux/Unix sys admins will appreciate the <strong>single user</strong> and <strong>emergency</strong> modes that are accessible via the Azure Console making Disk Swap and VM deletion for many recovery scenarios redundant.

The method of recovery depends on the problem you are facing, for example a lost or misplaced password can be reset through Azure Portal options -&gt; Reset Password . This communicates with the Linux Guest other possible tools such as Custom Script and other mechanisms are available however these options require that the Linux waagent be up and in a healthy state.

By ensuring that you have access to the<strong> Azure Serial Console</strong> and <strong>GRUB</strong> a password or an incorrect configuration change can take a matter of minutes instead of hours. You could even force the VM to boot from an alternative kernel should you have multiple kernels on disk in the scenario where your primary kernel becomes corrupt.
<p style="padding-left: 30px"><strong>suggested order of recovery methods</strong>
• Azure Serial Console
• Disk Swap - can be automated using either:</p>
<p style="padding-left: 90px"><a href="https://github.com/Azure/azure-support-scripts/tree/master/VMRecovery/ResourceManager">Power Shell Recovery Scripts</a></p>
<p style="padding-left: 90px"><a href="https://github.com/sribs/azure-support-scripts">bash Recovery Scripts</a></p>
<p style="padding-left: 30px">• Legacy Method</p>
<strong>Challenge:</strong>
Not all Linux Azure VMs are configured by default for <strong>GRUB </strong>access and neither are they all configured to be interrupted with the <strong>sysrq </strong>commands. Some older distros such as SLES 11 Linux VM's are not configured to display Login prompt in the Azure Serial Console

In this current <strong><em>draft</em> </strong>article I will review various distros and document findings on how to configure GRUB and what's the impact. (RH and SUSE to complete)
<h3><a href="#sysrq">How to configure Linux VM to accept SysRq keys</a></h3>
<h3><a href="#ubuntugrub">Ubuntu GRUB configuration</a></h3>
<ul>
 	<li><a href="#ubuntu1204">Ubuntu 12.04</a></li>
</ul>
<h3><a href="#RH">Red Hat GRUB configuration</a></h3>
<ul>
 	<li style="text-align: left"><a href="#RH74">Red Hat 7.4+ GRUB configuration</a></li>
 	<li><a href="#RH72">Red Hat 7.2+ GRUB configuration</a></li>
 	<li><a href="#RH6x">Red Hat 6.x GRUB configuration</a></li>
</ul>
<h3><a href="#binbash">Force the kernel to a bash prompt</a></h3>
<h3><a href="#single">Single User mode</a></h3>
<h3><a href="#ubunturecmode">Ubuntu Recovery Mode</a></h3>
&nbsp;

&nbsp;
<h2><a id="#sysrq"></a>How to configure Linux VM to accept SysRq keys</h2>
The <em><b>sysrq</b> </em>key is enabled on some newer Linux distros by default , whilst on other it could be configured for accepting  values only for certain <em><strong>SysRq</strong> </em>features and on others it could be disabled completely especially in many older versions.

The <strong>SysRq</strong> feature is useful for rebooting a crashed or hung VM directly from the Azure Serial Console, I also find it extremely helpful in gaining access to the the GRUB menu, alternatively restarting a VM from another Portal window or ssh session might drop your current console connection thus expiring GRUB Timeouts to which are used to display the GRUB menu.

The VM must be configured to accept a value of 1 for the kernel parameter which enables all functions of sysrq or 128 which allows reboot/poweroff

[video width="1920" height="1080" mp4="https://msdnshared.blob.core.windows.net/media/2018/10/enable-sysrq-for-Azure-Serial-Console1.mp4"][/video]

&nbsp;

To configure the VM to accept a reboot via SysRq commands on the Azure Portal you will need to set a value of 1 for the kernel parameter kernel.sysrq

For this configuration to persist a reboot it can be configured by adding entries to the file <b>sysctl.conf  </b>

<strong>echo kernel.sysrq=1 &gt;&gt; /etc/sysctl.conf</strong>

To configure the kernel parameter dynamically

<strong>sysctl -w kernel.sysrq=1</strong>

If you do not have root access or sudo is broken you can't enable SysRq from a shell prompt?

You can enable the <strong>sysrq</strong>  in such a scenario using the Portal. This can be beneficial if the sudoers.d/waagent file has become broken or an admin has deleted it.

Using the Azure Portal Operations -&gt; Run Command -&gt; RunShellScript feature, requires  the waagent process be healthy you can then inject this command to enable <strong>sysrq</strong>

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/enabling_sysrq_via_run.jpg"><img width="493" height="255" class="alignnone wp-image-675" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/enabling_sysrq_via_run.jpg" /></a>

&nbsp;

&nbsp;

<strong>sysctl -w kernel.sysrq=1 ; echo kernel.sysrq=1 &gt;&gt; /etc/sysctl.conf</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/enabling_sysrq_via_run2.jpg"><img width="510" height="313" class="alignnone wp-image-695" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/enabling_sysrq_via_run2.jpg" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/enabling_sysrq_via_run1.jpg"></a>Once completed you can then try accessing <strong>SysRq</strong> and should see that a reboot is possible.

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/enabling_sysrq-4.jpg"><img width="470" height="267" class="alignnone wp-image-745" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/enabling_sysrq-4.jpg" /></a>
<p lang="en-GB">Select <strong>Reboot</strong> and <strong>Send SysRq Command</strong></p>
<p lang="en-GB"><a href="https://msdnshared.blob.core.windows.net/media/2018/10/enabling_sysrq_5a.jpg"><img width="471" height="221" class="alignnone wp-image-755" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/enabling_sysrq_5a.jpg" /></a></p>
The system should log a reset message such as this

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/rh6-1.jpg"><img width="447" height="132" class="alignnone wp-image-735" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/rh6-1.jpg" /></a>
<h2></h2>
<h2><a id="#ubuntugrub"></a>Ubuntu GRUB configuration</h2>
By default you should be able to access GRUB by holding down <strong>Esc </strong>key during the VM boot, however in testing , the <strong>GRUB </strong> menu was not always presented.
To force and keep the GRUB menu on screen in the Azure Serial Console you can test and use one of these 3 options.

<strong>Option 1</strong>

update this file /etc/default/grub.d/50-cloudimg-settings.cfg and it will keep the GRUB menu on screen for ever how long you specify.

GRUB_TIMEOUT=0

to

GRUB_TIMEOUT=5

<strong>Option 2</strong>
We can also achieve similar behavior by making changes to this file /etc/default/grub and observe 3 seconds to hit <strong>Esc
</strong>

Comment these 2 lines:
<em>#GRUB_HIDDEN_TIMEOUT=0
#GRUB_HIDDEN_TIMEOUT_QUIET=true</em>

And add replace with

<em>GRUB_TIMEOUT_STYLE=countdown</em>

<strong>Option 3</strong>
This configuration gives you 5 seconds to hit <strong>Esc </strong> to acess <strong>GRUB </strong>and does perform a countdown to select the kernel

Update the file /etc/default/grub

GRUB_HIDDEN_TIMEOUT=5
#GRUB_HIDDEN_TIMEOUT_QUIET=true
#GRUB_TIMEOUT_STYLE=countdown
GRUB_TIMEOUT=10

For all these options you need to recreate GRUB configurations by running:

<em>update-grub</em><strong></strong>

&nbsp;
<h4><a id="#ubuntu1204"></a>Ubuntu 12.04</h4>

Ubuntu 12.04 will allow to see serial console but does not allow to interact. You will not see a <strong>login:</strong> prompt.

The settings required by each Ubuntu version for configuring serial console can be found <a href="https://help.ubuntu.com/community/SerialConsoleHowto">here</a>

Testing 12.04 was sufficient to

1) Create a file called /etc/init/ttyS0.conf containing the following:
<pre># ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.
start on stopped rc RUNLEVEL=[12345]
stop on runlevel [!12345]

respawn
exec /sbin/getty -L 115200 ttyS0 vt102
</pre>
2) Ask upstart to start the getty
<pre>sudo start ttyS0</pre>
<h2><a id="#RH"></a>Red Hat GRUB configuration</h2>
<h4><a id="#RH74"></a>RHEL 7.4+</h4>
The default /etc/default/grub configuration on these versions is adequately configured
<pre>GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial"
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300"
GRUB_DISABLE_RECOVERY="true"</pre>
Simply enable the SysRq key
<em>sysctl -w kernel.sysrq=1;echo kernel.sysrq=1 &gt;&gt; /etc/sysctl.conf;sysctl -a | grep -i sysrq</em>
<h3><a id="#RH72"></a>RHEL 7.2+</h3>
The file to modify is /etc/default/grub - a default config looks like this:
<pre>GRUB_TIMEOUT=1
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300"
GRUB_DISABLE_RECOVERY="true"</pre>
change the following lines in /etc/default/grub

GRUB_TIMEOUT=1

to

GRUB_TIMEOUT=5

GRUB_TERMINAL_OUTPUT="console"

to

GRUB_TERMINAL="serial console"

also add this line:

GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"

/etc/default/grub should now look similar to this:
<pre>GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300"
GRUB_DISABLE_RECOVERY="true"</pre>
Complete and update grub configuration using

<em>grub2-mkconfig -o /boot/grub2/grub.cfg</em>

set the SysRq kernel parameter:

<em>sysctl -w kernel.sysrq=1;echo kernel.sysrq=1 &gt;&gt; /etc/sysctl.conf;sysctl -a | grep -i sysrq</em>

For the more adventurous: I also configured GRUB and SysRq using a single line via the Run Command feature  it worked well but please backup your files before running this.
<pre>cp /etc/default/grub /etc/default/grub.bak; sed -i 's/GRUB_TIMEOUT=1/GRUB_TIMEOUT=5/g' /etc/default/grub; sed -i 's/GRUB_TERMINAL_OUTPUT="console"/GRUB_TERMINAL="serial console"/g' /etc/default/grub; echo "GRUB_SERIAL_COMMAND=\"serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1\"" &gt;&gt; /etc/default/grub;grub2-mkconfig -o /boot/grub2/grub.cfg;sysctl -w kernel.sysrq=1;echo kernel.sysrq=1 /etc/sysctl.conf;sysctl -a | grep -i sysrq</pre>
<h3><a id="#RH6x"></a>RHEL 6.x</h3>
The file to modify is /boot/grub/grub.conf make the necessary modifications and you should have a configuration like this (the <em>timeout=15</em> is used for demo purpose a reasonable value is 5)
<pre>#boot=/dev/vda
default=0
timeout=15
splashimage=(hd0,0)/grub/splash.xpm.gz
#hiddenmenu
serial --unit=0 --speed=9600
terminal serial
terminal --timeout=5 serial console</pre>
The last line, t<em>erminal --timeout=5</em> <em>serial console</em> will further increase <strong>GRUB</strong> timeout by adding a prompt for 5 seconds “Press any key to continue.” displayed in the console.

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/rh6-1.jpg"><img width="508" height="150" class="alignnone wp-image-735" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/rh6-1.jpg" /></a>

GRUB menu should appear on screen for the configured timeout=15  without the need to press Esc. Make sure to click in the Console in the Browser to make active the menu and select the required kernel

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/rh6-2.jpg"><img width="512" height="354" class="alignnone wp-image-765" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/rh6-2.jpg" /></a>
<h2></h2>
<h2><a id="#binbash"></a>Force the kernel to a bash prompt</h2>
no password for root access in single user?
If you do not have root password and single user requires you to have a root password, you can boot the kernel replacing the init program with a bash prompt - this can be achieved by appending init=/bin/bash
<a href="https://msdnshared.blob.core.windows.net/media/2018/10/pic1.png"><img width="671" height="310" class="alignnone size-full wp-image-525" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/pic1.png" /></a>

Remount your / (root) file system RW using the command
mount -o remount,rw /

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/pic22.png"><img width="671" height="310" class="alignnone size-full wp-image-545" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/pic22.png" /></a>

Now you can perform root password change or many other Linux configuration changes

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/pic3.png"><img width="671" height="202" class="alignnone size-full wp-image-515" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/pic3.png" /></a>

Restart the VM with /sbin/reboot -f
<h2><a id="#single"></a>Single User mode</h2>
Alternatively you might need to access the VM in <strong>single user</strong> or <strong>emergency </strong>mode Select the kernel you wish to boot or interrupt using arrow keys
<a href="https://msdnshared.blob.core.windows.net/media/2018/10/single_user_ubuntu.png"><img width="671" height="310" class="alignnone size-full wp-image-555" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/single_user_ubuntu.png" /></a>

Enter the desired mode by appending the keyword "<strong>single</strong>" or "<strong>1</strong>" to the line displaying "Ubuntu" on Red Hat systems you can also append <strong>rd.break</strong>

&nbsp;
<h2><a id="#ubunturecmode"></a>Ubuntu Recovery Mode</h2>
Additional recovery and clean up options are available for Ubuntu via GRUB however these are only are accessible if you configure kernel parameters accordingly.

Failure to configure this kernel boot parameter would force the Recovery menu to be sent to the Azure Diagnostics and <strong>not</strong> to the Azure Serial Console.

You can obtain access to the <strong>Ubuntu Recovery Menu</strong> by following these steps:

Interrupt the BOOT Process and access <strong>GRUB</strong> menu

<span>Select <em>Advanced Options for Ubuntu</em></span>

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/ubunturec1.png"><img width="671" height="310" class="alignnone size-full wp-image-615" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/ubunturec1.png" /></a>

Select the line displaying <em>(recovery mode)</em> do not press enter but press "<span>e</span>"

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/ubunturec2.png"><img width="671" height="310" class="alignnone wp-image-625" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/ubunturec2.png" /></a>

&nbsp;

Locate the line that will load the kernel and substitute the last parameter "<em><strong>nomodeset</strong></em>" with destination as <em><strong>console=ttyS0</strong></em>

linux       /boot/vmlinuz-4.15.0-1023-azure root=UUID=21b294f1-25bd-4265-9c4e-d6e4aeb57e97 ro recovery<strong> nomodeset</strong>

to

linux       /boot/vmlinuz-4.15.0-1023-azure root=UUID=21b294f1-25bd-4265-9c4e-d6e4aeb57e97 ro recovery <strong>console=ttyS0</strong>

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/ubunturec3.png"><img width="671" height="310" class="alignnone size-full wp-image-635" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/ubunturec3.png" /></a>

Press <strong>Ctrl-x</strong> to start and load the kernel

If all goes well you will see these additional Options which can help perform other recovery options

<a href="https://msdnshared.blob.core.windows.net/media/2018/10/ubunturec4.png"><img width="871" height="310" class="alignnone size-full wp-image-655" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/10/ubunturec4.png" /></a>
<pre></pre>]]></content:encoded>
    </item>
    <item>
      <title>/var/empty/sshd must be owned by root and not group or world-writable</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/var-empty-sshd-must-be-owned-by-root-and-not-group-or-world-writable</link>
      <pubDate>Tue, 30 Jan 2018 07:28:22 GMT</pubDate>
      <dc:creator><![CDATA[Vittorio Franco Libertucci]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=385</guid>
      <description><![CDATA[Problem Statement:
You are attempting to ssh into a Linux VM and are unsuccessful. We have seen...]]></description>
      <content:encoded><![CDATA[<h1>Problem Statement:</h1>
You are attempting to ssh into a Linux VM and are <span lang="EN-GB" style="margin: 0px;color: #333333;font-family: 'Georgia',serif;font-size: 12pt">unsuccessful</span>. We have seen customers modify key sshd configuration files and upon restarting sshd or rebooting the VM connectivity is lost.
<h2>symptoms/errors experienced</h2>
The serial or console log may exhibt errors such as this:

<b>SuSE</b>
/var/empty must be owned by root and not group or world-writable.
startproc: exit status of parent of /usr/sbin/sshd: 255
Failed

&nbsp;

<b>CentOS</b>
Starting sshd: /var/empty/sshd must be owned by root and not group or world-writable.
[FAILED]
<h1><b>Resolution options:</b></h1>
There are a few methods to change the permissions on a Linux file when you don’t have ssh access.

<a href="#option1">1 - Portal</a> - Run a Linux <em>Custom Script</em> into the VM which issues the Linux commands <i>chmod</i> on the file that you need to change via portal.azure.com

<a href="#option2">2 - Manually</a> - Delete the VM, keep the disks, mount OS disk to another temporary VM and update the files on the temporary VM. Recreate the VM from disk

<a href="#option3">3 - Serial Console</a> - Use the Serial Console feature if available for the region your VM is located in

<a href="#option4">4 - CLI</a> - The command Line Interface can also be used to run BASH commands into your VM

&nbsp;
<h2><strong><a name="option1">1. Portal</a></strong></h2>

This option relies on theWAagent process being up. From the serial log or portal check if the agent looks to be up.
<p lang="en-GB">Navigate to <span>Properties</span> of the VM in the portal to see if the WAagent is ok</p>
<p lang="en-GB"><a href="https://msdnshared.blob.core.windows.net/media/2018/01/pic2.png"><img width="686" height="457" class="alignnone wp-image-405" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/01/pic2.png" /></a></p>
Navigate to portal.azure.com and locate you VM's settings. Go to "<strong>Extensions</strong>" -&gt; "<strong>Add</strong>" select "<strong>Custom Script For Linux</strong>"

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/pic1.png"><img width="724" height="334" class="alignnone wp-image-395" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/01/pic1.png" /></a>

Select the "<strong>Create</strong>" button

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/pic3.png"><img width="605" height="623" class="alignnone wp-image-406" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/01/pic3.png" /></a>

Populate the "<strong>Script File</strong>" field with the attached script (download  <a href="https://msdnshared.blob.core.windows.net/media/2018/01/update_perms.txt">update_perms.txt</a> to your local PC/MAC and rename to update_perms.sh)

Note you might have to update the script to reflect your OS - this attached script runs on Red Hat variants.

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/submit_script.png"><img width="649" height="774" class="alignnone wp-image-425" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/01/submit_script.png" /></a>

Notifications will update when the Script has completed - The <strong>STATUS</strong> should display <strong>Success</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/pic4.png"><img width="651" height="539" class="alignnone wp-image-435" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/01/pic4.png" /></a>

&nbsp;

In the guest VM the example script <strong>update_perms.sh</strong> , changes the permissions on the file<strong> /var/empty/sshd</strong> from <strong>777</strong> to <strong>755 </strong>and sets the <strong>owner</strong> and <strong>group</strong> to <strong>root:root </strong>

<span>Wait for script to run. </span>The script will take a few minutes. The Linux Agent receives the request and hands off to the correct extension.

If you are able to ssh back into your VM and are curious to see what happened during executing of the<strong> update_params.sh</strong>, look in the direcory <strong>/var/log/azure/Microsoft.OSTCExtensions.CustomScriptForLinux/&lt;version&gt;</strong> and check the file <strong>extension.log</strong>
<h2><strong><a name="option2">2. Manually attach your VM's disks to a temporary VM</a></strong></h2>
Delete the VM, keep the disks, mount OS disk to another temporary VM and update the files (permissions and ownership) on the temporary VM. Recreate the VM from disk. Instructions on this method can be found <a href="https://blogs.msdn.microsoft.com/linuxonazure/2017/05/07/az-cli-how-to-delete-and-re-deploy-a-vm-from-vhd/">here</a>

&nbsp;
<h2><strong><a name="option3">3. Serial Console</a></strong></h2>
At time of writing, Jan 2018, the feature of "<span>Serial Console</span>" was available only in <span>West Central US</span>

The console will eventually be rolled out to all regions.

This feature allows you to access the VM via a console as if you were "on-prem" or "bare metal" - permitting you to modify files without using Custom Script and without having to delete the VM.<a href="https://msdnshared.blob.core.windows.net/media/2018/01/serial-console.png"></a>

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/serial-console.png"><img width="1638" height="976" class="alignnone size-full wp-image-445" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/01/serial-console.png" /></a>

<h2><strong><a name="option4">4. CLI</a></strong></h2>

The Command Line Interface (CLI) can be used to inject commands into a VM. There are 2 versions of CLI - latest documentation is located <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/extensions-customscript">here</a>

In this example, using the newer CLI v2 version we are resetting the /var/empty/sshd permissions and ownership using the customScript extension via CLI. The sshd service is also restarted.

You will need to replace <em><strong>yourvm</strong> </em>with the name of  <strong>Virtual Machine</strong> and <em><strong>yourrg</strong> </em>with your <strong>Resource Group</strong>
<table width="993">
<tbody>
<tr>
<td><span>vmname=</span><b>yourvm</b><span>;rg=</span><b>yourrg</b><span>;timestamp=`date +%d%Y%H%M%S`;az vm extension set --resource-group $rg --vm-name $vmname --name customScript --publisher Microsoft.Azure.Extensions --settings "{'commandToExecute': 'bash -c \'chmod 755 /var/empty/sshd;chown root:root </span><span>/var/empty/sshd;systemctl start sshd;ps -eaf | grep sshd</span><span>\'','timestamp': "$((timestamp))"}"</span></td>
</tr>
</tbody>
</table>
&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>AZ CLI: How to delete and re-deploy a VM from VHD (unmanaged disk)</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/az-cli-how-to-delete-and-re-deploy-a-vm-from-vhd</link>
      <pubDate>Sun, 07 May 2017 19:17:04 GMT</pubDate>
      <dc:creator><![CDATA[Marco A Bicca]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=375</guid>
      <description><![CDATA[You should be able to use the built-in CLI on the Azure portal, for more details on how to use it,...]]></description>
      <content:encoded><![CDATA[You should be able to use the built-in CLI on the <a target="_blank" href="https://portal.azure.com" rel="noopener">Azure portal,</a> for more details on how to use it, please check: <a target="_blank" href="https://docs.microsoft.com/en-us/azure/cloud-shell/quickstart" rel="noopener">Azure Cloud Shell (quickstart)</a>

If not, you can always install it locally on your workstation or also using docker, for details, please follow the steps described here:<a target="_blank" href="https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-install/" rel="noopener">
Install the Azure CLI</a>

For the steps to work properly, please, make sure you are logged into the Azure CLI:
<code><tt>az login</tt></code>

<strong>NOTE: You will get a code which you then have to type in the box using the link https://aka.ms/devicelogin and proceeding with logging in to your Azure account. Once you go through that you can go back to the prompt.
</strong>

In this example, the following variables will be used:

Resource Group: <strong>ARMGROUP</strong>
Original VM Name: <strong>LinuxVM</strong>
Location: <strong>southcentralus</strong>
NIC Name: <strong>LinuxVM-NIC</strong>
VHD URI: <strong>https://ARMSTORAGE.blob.core.windows.net/vhds/linuxvm.vhd</strong>

If you want to keep some information from the VM before deleting:
<code><tt>az vm show -g ARMGROUP -n LinuxVM &gt; ORIGINAL_VM.txt</tt></code>

Deleting a VM on ARM using the CLI:
<code><tt>az vm delete -g ARMGROUP -n LinuxVM</tt></code>

Recreating the VM from the Original VHD:
<code><tt>az vm create -g ARMGROUP -n LinuxVM --nics LinuxVM-NIC --use-unmanaged-disk --attach-os-disk https://storageaccount.blob.core.windows.net/vhds/linuxvmoriginal2017.vhd --size Standard_D1_V2 -l southcentralus --os-type Linux</tt></code>

After the command is executed you should be able to see the VM on the Azure Portal. You might need to re-enable diagnostics in the particular VM.]]></content:encoded>
    </item>
    <item>
      <title>How to: Deploy a basic wordpress on Ubuntu 16.04 LTS on Azure</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/how-to-deploy-a-basic-wordpress-on-ubuntu-16-04-lts-on-azure</link>
      <pubDate>Mon, 10 Apr 2017 22:16:36 GMT</pubDate>
      <dc:creator><![CDATA[Marco A Bicca]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=366</guid>
      <description><![CDATA[How to deploy a simple Wordpress instance using Ubuntu 16.04 LTS, Nginx, MariaDB and Memcache in...]]></description>
      <content:encoded><![CDATA[How to deploy a simple Wordpress instance using Ubuntu 16.04 LTS, Nginx, MariaDB and Memcache in Azure.

This article is destined to help understand a basic Wordpress deployment on Azure using Ubuntu 16.04 LTS, Nginx with PHP-fpm (for PHP support), MariaDB and Memcache

In this example, we are deploying a Standard_F2S VM with premium disk, 2 CPU’s, 4GB of memory and also a local 7GB SSD (Ephemeral disk) which we will use for swap configuration (4GB).

Considering you already have  your VM deployed with the latest Ubuntu 16.04 LTS, the steps we will describe are:

1) Installing Nginx
2) Installing MariaDB
3) Installing PHP7 / PHP-FPM / Memcache
4) Installing Wordpress
5) Enabling Memcache

<span style="text-decoration: underline"><strong>1) Installing Nginx</strong></span>

<span style="color: #0000ff">sudo apt-get update</span>
<span style="color: #0000ff">sudo apt-get install nginx</span>

You can verify Nginx is correctly listening on port 80 by issuing:

<span style="color: #0000ff">sudo netstat -anp | grep :80</span>
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN  XXXX/nginx –g daemo

This should indicate that Nginx is listening on port 80 on all IP’s

<span style="text-decoration: underline"><strong>2) Installing MariaDB</strong></span>

<span style="color: #0000ff"> sudo apt-get install mariadb-server mariadb-client</span>

You will be asked to provide a password for the mariadb root account, please make sure you note that down.

<span style="color: #ff0000"><strong>NOTE: We highly recommend using the command “sudo mysql_secure_installation” but keep in mind that doing that will add a validation plugin for MySQL passwords which require certain levels of security where you can choose from LOW to STRONG.</strong></span>

<span style="text-decoration: underline"><strong>3) Installing PHP / PHP-FPM / Memcached</strong></span>

<span style="color: #0000ff">sudo apt-get install php7.0-fpm </span>
<span style="color: #0000ff"> sudo apt-get install php-memcache memcached</span>
<span style="color: #0000ff"> sudo apt-get install php7.0-mysql php7.0-curl php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-xml php7.0-xmlrpc</span>

Turn off cgi.fix_pathinfo in php7.0-fpm:

<span style="color: #0000ff"> sudo sed -i.bak 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g'  /etc/php/7.0/fpm/php.ini</span>
<span style="color: #0000ff">sudo systemctl restart php7.0-fpm.service</span>

<span style="text-decoration: underline"><strong>4) Installing Wordpress</strong></span>
<ol>
 	<li>Connect to MySQL and create a database and a user:
<span style="color: #0000ff">mysql -u root -p</span>
<span style="color: #008000">CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;</span>
<span style="color: #008000"> GRANT ALL ON wordpress.* TO ‘wpuser’@’localhost’ IDENTIFIED BY ‘password’;</span>
<span style="color: #008000"> FLUSH PRIVILEGES;</span>
<span style="color: #008000"><span style="color: #008000"> quit

</span></span></li>
 	<li><span style="color: #0000ff">sudo –i</span>
<span style="color: #0000ff"> cd /var/www/html</span>
<span style="color: #0000ff"> curl –O <a href="https://wordpress.org/latest.tar.gz">https://wordpress.org/latest.tar.gz</a></span>
<span style="color: #0000ff"> tar xzvf latest.tar.gz</span>
<span style="color: #0000ff"> cd wordpress</span>
<span style="color: #0000ff"> mv * ..</span>
<span style="color: #0000ff"> rm -rf latest.tar.gz wordpress</span>
<span style="color: #0000ff"> chown –R www-data:www-data /var/www/html</span>
<span style="color: #0000ff"> chmod g+w /var/www/html/wp-content</span>
<span style="color: #0000ff"> chmod g+w /var/www/html/wp-content/themes</span>
<span style="color: #0000ff"><span style="color: #0000ff"> chmod g+w /var/www/html/wp-content/plugins

</span></span></li>
 	<li>Setup the Wordpress configuration file
<span style="color: #0000ff">curl –s https://api.wordpress.com/secret-key/1.1/salt/</span>
copy the content from the output
<span style="color: #0000ff"><span style="color: #0000ff">vi /var/www/html/wp-config-sample.php

</span></span></li>
 	<li>Replace the lines below with the output from the output above:<span style="color: #008000">define('AUTH_KEY', 'put your unique phrase here');</span>
<span style="color: #008000">define('SECURE_AUTH_KEY',  'put your unique phrase here');</span>
<span style="color: #008000">define('LOGGED_IN_KEY',    'put your unique phrase here');</span>
<span style="color: #008000">define('NONCE_KEY',        'put your unique phrase here');</span>
<span style="color: #008000">define('AUTH_SALT',        'put your unique phrase here');</span>
<span style="color: #008000">define('SECURE_AUTH_SALT', 'put your unique phrase here');</span>
<span style="color: #008000">define('LOGGED_IN_SALT',   'put your unique phrase here');</span>
<span style="color: #008000">define('NONCE_SALT',       'put your unique phrase here');
</span></li>
 	<li>Rename the config file:
<span style="color: #0000ff"><span style="color: #0000ff">mv /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

</span></span></li>
 	<li>Edit the file again to configure MySQL and replace the variables with the corresponding values:<span style="color: #008000">define('DB_NAME', <strong>'wordpress'</strong>);</span>
<span style="color: #008000">/** MySQL database username */</span>
<span style="color: #008000">define('DB_USER', <strong>'wpuser'</strong>);</span>
<span style="color: #008000">/** MySQL database password */</span>
<span style="color: #008000">define('DB_PASSWORD', <strong>'password'</strong>);</span></li>
 	<li>Edit Nginx default website configuration:
<span style="color: #008000"><span style="color: #008000">vi /etc/nginx/sites-available/default

</span></span></li>
 	<li>Replace the location / area in the file with the content below, including the other block:</li>
</ol>
<span style="color: #008000"> location / {                </span>
<span style="color: #008000"># try_files $uri $uri/ =404;</span>
<span style="color: #008000">try_files $uri $uri/ /index.php?q=$uri&amp;$args;</span>
<span style="color: #008000"> }</span>

<span style="color: #008000">location ~ \.php$ {                </span>
<span style="color: #008000">try_files $uri =404;</span>
<span style="color: #008000">fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;</span>
<span style="color: #008000">include /etc/nginx/fastcgi_params;</span>
<span style="color: #008000">fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;</span>
<span style="color: #008000"> }</span>

Check to see if nginx configuration is correct and if it is, restart the service:

<span style="color: #0000ff"> nginx –t</span>
<span style="color: #0000ff"> systemctl restart nginx</span>

Assuming you have a Network Security Group with a rule to allow port 80 inbound to the VM, you can then access Wordpress from the external IP of the VM and finish the setup:
http://IP

5) Enabling MemCache

<span style="color: #0000ff">sudo -i</span>
<span style="color: #0000ff">cd /tmp</span>
<span style="color: #0000ff"> wget <a href="https://downloads.wordpress.org/plugin/memcached.3.0.1.zip">https://downloads.wordpress.org/plugin/memcached.3.0.1.zip</a></span>
<span style="color: #0000ff"> apt-get install unzip</span>
<span style="color: #0000ff"> unzip memcached.3.0.1.zip</span>
<span style="color: #0000ff"> cd memcached</span>
<span style="color: #0000ff"> cp object-cache.php /var/www/html/wp-content</span>
<span style="color: #0000ff"> chown www-data:www-data /var/www/html/wp-content/object-cache.php</span>

To check stats in memcached you can use:
<span style="color: #0000ff">watch "echo stats | nc 127.0.0.1 11211"</span>

After finishing the setup through the web interface in Wordpress you should be able to access the website at the <a href="http://IP">http://IP</a> address or the management interface at <a href="http://IP/wp-admin">http://IP/wp-admin</a> using the user/password that you configured during the Wordpress installation.

Happy blogging!]]></content:encoded>
    </item>
    <item>
      <title>How to: Add SWAP to Linux VM's on Azure</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/how-to-add-swap-to-linux-vms-on-azure</link>
      <pubDate>Mon, 10 Apr 2017 21:58:48 GMT</pubDate>
      <dc:creator><![CDATA[Marco A Bicca]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=365</guid>
      <description><![CDATA[Every virtual machine (VM) on Azure has what we call a temporary (ephemeral) disk which is...]]></description>
      <content:encoded><![CDATA[Every virtual machine (VM) on Azure has what we call a<a href="https://docs.microsoft.com/en-us/azure/storage/storage-about-disks-and-vhds-linux"> temporary (ephemeral)</a> disk which is recommended to be used <span style="text-decoration: underline"><strong>ONLY</strong></span> as temporary storage and that includes SWAP files or data that does not need to be available upon a reboot or saved , the data stored in this <span style="text-decoration: underline"><strong>drive will be lost</strong></span>.

<span>To create a swap file in the directory that's defined by the </span><b>ResourceDisk.MountPoint</b><span> parameter, you can update the </span><b>/etc/waagent.conf</b><span> file by setting the following three parameters:

</span><span style="color: #008000">ResourceDisk.Format=y
ResourceDisk.EnableSwap=y
ResourceDisk.SwapSizeMB=<i>xx</i></span>

Where the size is in MB, so for instance, to create a SWAP file of 4GB you could use these lines:

<span style="color: #008000">ResourceDisk.Format=y</span>
<span style="color: #008000">ResourceDisk.EnableSwap=y</span>
<span style="color: #008000">ResourceDisk.SwapSizeMB=<strong><i>4096</i></strong></span>

Before creating a SWAP file using the WAAgent, we also recommend looking at how much space you have available for the temporary disk by checking <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-sizes">this link</a> where on each category of VM we display the local SSD or local HDD storage available.

References:

<a target="_blank" href="https://support.microsoft.com/en-us/help/4010058/how-to-add-a-swap-file-in-linux-azure-virtual-machines">How to add a swap file in Linux Azure virtual machines</a>

<a target="_blank" href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/optimization">Optimizing your Linux VM on Azure</a>]]></content:encoded>
    </item>
    <item>
      <title>How to: Resize Linux osDisk partition on Azure</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/how-to-resize-linux-osdisk-partition-on-azure</link>
      <pubDate>Mon, 03 Apr 2017 21:02:25 GMT</pubDate>
      <dc:creator><![CDATA[Marco A Bicca]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=355</guid>
      <description><![CDATA[Most Linux images on Azure will by default have 30GB size for the osDisk and that is something that...]]></description>
      <content:encoded><![CDATA[Most Linux images on Azure will by default have 30GB size for the osDisk and that is something that you might want to resize moving forward.
<p style="text-align: center"><span style="color: #ff0000"><strong>NOTE: We recommend to store applications and data on a separate data disk not only because of space but also for performance reasons.</strong></span></p>
Resizing the partition is really simple on Azure and we can be done by the following procedure:

a) Stopping and deallocating the VM on the portal or Azure CLI / PowerShell;
b) Editing the disk on the portal and setting the size to the desired value;
c) Updating the partition information within the Linux OS which might be slightly different depending on the partitions and distribution but the concept is very similar , which is basically deleting and recreating the root partition.
<p style="text-align: center"><span style="color: #ff0000"><strong>NOTE: You must create a backup or a snapshot of the VHD prior to the resizing steps , you can use <a href="http://storageexplorer.com">http://storageexplorer.com</a> or also <a href="https://docs.microsoft.com/en-us/azure/storage/storage-use-azcopy">AZCopy</a> once the VM is deallocated when using unmanaged disks.
</strong></span><span style="color: #ff0000"><strong>For managed disks, you can use the Azure Portal to create a snapshot of the disk.</strong></span></p>
Steps to make the required partition changes are listed below per distribution and have been tested in the specific releases listed:

<span style="text-decoration: underline"><strong>For Red Hat 7.3 / CentOS 7.3 and Oracle 7.3:</strong></span>
<p class="p1">1) Login to the VM using SSH, we can check the size of the disk by using:
<code>sudo dmesg | grep -i sda</code></p>
<p class="p1">We should see something similar to the output below (assuming you changed the size to <strong>100GB</strong> on the portal for the disk):
<span style="color: #008000">[    3.100914] sd 2:0:0:0: [sda] 209715200 512-byte logical blocks: (107 GB/<b>100 GiB</b>)
</span>
2) To proceed with the partition resize, we will use:
<code>sudo fdisk /dev/sda</code></p>
<p class="p1">type: <span style="color: #0000ff"><code>p</code></span>
this will show both partitions /dev/sda1 and /dev/sda2 which are basically partitions 1 and 2</p>
<p class="p1">type: <span style="color: #0000ff"><code>d</code></span> then <span style="color: #0000ff"><code>2</code></span> (to delete partition 2)
type: <span style="color: #0000ff"><code>n</code></span> then <span style="color: #0000ff"><code>p</code></span>, <span style="color: #0000ff"><code>2</code></span> (to recreate partition 2) you can accept the default values
type: <span style="color: #0000ff"><code>w</code></span> (to save the new partition)
type: <span style="color: #0000ff"><code>q</code></span> (to exit fdisk)
<span style="color: #0000ff"><code>sudo reboot</code></span> (to reboot the VM so the partition is updated)</p>
<p class="p1">3) To finalize the resize, after the reboot, execute the command:</p>
<p class="p1">For Red Hat 7.3 and CentOS 7.3:
<span style="color: #0000ff"><code>sudo xfs_growfs /dev/sda2</code></span></p>
<p class="p1">For Oracle 7.3:
<span style="color: #0000ff"><code>sudo btrfs filesystem resize max /</code></span></p>
<p class="p1">4) Use the command: <span style="color: #0000ff"><code>df -h</code></span> to verify its size:
<span style="color: #008000">Filesystem      Size  Used Avail Use% Mounted on</span>
<span style="color: #008000">/dev/sda2       <b>100G</b>  1.6G   98G   2% /</span></p>
<span style="text-decoration: underline"><strong>For Ubuntu 16.04 LTS:</strong></span>

No extra steps are necessary, simply deallocating the VM, changing the size on the portal and starting the VM backup will work. You can verify the size after the VM is up by using:
<span style="color: #0000ff"><code>df -h</code>
<span style="color: #008000">Filesystem Size Used Avail Use% Mounted on</span>
<span style="color: #008000">/dev/sda1 97G 1.4G 96G 2% /</span>
</span>

<span style="text-decoration: underline"><strong>For Debian 8:</strong></span>
<p class="p1">1) Login to the VM using SSH, we can check the size of the disk by using:
<span style="color: #0000ff"><code>sudo dmesg | grep -i sda</code></span></p>
<p class="p1">We should see something similar to the output below (assuming you changed the size to <strong>100GB</strong> on the portal for the disk):
<span style="color: #008000">[    3.100914] sd 2:0:0:0: [sda] 209715200 512-byte logical blocks: (107 GB/<b>100 GiB</b>)</span></p>
<span style="color: #000000">2) To proceed with the partition resize, we will use:</span><span style="color: #0000ff">
<code>sudo fdisk /dev/sda</code></span>
<p class="p1">type: <span style="color: #0000ff"><code>p</code></span>
this will show partition /dev/sda1</p>
type: <span style="color: #0000ff"><code>d</code></span>
type: <span style="color: #0000ff"><code>n</code></span> then <span style="color: #0000ff"><code>p</code><span style="color: #000000">,</span> <code>1</code></span> (to recreate partition 1) you can accept the default values
<strong>NOTE:</strong> if you receive a message about deleting or keeping a signature on the disk, just answer <strong><code>N</code></strong>
type: <span style="color: #0000ff"><code>w</code></span> (to save the new partition)
type: <span style="color: #0000ff"><code>q</code></span> (to exit fdisk)
<span style="color: #0000ff"><code>sudo reboot</code></span> (to reboot the VM so the partition is updated)

<span style="color: #0000ff"><span style="color: #000000">3) To finalize the resize, after the reboot, execute the command:</span>
<code>resize2fs /dev/sda1</code></span>

<span>4) Use the command: </span><span style="color: #0000ff"><code>df -h</code></span><span> to verify its size:</span>
<span style="color: #008000">Filesystem Size Used Avail Use% Mounted on</span>
<span style="color: #008000">/dev/sda1 99G 698M 94G 1% /
</span>

<span style="text-decoration: underline"><strong>For SUSE 12 SP2 (Premium):</strong></span>
<p class="p1">1) Login to the VM using SSH, we can check the size of the disk by using:
<span style="color: #0000ff"><code>sudo dmesg | grep -i sda</code></span></p>
<p class="p1">We should see something similar to the output below (assuming you changed the size to <strong>100GB</strong> on the portal for the disk):
<span style="color: #008000">[    3.100914] sd 2:0:0:0: [sda] 209715200 512-byte logical blocks: (107 GB/<b>100 GiB</b>)</span></p>
<span style="color: #000000">2) To proceed with the partition resize, we will use:</span><span style="color: #0000ff">
<code>sudo fdisk /dev/sda</code></span>

type: <span style="color: #0000ff"><code>p</code>
</span>this will show both partitions /dev/sda1 and /dev/sda2 which are basically partitions 1 and 2
<p class="p1">type: <span style="color: #0000ff"><code>d</code></span> then <span style="color: #0000ff"><code>2</code></span> (to delete partition 2)
type: <span style="color: #0000ff"><code>n</code></span> then <span style="color: #0000ff"><code>p</code></span><span>, </span><span style="color: #0000ff"><code>2</code></span> (to recreate partition 2) you can accept the default values
type: <span style="color: #0000ff"><code>w</code></span> (to save the new partition)
type: <span style="color: #0000ff"><code>q</code></span> (to exit fdisk)
<span style="color: #0000ff"><code>sudo reboot</code></span> (to reboot the VM so the partition is updated)</p>
<p class="p1">3) To finalize the resize, after the reboot, execute the command:
<span style="color: #0000ff"><code>resize2fs /dev/sda2</code></span></p>
<p class="p1">4) Use the command: <span style="color: #0000ff"><code>df -h</code></span> to verify its size:
<span style="color: #008000">Filesystem Size Used Avail Use% Mounted on</span>
<span style="color: #008000">/dev/sda2 98G 1.2G 92G 2% /</span></p>
<span style="text-decoration: underline"><strong>
For CoreOS (Stable):</strong></span>

<span>No extra steps are necessary, simply deallocating the VM, changing the size on the portal and starting the VM backup will work. CoreOS has a few extra partitions and the extra space will be added to the root partition (usually /dev/sda9).</span>]]></content:encoded>
    </item>
    <item>
      <title>Azure Linux Extensions: Custom Script for Linux</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/extensions-custom-script-for-linux</link>
      <pubDate>Sun, 12 Feb 2017 16:45:03 GMT</pubDate>
      <dc:creator><![CDATA[Marco A Bicca]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=315</guid>
      <description><![CDATA[You have probably seen some extensions that are available on Azure, some of them listed/documented...]]></description>
      <content:encoded><![CDATA[You have probably seen some extensions that are available on Azure, some of them listed/documented here:
<a target="_blank" href="https://github.com/Azure/azure-linux-extensions" rel="noopener">Azure Linux Extensions</a>

In this article, we will cover a few examples that you can use with the "Custom Script for Linux" extension.

This extension basically allows you to run a script inside a Linux VM, so as long as the Linux Agent (WAAGENT) is working correctly you should be able to use this extension without problems.

You can run this extension from the portal , so on your Azure Resource Manager (ARM) VM, you can access that by clicking:

<strong>VM Name &gt; Extensions &gt; Add &gt; Select "Custom Script for Linux" &gt; Create</strong>

<a href="https://msdnshared.blob.core.windows.net/media/2017/02/Screen-Shot-2017-02-12-at-4.44.18-PM.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/02/Screen-Shot-2017-02-12-at-4.44.18-PM-300x73.png" alt="screen-shot-2017-02-12-at-4-44-18-pm" width="300" height="73" class="alignnone size-medium wp-image-325" /></a>

After that all you will need is the upload the script you want to run and then change the "Command" line to the appropriate one to execute that file, so in this case we have created a bash script called <strong>adduser.sh</strong> , in this case the command line would be changed to: <strong>bash adduser.sh </strong>like in the screenshot below:

<a href="https://msdnshared.blob.core.windows.net/media/2017/02/Screen-Shot-2017-02-12-at-1.37.27-PM.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/02/Screen-Shot-2017-02-12-at-1.37.27-PM-1024x424.png" alt="screen-shot-2017-02-12-at-1-37-27-pm" width="879" height="364" class="alignnone wp-image-316 size-large" /></a>

Click <strong>OK</strong> and the script will start to be deployed and executed inside your Linux VM.

In most cases, you will need to be familiar with shell scripting in Linux and also we highly recommend testing the script extensively before you run it and keep in mind to create a script that will handle any prompts or questions, since you won't have access to it while it gets executed.

As a few simple examples, let's assume you want to deal with any of these issues:
1) Disabling the UFW firewall on a Ubuntu Linux VM that is blocking access to the VM
2) Fixing wrong permissions on SSH Host Keys which are not allowing you to login to a given VM
3) Manually adding a new account to a VM when using the portal is not working properly for some reason

<span style="text-decoration: underline"><strong>1) Disabling the UFW firewall on a Ubuntu Linux VM</strong></span>

Create an empty text file called "disableufw.sh" and add these lines into it:

<code>#!/bin/bash</code>
<code>ufw disable</code>
<code>logger "ufw disabled by custom script"</code>

This script will basically run the command ufw disable which disables the Ubuntu firewall and it will also log a message "ufw disabled by custom script" in the system logs using the logger command.

<span style="text-decoration: underline"><strong>2) Fixing wrong permissions on SSH Host Key files</strong></span>

Create an empty text file called "fixsshkeys.sh" and add these lines into it:

<code>#!/bin/bash
chmod 640 /etc/ssh/ssh_host_ecdsa_key ssh_host_ed25519_key
chmod 644 /etc/ssh/ssh_host_ecdsa_key.pub ssh_host_ed25519_key.pub ssh_host_rsa_key.pub
chmod 600 /etc/ssh/ssh_host_rsa_key
logger "SSH keys permission reset successfully"</code>

This script will reset the the file permissions on the specified files above to its defaults.

<span style="text-decoration: underline"><strong>3) Manually adding a new account with sudo access and SSH Key.</strong></span>

Create an empty text file called "adduser.sh" and add these lines into it:

<span style="text-decoration: underline">For CentOS / RHEL and Oracle distributions</span>

<code>#!/bin/bash
# Make sure you use a username that is lowercase.
USERNAME="rescue"
# Creates the user account using the name provided
useradd -m $USERNAME
logger "Azure custom script - adding $USERNAME"
# Creates SSH configuration folder for user.
mkdir -p /home/$USERNAME/.ssh
logger "Azure custom script - creating SSH configuration folder"
# Adding the SSH-Key data to the authorized_keys file for the given user.
# Replace the content "SSH-PUBLIC-KEY" with the public key for your user.
echo SSH-PUBLIC-KEY &gt;&gt; /home/$USERNAME/.ssh/authorized_keys
logger "Azure custom script - adding SSH key for user $USERNAME"
# Adding user account to sudoers
echo "$USERNAME ALL = (ALL) ALL" &gt; /etc/sudoers.d/$USERNAME</code>

<span style="text-decoration: underline">For SUSE distributions</span>

<code>#!/bin/bash
# Input your desired password# Make sure you use a username that is lowercase.
USERNAME="rescue"
# Creates the user account using the name provided
useradd -m $USERNAME -G users
logger "Azure custom script - adding $USERNAME"
# Creates SSH configuration folder for user
mkdir -p /home/$USERNAME/.ssh
logger "Azure custom script - creating SSH configuration folder"
# Adding the SSH-Key data to the authorized_keys file for the given user.
# Replace the content "SSH-PUBLIC-KEY" with the public key for your user.
echo "SSH-PUBLIC-KEY" &gt;&gt; /home/$USERNAME/.ssh/authorized_keys
logger "Azure custom script - adding SSH key for user $USERNAME"
# Adding user account to sudoers.
echo "$USERNAME ALL = (ALL) NOPASSWD: ALL" &gt; /etc/sudoers.d/$USERNAME
logger "Azure custom script - creating $USERNAME sudoers file"</code>

<span style="text-decoration: underline">For Ubuntu / Debian distributions</span>

<code>#!/bin/bash
# Make sure you use a username that is lowercase.
USERNAME="rescue"
# Creates the user account using the name provided.
useradd -m -G sudo $USERNAME
logger "Azure custom script - adding $USERNAME"
# Creates SSH configuration folder for user.
mkdir -p /home/$USERNAME/.ssh
logger "Azure custom script - creating SSH configuration folder"
# Adding the SSH-Key data to the authorized_keys file for the given user.
# Replace the content "SSH-PUBLIC-KEY" with the public key for your user.
echo "SH-PUBLIC-KEY" &gt;&gt; /home/$USERNAME/.ssh/authorized_keys
logger "Azure custom script - adding SSH key for user $USERNAME"</code>

The scripts above you basically create an account named "rescue" and it will use the SSH public key added to login, just make sure you replace the field "SSH-PUBLIC-KEY" with the contents of your SSH public key.

For more reference around the extension and other ways to execute it such as using Azure PowerShell or Azure CLI, you can check this page:
<a target="_blank" href="https://github.com/Azure/azure-linux-extensions/tree/master/CustomScript" rel="noopener">Custom Script for Linux</a>]]></content:encoded>
    </item>
    <item>
      <title>Linux Recovery: Fixing non-boot issues related to Kernel problems using chroot</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/linux-recovery-fixing-non-boot-issues-related-to-kernel-problems-using-chroot</link>
      <pubDate>Sun, 09 Oct 2016 21:19:30 GMT</pubDate>
      <dc:creator><![CDATA[Marco A Bicca]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=295</guid>
      <description><![CDATA[In a previous article, it was described how to manually fix kernel related issues that could cause a...]]></description>
      <content:encoded><![CDATA[In a previous article, it was described how to manually fix kernel related issues that could cause a Linux VM to not boot properly.

There is also an option where you can use steps to use <a target="_blank" href="http://blogs.msdn.microsoft.com/linuxonazure/2016/08/16/linux-recovery-using-chroot-steps-to-recover-vms-that-are-not-accessible/">CHROOT</a> and then use tools to automatically fix these same issues without the need to manually edit files.

Assuming you have your system ready after going to the steps described in <a target="_blank" href="http://blogs.msdn.microsoft.com/linuxonazure/2016/08/16/linux-recovery-using-chroot-steps-to-recover-vms-that-are-not-accessible/">this article</a>, meaning you just went through the sequence of steps and you finally executed:
<span style="color: #0000ff">chroot /rescue</span>

For a quick example, let's assume you had a non-boot scenario after updating the kernel on a CentOS 7.2 to version:
<strong>3.10.0-327.36.1.el7.x86_64</strong>

You can quickly see which kernels you still have installed by running:
<span style="color: #0000ff">cd /rescue/boot/grub2/</span>
<span style="color: #0000ff">grep -i linux16 grub.cfg</span>

The output should be similar to:
<span style="color: #008000">linux16 /boot/<strong>vmlinuz-3.10.0-327.36.1.el7.x86_64</strong> root=UUID=3b5d406c-7fa6-458f-815c-9684bb9fe148 ro console=tty1 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300 net.ifnames=0 LANG=en_US.UTF-8</span>
<span style="color: #008000"> linux16 /boot/<strong>vmlinuz-3.10.0-327.18.2.el7.x86_64</strong> root=UUID=3b5d406c-7fa6-458f-815c-9684bb9fe148 ro console=tty1 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300 net.ifnames=0</span>

Which means you have the current one <strong>36.1</strong> as well as the <strong>18.2</strong> installed.

You can then easily roll back to 18.2 by executing:
<span style="color: #0000ff">grep -i menuentry grub.cfg</span>

<span style="color: #000000">Output should be similar to:</span>
<span style="color: #008000">menuentry '<strong>CentOS Linux (3.10.0-327.36.1.el7.x86_64) 7 (Core)</strong>' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.18.2.el7.x86_64-advanced-3b5d406c-7fa6-458f-815c-9684bb9fe148' {</span>
<span style="color: #008000">menuentry '<strong>CentOS Linux (3.10.0-327.18.2.el7.x86_64) 7 (Core)</strong>' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.18.2.el7.x86_64-advanced-3b5d406c-7fa6-458f-815c-9684bb9fe148' {</span>

<span style="color: #000000">With that you can then execute:
<span style="color: #0000ff">grub2-editenv list
</span>This will display:
<span style="color: #008000">saved_entry=CentOS Linux (3.10.0-327.36.1.el7.x86_64) 7 (Core)</span></span>

<span style="color: #0000ff">grub2-set-default "CentOS Linux (3.10.0-327.18.2.el7.x86_64) 7 (Core)"</span>

This will change the kernel back to the 18.2 version, now after this you can safely go through the final steps to exit the CHROOT environment:

<span>The steps to exit the chroot environment and umount everything are:</span>

<span style="color: #0000ff">exit
cd /
umount /rescue/proc/
umount /rescue/sys/
umount /rescue/dev/pts
umount /rescue/dev/</span>

<span style="color: #000000">For Debian and Ubuntu distributions you will need to umount (run):</span>

<span style="color: #0000ff">umount /rescue/run/
umount /rescue</span>

The finally you can detach the disk and use one of our articles to rebuild the VM using either PowerShell or Azure CLI:
<a target="_blank" href="https://blogs.msdn.microsoft.com/linuxonazure/2016/07/21/azure-powershell-how-to-delete-and-re-deploy-a-vm-from-vhd/"><span>Azure PowerShell: How to delete and re-deploy a VM from VHD<span>
</span></span></a><a target="_blank" href="https://blogs.msdn.microsoft.com/linuxonazure/2016/07/21/azure-cli-how-to-delete-and-re-deploy-a-vm-from-vhd/"><span>Azure CLI: How to delete and re-deploy a VM from VHD</span></a>]]></content:encoded>
    </item>
    <item>
      <title>Linux Recovery: Manually fixing non-boot issues related to Kernel problems</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/linux-recovery-manually-fixing-non-boot-issues-related-to-kernel-problems</link>
      <pubDate>Sun, 09 Oct 2016 20:37:23 GMT</pubDate>
      <dc:creator><![CDATA[Marco A Bicca]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=285</guid>
      <description><![CDATA[You have a Linux VM that had kernel changes applied recently such as a kernel upgrade and is no...]]></description>
      <content:encoded><![CDATA[<p style="text-align: justify">You have a Linux VM that had kernel changes applied recently such as a kernel upgrade and is no longer starting up properly due to kernel errors during the boot process.</p>
<p style="text-align: justify">Kernel messages will vary; some examples could be:</p>

<ul style="text-align: justify">
 	<li>no root device found,</li>
 	<li>kernel timeouts,</li>
 	<li>null pointer,</li>
 	<li>kernel panic errors.</li>
</ul>
<p style="text-align: justify">Most of the time the recovery steps will be similar requiring that you need to either install a newer kernel or simply roll-back to the previous version manually.</p>
<p style="text-align: justify"><strong><u>Example of error messages that you can see</u></strong></p>
<p style="text-align: justify"><strong>A) No root device found</strong></p>
<p style="text-align: justify"><span style="color: #008000">dracut Warning: No root device "block:/dev/disk/by-uuid/6d089360-3e14-401d-91d0-378f3fd09332" found</span>
<span style="color: #008000">dracut Warning: Boot has failed. To debug this issue add "rdshell" to the kernel command line.</span>
<span style="color: #008000">dracut Warning: Signal caught!</span>
<span style="color: #008000">Kernel panic - not syncing: Attempted to kill init!</span>
<span style="color: #008000">Pid: 1, comm: init Not tainted 2.6.32-504.12.2.el6.x86_64 #1</span>
<span style="color: #008000">Call Trace:</span>
<span style="color: #008000">[&lt;ffffffff8152933c&gt;] ? panic+0xa7/0x16f</span>
<span style="color: #008000">[&lt;ffffffff8107a5f2&gt;] ? do_exit+0x862/0x870</span>
<span style="color: #008000">[&lt;ffffffff8118fa25&gt;] ? fput+0x25/0x30</span>
<span style="color: #008000">[&lt;ffffffff8107a658&gt;] ? do_group_exit+0x58/0xd0</span>
<span style="color: #008000">[&lt;ffffffff8107a6e7&gt;] ? sys_exit_group+0x17/0x20</span>
<span style="color: #008000">[&lt;ffffffff8100b072&gt;] ? system_call_fastpath+0x16/0x1b</span></p>
<p style="text-align: justify"><strong>B) Example of a kernel timeout error</strong></p>
<p style="text-align: justify"><span style="color: #008000">INFO: task swapper:1 blocked for more than 120 seconds.</span>
<span style="color: #008000">Not tainted 2.6.32-504.8.1.el6.x86_64 #1</span>
<span style="color: #008000">"echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.</span>
<span style="color: #008000">swapper       D 0000000000000000     0     1      0 0x00000000</span>
<span style="color: #008000">ffff88010f64fde0 0000000000000046 ffff88010f64fd50 ffffffff81074f95</span>
<span style="color: #008000">0000000000005c2f ffffffff8100bb8e ffff88010f64fe50 0000000000100000</span>
<span style="color: #008000">0000000000000002 00000000fffb73e0 ffff88010f64dab8 ffff88010f64ffd8</span>
<span style="color: #008000">Call Trace:</span>
<span style="color: #008000">[&lt;ffffffff81074f95&gt;] ? __call_console_drivers+0x75/0x90</span>
<span style="color: #008000">[&lt;ffffffff8100bb8e&gt;] ? apic_timer_interrupt+0xe/0x20</span>
<span style="color: #008000">[&lt;ffffffff81075d51&gt;] ? vprintk+0x251/0x560</span>
<span style="color: #008000">[&lt;ffffffff8152a862&gt;] schedule_timeout+0x192/0x2e0</span>
<span style="color: #008000">[&lt;ffffffff810874f0&gt;] ? process_timeout+0x0/0x10</span>
<span style="color: #008000">[&lt;ffffffff8152a9ce&gt;] schedule_timeout_uninterruptible+0x1e/0x20</span>
<span style="color: #008000">[&lt;ffffffff81089650&gt;] msleep+0x20/0x30</span>
<span style="color: #008000">[&lt;ffffffff81c2a571&gt;] prepare_namespace+0x30/0x1a9</span>
<span style="color: #008000">[&lt;ffffffff81c2992a&gt;] kernel_init+0x2e1/0x2f7</span>
<span style="color: #008000">[&lt;ffffffff8100c20a&gt;] child_rip+0xa/0x20</span>
<span style="color: #008000">[&lt;ffffffff81c29649&gt;] ? kernel_init+0x0/0x2f7</span>
<span style="color: #008000">[&lt;ffffffff8100c200&gt;] ? child_rip+0x0/0x20</span></p>
<p style="text-align: justify"><strong>C) Example of a kernel null point error</strong></p>
<p style="text-align: justify"><span style="color: #008000">Pid: 242, comm: async/1 Not tainted 2.6.32-504.12.2.el6.x86_64 #1</span>
<span style="color: #008000">Call Trace:</span>
<span style="color: #008000">[&lt;ffffffff81177468&gt;] ? kmem_cache_create+0x538/0x5a0</span>
<span style="color: #008000">[&lt;ffffffff8152aede&gt;] ? mutex_lock+0x1e/0x50</span>
<span style="color: #008000">[&lt;ffffffff81370424&gt;] ? attribute_container_add_device+0x104/0x150</span>
<span style="color: #008000">[&lt;ffffffffa009c1de&gt;] ? storvsc_device_alloc+0x4e/0xa0 [hv_storvsc]</span>
<span style="color: #008000">[&lt;ffffffff8138a1dc&gt;] ? scsi_alloc_sdev+0x1fc/0x280</span>
<span style="color: #008000">[&lt;ffffffff8138a739&gt;] ? scsi_probe_and_add_lun+0x4d9/0xe10</span>
<span style="color: #008000">[&lt;ffffffff8128e62d&gt;] ? kobject_set_name_vargs+0x6d/0x70</span>
<span style="color: #008000">[&lt;ffffffff8152aede&gt;] ? mutex_lock+0x1e/0x50</span>
<span style="color: #008000">[&lt;ffffffff81370424&gt;] ? attribute_container_add_device+0x104/0x150</span>
<span style="color: #008000">[&lt;ffffffff81367ae9&gt;] ? get_device+0x19/0x20</span>
<span style="color: #008000">[&lt;ffffffff8138b440&gt;] ? scsi_alloc_target+0x2d0/0x300</span>
<span style="color: #008000">[&lt;ffffffff8138b661&gt;] ? __scsi_scan_target+0x121/0x740</span>
<span style="color: #008000">[&lt;ffffffff8138bd07&gt;] ? scsi_scan_channel+0x87/0xb0</span>
<span style="color: #008000">[&lt;ffffffff8138bde0&gt;] ? scsi_scan_host_selected+0xb0/0x190</span>
<span style="color: #008000">[&lt;ffffffff8138bf51&gt;] ? do_scsi_scan_host+0x91/0xa0</span>
<span style="color: #008000">[&lt;ffffffff8138c13c&gt;] ? do_scan_async+0x1c/0x150</span>
<span style="color: #008000">[&lt;ffffffff810a7086&gt;] ? async_thread+0x116/0x2e0</span>
<span style="color: #008000">[&lt;ffffffff81064b90&gt;] ? default_wake_function+0x0/0x20</span>
<span style="color: #008000">[&lt;ffffffff810a6f70&gt;] ? async_thread+0x0/0x2e0</span>
<span style="color: #008000">[&lt;ffffffff8109e66e&gt;] ? kthread+0x9e/0xc0</span>
<span style="color: #008000">[&lt;ffffffff8100c20a&gt;] ? child_rip+0xa/0x20</span>
<span style="color: #008000">[&lt;ffffffff8109e5d0&gt;] ? kthread+0x0/0xc0</span>
<span style="color: #008000">[&lt;ffffffff8100c200&gt;] ? child_rip+0x0/0x20</span>
<span style="color: #008000">BUG: unable to handle kernel NULL pointer dereference at 0000000000000008</span>
<span style="color: #008000">IP: [&lt;ffffffffa009c0a0&gt;] storvsc_device_destroy+0x20/0x50 [hv_storvsc]</span>
<span style="color: #008000">PGD 0</span></p>
<p style="text-align: justify"><strong>D) Example of a Kernel Panic error</strong></p>
<p style="text-align: justify"><span style="color: #008000">Invalid op code: 0000 [#2] [11427.908676] --- end trace 61a458bb863d7f0f ]---</span>
<span style="color: #008000">Kernel panic - not syncing: attempted to kill the idle task!</span></p>
<p style="text-align: justify"><strong>Recovering from these issues</strong></p>
<p style="text-align: justify">In all cases we will need to go through the normal procedure of deleting the affected Linux VM, keep its OSDisk, attach it to a new VM running the same version as the impacted VM or at least the same distribution and then, depending on the issue we will have two options of repairing which are described below.</p>
<p style="text-align: justify">1) Simply editing configuration files to roll-back the kernel and boot from a previous working setup, Linux boot loaders usually have more than one entry which defines which kernel to use for booting, that usually gets updated every time you perform an upgrade to reference the new installed kernel.</p>
<p style="text-align: justify">2) Go through a <a href="http://blogs.msdn.microsoft.com/linuxonazure/2016/08/16/linux-recovery-using-chroot-steps-to-recover-vms-that-are-not-accessible/">CHROOT</a> process, by attaching the impacting VM OSDisk to a temporary new VM and running known tools (apt-get/yum/zypper) to install/reinstall a kernel. This is the easiest and usually fastest way to repair since you do not have to manually edit files.</p>
<p style="text-align: justify">Example, a Linux VM running CentOS 6.6 has loaded a kernel version 2.6.32-504.16.2.el6.x86_64, this can be seen with the command:
<span style="color: #0000ff">uname -a</span></p>
<p style="text-align: justify"><strong>Linux vfldev 2.6.32-504.16.2.el6.x86_64 #1 SMP Wed Apr 22 06:48:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux</strong></p>
<p style="text-align: justify">The boot loader configuration file that knows of the kernel version to load, in the case for CentOS the file is /boot/grub/grub.conf and on newer versions /boot/grub2/grub.cfg</p>
<p style="text-align: justify">Looking closer at the grub.conf we can see that the current loaded version is referenced in the first 4 lines highlighted in blue.</p>
<p style="text-align: justify">1) Title &gt; Simply the title that shows up in the menu (not applicable in cloud environments)
2) The root disk
3) The kernel command line being loaded at boot time and its parameters
4) The path for the initrd file that will be loaded to boot and usually matches the kernel too</p>
<p style="text-align: justify">An example of grub.conf with reference to 4 Linux versions:</p>
<p style="text-align: justify"><strong><span style="color: #008000">title CentOS (2.6.32-504.16.2.el6.x86_64)</span></strong>
<span style="color: #008000">root (hd0,0)</span>
<span style="color: #008000">kernel /boot/vmlinuz-2.6.32-504.16.2.el6.x86_64 ro root=UUID=6d089360-3e14-401d-91d0-378f3fd09332 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM numa=off console=ttyS0 earlyprintk=ttyS0 rootdelay=300 crashkernel=auto</span>
<span style="color: #008000">initrd /boot/initramfs-2.6.32-504.16.2.el6.x86_64.img</span></p>
<p style="text-align: justify"><strong><span style="color: #008000">title CentOS (2.6.32-504.12.2.el6.x86_64)</span></strong>
<span style="color: #008000">root (hd0,0)</span>
<span style="color: #008000">kernel /boot/vmlinuz-2.6.32-504.12.2.el6.x86_64 ro root=UUID=6d089360-3e14-401d-91d0-378f3fd09332 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM numa=off console=ttyS0 earlyprintk=ttyS0 rootdelay=300 crashkernel=auto</span>
<span style="color: #008000">initrd /boot/initramfs-2.6.32-504.12.2.el6.x86_64.img</span></p>
<p style="text-align: justify"><strong><span style="color: #008000">title CentOS (2.6.32-504.8.1.el6.x86_64)</span></strong>
<span style="color: #008000">root (hd0,0)</span>
<span style="color: #008000">kernel /boot/vmlinuz-2.6.32-504.8.1.el6.x86_64 ro root=UUID=6d089360-3e14-401d-91d0-378f3fd09332 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM numa=off console=ttyS0 earlyprintk=ttyS0 rootdelay=300 crashkernel=auto</span>
<span style="color: #008000">initrd /boot/initramfs-2.6.32-504.8.1.el6.x86_64.img</span></p>
<p style="text-align: justify"><strong><span style="color: #008000">title CentOS (2.6.32-431.29.2.el6.x86_64)</span></strong>
<span style="color: #008000">root (hd0,0)</span>
<span style="color: #008000">kernel /boot/vmlinuz-2.6.32-431.29.2.el6.x86_64 ro root=UUID=6d089360-3e14-401d-91d0-378f3fd09332 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM numa=off console=ttyS0 earlyprintk=ttyS0 rootdelay=300</span>
<span style="color: #008000">initrd /boot/initramfs-2.6.32-431.29.2.el6.x86_64.img</span></p>
<p style="text-align: justify">To change the boot loader (grub.conf) and force the Linux VM to load a different kernel manual intervention is required, below you can find steps to do that change.</p>
<p style="text-align: justify"><strong>NOTE</strong>: We highly recommend making a backup of the VHD from the inaccessible VM before going through the steps for the recovery process, you can make a backup of the VHD by using Microsoft Storage Explorer, available at <a href="http://storageexplorer.com/">http://storageexplorer.com</a></p>
<p style="text-align: justify"><strong>A</strong> = Original VM (Inaccessible VM)
<strong>B</strong> = New VM (New Recovery VM)</p>

<ol style="text-align: justify">
 	<li>Stop VM  <strong><em>A </em></strong>via Azure Portal</li>
 	<li>For Resource Manager VM, we recommend to save the current VM information before deleting
<ul>
 	<li>Azure CLI:                  azure vm show ResourceGroupName LinuxVmName &gt; ORIGINAL_VM.txt</li>
 	<li>Azure PowerShell:     Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName</li>
</ul>
</li>
 	<li>Delete VM <strong><em>A </em></strong>BUT select “<strong>keep the attached disks</strong>”
<strong>NOTE:</strong> The option to keep the attached disks is only available for classic deployments, for Resource Manager deleting a VM will always keep its OSDisk by default.</li>
 	<li>Once the lease is cleared, attach the Data Disk from <strong><em>A </em></strong>to VM <strong><em>B </em></strong>via the Azure Portal, Virtual Machines, Select “<strong>B</strong>”, <strong>Attach Disk</strong></li>
 	<li>On VM “<strong><em>B</em></strong>” eventually the disk will attach and you can then mount it.</li>
 	<li>Locate the drive name to mount, on VM “<strong><em>B</em></strong>” look in relevant log file note each Linux is slightly different.
<ul>
 	<li><span style="color: #0000ff">grep SCSI /var/log/kern.log</span> <strong>(ubuntu, debian)
</strong><span style="color: #0000ff">grep SCSI /var/log/messages</span> <strong>(centos, suse, oracle, redhat)</strong></li>
</ul>
</li>
 	<li>Mount the attached disk onto mountpoint /rescue
<span style="color: #0000ff">df -h</span>
<span style="color: #0000ff">mkdir /rescue</span>
<strong>For Red Hat 7.2+
</strong><span style="color: #0000ff">mount -o nouuid /dev/sdc2 /rescue</span>
<strong>For CentOS 7.2+</strong>
<span style="color: #0000ff">mount -o nouuid /dev/sdc1 /rescue</span>
<strong>For Debian 8.2+, Ubuntu 16.04+, SUSE 12 SP4+
</strong><span style="color: #0000ff">mount /dev/sdc1 /rescue</span></li>
 	<li>Mount the OS disk on /rescue on VM<strong> B</strong>, and modify the /rescue/boot/grub.conf file.<strong>Modified grub.conf</strong></li>
</ol>
<p style="text-align: justify"><span style="color: #0000ff">#title CentOS (2.6.32-504.16.2.el6.x86_64)
#root (hd0,0)
#kernel /boot/vmlinuz-2.6.32-504.16.2.el6.x86_64 ro root=UUID=6d089360-3e14-401d-91d0-378f3fd09332 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM numa=off console=ttyS0 earlyprintk=ttyS0 rootdelay=300 crashkernel=auto
#initrd /boot/initramfs-2.6.32-504.16.2.el6.x86_64.img</span></p>
<p style="text-align: justify">Another item to check is if the device specified by the UUID value from the boot loader file, grub.conf exists.</p>
<p style="text-align: justify">Taking our example of the OS disk mounted on /rescue look in /rescue/dev/disk/by-uuid</p>
<p style="text-align: justify">We can clearly see that there is a corresponding UUID file found on disk highlighted in pink that is referenced in the grub.conf file</p>
<p style="text-align: justify">The file is actually a symbolic link as denoted by the l at the start of the attributes lrwxrwxrwx and is pointing to the OSDisk sda1</p>
<p style="text-align: justify">Even if this file is missing, testing deletion of the symbolic link is recreated when the system starts up.</p>
<p style="text-align: justify">It is possible to create symbolic links manually you would need to know if sda1 is your boot device and the corresponding UUID.</p>
<p style="text-align: justify"><span style="color: #0000ff">cd /rescue/dev/disk/by-uuid</span>
<span style="color: #0000ff"> ln -s ../../sda1 6d089360-3e14-401d-91d0-378f3fd09332</span></p>
<p style="text-align: justify">The sda1 file is known as a block device in Linux seen by the ls output and denoted by a b in the attributes <strong>brw-rw----</strong> or by running the file command.</p>
<p style="text-align: justify">You could also check that this file is present again testing on a centos 6.5 this file also gets recreated if missing.</p>
<p style="text-align: justify"><span style="color: #0000ff">cd /rescue/dev/disk/by-uuid</span>
<span style="color: #0000ff"> ls -ltr ../../sda1</span>
<span style="color: #0000ff"> brw-rw---- 1 root disk 8, 1 Apr 30 14:37 ../../sda1</span></p>
<p style="text-align: justify"><span style="color: #0000ff">file ../../sda1</span>
<span style="color: #0000ff"> ../../sda1: block special</span></p>
<p style="text-align: justify">2) If the VM still does not boot after having tried to boot from a previous kernel next you could try to rebuild the initramfs and copy over a new compressed image of the Linux kernel this is seen in the example in the grub file.</p>
<p style="text-align: justify"><strong>Initramfs file</strong>
<span style="color: #008000">initrd /boot/initramfs-2.6.32-504.16.2.el6.x86_64.img</span></p>
<p style="text-align: justify"><strong>Kernel file</strong>
<span style="color: #008000">/boot/vmlinuz-2.6.32-504.16.2.el6.x86_64</span></p>
<p style="text-align: justify">Normally, in an on-premise environment you would boot a system from a recovery cd. In Cloud environments we have to attach the OS disk to a temporary VM of the same OS and Version for recovering or manipulating  system files for a no-boot scenario, this is reinforced even more if we are going to attempt a copy or recreate initramfs and kernel files</p>
<p style="text-align: justify">Once the OS disk is attached to a temp VM on /rescue (first secure any data by copying off the OS disk)</p>
<p style="text-align: justify">Revert previously made changes to grub.conf if you had commented out entries referring to the first kernel to boot re-instate them.</p>
<p style="text-align: justify">Then  proceed to rebuild initramfs.</p>
<p style="text-align: justify"><span style="color: #0000ff">mv /rescue/boot/initramfs-2.6.32-504.8.1.el6.x86_64.img  /rescue/boot/initramfs-2.6.32-504.8.1.el6.x86_64.old-img</span></p>
<p style="text-align: justify">On the temporary CentOS 6.6 Linux VM we were unable to locate the exact same initramfs, hence building and using the latest version available on the temp.</p>
<p style="text-align: justify"><span style="color: #0000ff"> dracut /rescue/boot/initramfs-2.6.32-504.8.1.el6.x86_64.img  2.6.32-504.8.1.el6.x86_64</span></p>
<p style="text-align: justify">Then to be safe copy relevant vmlinuz file and finally update the grub.conf to reflect new kernel values:
<span style="color: #0000ff">ls -ltr /lib/modules/</span></p>
<p style="text-align: justify"><strong>drwxr-xr-x. 7 root root 4096 Apr 14  2014 2.6.32-431.11.2.el6.x86_64</strong>
<strong>drwxr-xr-x. 7 root root 4096 Jun  4  2014 2.6.32-431.17.1.el6.x86_64</strong>
<strong>drwxr-xr-x. 7 root root 4096 Sep 25  2014 2.6.32-431.29.2.el6.x86_64</strong>
<strong>drwxr-xr-x. 7 root root 4096 Nov 18 18:54 2.6.32-504.1.3.el6.x86_64</strong>
<strong>drwxr-xr-x. 7 root root 4096 Mar 25 19:28 2.6.32-504.12.2.el6.x86_64</strong></p>
<p style="text-align: justify"><span style="color: #0000ff">dracut /rescue/boot/initramfs-2.6.32-504.12.2.el6.x86_64.img 2.6.32-504.12.2.el6.x86_64</span></p>
<p style="text-align: justify"><span style="color: #0000ff">ls -ltr /rescue/boot/initramfs-2.6.32-504.12.2.el6.x86_64.img</span>
<strong>-rw-------. 1 root root 19354168 May  6 15:39 /rescue/boot/initramfs-2.6.32-504.12.2.el6.x86_64.img</strong></p>
<p style="text-align: justify"><span style="color: #0000ff">cp /boot/vmlinuz-2.6.32-504.12.2.el6.x86_64 /rescue/boot/</span></p>
<p style="text-align: justify"><span style="color: #0000ff">ls -ltr /rescue/boot/vmlinuz*</span></p>
<p style="text-align: justify"><strong>-rwxr-xr-x. 1 root root 4128368 Nov 22  2013 /rescue/boot/vmlinuz-2.6.32-431.el6.x86_64</strong>
<strong>-rwxr-xr-x. 1 root root 4128688 Jan  3  2014 /rescue/boot/vmlinuz-2.6.32-431.3.1.el6.x86_64</strong>
<strong>-rwxr-xr-x. 1 root root 4129872 May  7  2014 /rescue/boot/vmlinuz-2.6.32-431.17.1.el6.x86_64</strong>
<strong>-rwxr-xr-x. 1 root root 4131984 Sep  9  2014 /rescue/boot/vmlinuz-2.6.32-431.29.2.el6.x86_64</strong>
<strong>-rwxr-xr-x. 1 root root 4153008 Jan 28 21:40 /rescue/boot/vmlinuz-2.6.32-504.8.1.el6.x86_64</strong>
<strong>-rwxr-xr-x. 1 root root 4152720 May  6 15:44 /rescue/boot/vmlinuz-2.6.32-504.12.2.el6.x86_64</strong></p>
<p style="text-align: justify"><span style="color: #0000ff">vi /rescue/boot/grub/grub.conf</span></p>
<p style="text-align: justify"><span style="color: #008000">title CentOS (2.6.32-504.12.2.el6.x86_64)</span>
<span style="color: #008000">root (hd0,0)</span>
<span style="color: #008000">kernel /boot/vmlinuz-2.6.32-504.12.2.el6.x86_64 ro root=UUID=6d089360-3e14-401d-91d0-378f3fd09332 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet numa=off console=ttyS0 earlyprintk=ttyS0 rootdelay=300</span>
<span style="color: #008000">initrd /boot/initramfs-2.6.32-504.12.2.el6.x86_64.img</span></p>
<p style="text-align: justify"><span style="color: #0000ff">cd /</span>
<span style="color: #0000ff"> umount /rescue</span></p>

<ol style="text-align: justify">
 	<li>Detach the disk from VM <strong><em>B</em></strong> via the Azure portal</li>
 	<li>Recreate the original VM <strong><em>A</em></strong> from the repaired VHD</li>
</ol>
<p style="text-align: justify">For a Classic VM:</p>
<p style="text-align: justify">Recreate the original VM <strong><em>A</em></strong> (Create VM from <strong>Gallery</strong>, Select <strong>My Disks</strong>) you will see the Disk referring to VM <strong><em>A – </em></strong>Select the original Cloud Service name.</p>
<p style="text-align: justify">For a Resource Manager VM you will need to use either Powershell or Azure CLI tools, the articles below have steps to recreate a VM from its original VHD:</p>
<p style="text-align: justify"><a href="https://blogs.msdn.microsoft.com/linuxonazure/2016/07/21/azure-powershell-how-to-delete-and-re-deploy-a-vm-from-vhd/">Azure PowerShell: How to delete and re-deploy a VM from VHD
</a><a href="https://blogs.msdn.microsoft.com/linuxonazure/2016/07/21/azure-cli-how-to-delete-and-re-deploy-a-vm-from-vhd/">Azure CLI: How to delete and re-deploy a VM from VHD</a></p>
<p style="text-align: justify"></p>
&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Unsupported: How to install xRDP for GUI remote access on Linux</title>
      <link>https://docs.microsoft.com/archive/blogs/linuxonazure/unsupported-how-to-install-xrdp-for-gui-remote-access-on-linux</link>
      <pubDate>Mon, 26 Sep 2016 18:44:19 GMT</pubDate>
      <dc:creator><![CDATA[Marco A Bicca]]></dc:creator>
      <guid
        isPermaLink="false">http://blogs.msdn.microsoft.com/linuxonazure/?p=275</guid>
      <description><![CDATA[You want to access a Linux VM on Azure using a GUI through Remote Desktop or similar tools.
The...]]></description>
      <content:encoded><![CDATA[<p class="">You want to access a Linux VM on Azure using a GUI through Remote Desktop or similar tools.</p>
<p class="">The installation and configuration of 3rd party tools are beyond the scope of Azure Linux support but we have here a few notes and best practices to enable xRDP if needed.</p>
<p class="">There are other ways of achieving similar results with other tools, in this article we are covering specifically xRDP.</p>
<p class="">When using the standard configuration in xRDP the port needed to be opened by using an Endpoint (Classic) or Network Security Groups (Resource Manager) will be 3389 TCP, the same used for Microsoft Windows remote access.</p>
<p class="">There are a few security implications to keep in mind when enabling xRDP but we will be covering a few best practices at the end of this article.</p>
<p class="">Steps to install xRDP are listed below.</p>
<p class=""><strong><span class="hljs-strong">For Ubuntu/Debian:</span></strong>
<span style="color: #0000ff">sudo -i</span>
<span style="color: #0000ff">apt-get update</span>
<span style="color: #0000ff">apt-get install xrdp</span></p>
<p class=""><strong><span class="hljs-strong">For Red Hat, CentOS and Oracle:</span></strong>
You need to install a 3rd party repository (EPEL) which is usually not supported by the vendors but here you can find more information:
<a target="_blank" href="https://fedoraproject.org/wiki/EPEL">https://fedoraproject.org/wiki/EPEL</a></p>
<p class="">Make sure you install the one for your specific version (6.x/7.x).</p>
After that repository is successfully installed then you can proceed with the steps below.
<p class=""><strong><span class="hljs-strong">Red Hat / CentOS and Oracle version 7.x:</span></strong>
<span style="color: #0000ff">sudo -i</span>
<span style="color: #0000ff">yum install xrdp tigervnc-server xterm</span>
<span style="color: #0000ff">systemctl enable xrdp
systemctl enable xrdp-sesman</span></p>
<p class=""><strong><span class="hljs-strong">Red Hat / CentOS and Oracle version 6.x</span></strong>
<span style="color: #0000ff">sudo -i</span>
<span style="color: #0000ff">yum install xrdp tigervnc-server xterm</span>
<span style="color: #0000ff">service xrdp restart</span>
<span style="color: #0000ff">chkconfig xrdp on</span></p>
Once you can connect using xRDP and you have xterm opened, you can test any graphical application that you want, for example, you can try xclock.
<h2><strong><span class="hljs-strong">Best practices to improve security</span></strong></h2>
A) Using an SSH local tunnel to avoid opening extra ports and encrypt traffic.

By tunneling the xRDP access through SSH you not only encrypt all traffic but you also avoid opening up extra ports on your Linux VM and Azure network topology and the xRDP daemon can be basically listening to the localhost interface in your Linux VM on Azure.

Basic steps to configure a more secure xRDP environment are:

1) Edit the /etc/xrdp/xrdp.ini and change/add the following to force the daemon to listen to 127.0.0.1 and also use a higher encryption level:

[globals]
bitmap<span class="hljs-emphasis">_cache=yes
bitmap_</span>compression=yes
port=3389
<span style="color: #0000ff"><strong>crypt</strong></span><span class="hljs-emphasis"><span style="color: #0000ff"><strong>_level=high</strong></span>
channel_</span>code=1
max_bpp=24
#black=000000
#grey=d6d3ce
#dark_grey=808080
#blue=08246b
#dark_blue=08246b
#white=ffffff
#red=ff0000
#green=00ff00
#background=626c72
<span style="color: #0000ff"><strong>address=127.0.0.1
</strong></span>
<span style="color: #ff0000">NOTE: Keep in mind that by changing the daemon to 127.0.0.1 you will only be able to access it by doing an SSH tunnel which can be done by following the steps below.</span>

For OSX and Linux users, you can run on a terminal window:
<span style="color: #0000ff">ssh -N -p 22 USER@VM<span class="hljs-emphasis">_PUBLIC_</span>IP -L 3389:127.0.0.1:3389</span>

In the example above you are basically using a local port 3389 (on your workstation/laptop) and tunnelling that traffic to your Linux VM on Azure to its localhost on port 3389, so to connect to the VM using xRDP you will basically connect locally on your workstation to port 3389 and that gets automatically tunnelled to the VM on Azure.
<p class="">Generally GUI's are disabled by default on Linux servers due to security concerns so, if you really need to enable this kind of access it is highly recommended that you are using <a target="_blank" href="http://blogs.msdn.microsoft.com/linuxonazure/2016/08/07/best-practices-using-ssh-keys-to-access-linux-vms-on-azure/">SSH Keys</a> as well as local tunnels so you don't have to open extra ports to the Linux VM.</p>]]></content:encoded>
    </item>
  </channel>
</rss>