Resize Linux osDisk partition on Azure

1) Login to the VM using SSH, we can check the size of the disk by using:
sudo dmesg | grep -i sda

We should see something similar to the output below (assuming you changed the size to 100GB on the portal for the disk):
[    3.100914] sd 2:0:0:0: [sda] 209715200 512-byte logical blocks: (107 GB/100 GiB)

2) To proceed with the partition resize, we will use: sudo fdisk /dev/sda

type: p
this will show partition /dev/sda1

type: d
type: n then p1 (to recreate partition 1) you can accept the default values
NOTE: if you receive a message about deleting or keeping a signature on the disk, just answer N
type: w (to save the new partition)
type: q (to exit fdisk)
sudo reboot (to reboot the VM so the partition is updated)

3) To finalize the resize, after the reboot, execute the command: resize2fs /dev/sda1

4) Use the command: df -h to verify its size:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 99G 698M 94G 1% /



Install the Azure Linux Agent

Perhaps as easy as? –

apt install waagent
service walinuxagent restart


Choose the Azure Linux Agent release here:

Copy the URL to the tar.gz file

Go the the directory you want to download the file and enter


Expand the file

tar -xvf XXXXXXXX.tar.gz

Install the new python downloaded version

sudo python install --register-service

Restart the waagent service

sudo service waagent restart

Verify the version details

waagent -version

If you get an error saying setup tools is missing run the following:

To install setuptools on Debian:

sudo apt-get install python3-setuptools

For an older version of Python (Python 2.x):

sudo apt-get install python-setuptools




Gnome GUI “Authentication Required” Administrator password

When getting a popup message to Authenticate as “administrator” in gnome it most likely means the user you are using does not have the correct groups associated to them.

Some of the messages you see were “Authentication required to refresh system repositories”

When rebooting or relogging in, it will now show your username to authenticate instead of “administrator”

Add the user to the adm and sudo group.

sudo usermod -a -G adm <username>

sudo usermod -a -G sudo <username>

Not exactly related – but similar issue:


Compacting Linux VHDX with Hyper-V

I wasn’t able to reduce the file size of my Linux disks on Hyper-V through the build in compact function of Hyper-V

In order to compact your disk run the following command on the Linux install

sudo fstrim -v

Shutdown your Linux install

Compact your disk



Default page to serve Apache2 and Debian9

sudo nano /etc/apache2/mods-enabled/dir.conf

Add file name that it can access only with directory’s name, or change the order

DirectoryIndex index.html index.htm

Install Ubuntu 18.4, Apache2, PHP 7.3 and Percona 5.7

Update system repositories

sudo apt update

Install Apache 2

Install Apache 2 with the apt command

sudo apt install apache2

Allow Apache on UFW and verify its status

sudo ufw allow 'Apache'

Install PHP 7.3

Update system repositories

sudo apt update
sudo apt upgrade

Add PPA for PHP 7.3

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install PHP 7.3 for Apache

sudo apt install php7.3

Install PHP 7.3 Extensions

Install extensions through:

sudo apt install php7.3-extension_name

sudo apt install php7.3-common php7.3-mysql php7.3-xml php7.3-xmlrpc php7.3-curl php7.3-gd php7.3-imagick php7.3-cli php7.3-dev php7.3-imap php7.3-mbstring php7.3-opcache php7.3-soap php7.3-zip php7.3-intl

Adjust php.ini file

sudo nano /etc/php/7.3/apache2/php.ini

upload_max_filesize = 100M
post_max_size = 48M
memory_limit = 512M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

Restart Apache2 and PHP services

sudo systemctl restart apache2.service

Test PHP7.3 and Apache2 install

sudo nano /var/www/html/phpinfo.php

Add the following line and save

<?php phpinfo( ); ?>

Load web browser with localhost/phpinfo.php

The following is ONLY for dev environment

Add current user to group that owns /var/www/html folder

sudo usermod -a -G GROUPNAME USERNAME

Reboot system

Change group permissions to rwx

sudo chmod -R g+rwx /var/ww/html

Install Persona 5.7


Update max_allowed_packet in mysqld.cnf to 32M to prevent Mysql went away message when doing large imports like: “ERROR 2006 (HY000) at line XXXX: MySQL server has gone away”

sudo nano /etc/mysql/percona-server.conf.d/mysqld.cnf


sudo service mysql restart

Install PHPMyAdmin

sudo apt update && sudo apt install phpmyadmin

For WordPress installation /

Enable mod_rewrite

sudo a2enmod rewrite

sudo systemctl restart apache2

By default, Apache prohibits using an .htacess file to apply rewrite rules.

sudo nano /etc/apache2/sites-available/000-default.conf

Add the following code between <VirtualHost *:80>

<Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted

sudo systemctl restart apache2

Create a .htaccess file in the web root folder

sudo nano /var/www/html/.htaccess

Add default WordPress .htaccess file contents:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress





Setup Remote Desktop XRDP on Debian 9

Install XRDP

sudo apt install xrdp

Configuring the firewall

sudo ufw allow 3389

Modify the Xwrapper.config file when you get a blank screen when removing in.

sudo nano /etc/X11/Xwrapper.config


allowed_users = console


allowed_users = anybody

Restart XRDP.

sudo systemctl restart xrdp

Actually, reboot the entire server

When logging in and you receive the message: Authentication Required – Authentication is required to create a color managed device click cancel and it’s all working.

In case you get a blue screen after login I found the following code works to fix this when you use Gnome as your desktop

$echo gnome-session > ~/.xsession
$chmod +x ~/.xsession

PowerShell – Running scripts is disabled on this system.

There are four different execution policies in PowerShell

  • Restricted – No scripts can be run.
  • AllSigned – Only scripts signed by a trusted publisher can be run.
  • RemoteSigned – Downloaded scripts must be signed by a trusted publisher.
  • Unrestricted – All Windows PowerShell scripts can be run.

You can change the PowerShell execution policies with Set-ExecutionPolicy like

Set-ExecutionPolicy Unrestricted

You can get the current policy in PowerShell



Windows PowerShell Remove previous Hyper-V backup folders older than….

This is based on code from Mike Galvin. When you copy the dirs to a network drive or so, this allows you to delete older backups.

Create a file called “Remove-old-Backups.ps1” and enter the following code:

##Remove previous backup folders older than the configured number of days.
$History = 4
## Location of the VM names file
$VmList = "c:\scripts\vms.txt"
##If a VM list file is configured, get the content of the file.
If ($VmList)
$Vms = Get-Content $VmList
echo $Vms
ForEach ($Vm in $Vms)
Get-ChildItem -Path $Backup -Filter "$Vm
-*-*-*-*-*-*" -Directory | Where-Object CreationTime –lt (Get-Date).AddDays(-$History) | Remove-Item -Recurse -Force
echo $Backup



Windows PowerShell copy local directory to network drive where items created TODAY

The following script will copy a local directory with items created TODAY to a network share.

Copy and paste below code to a file ending with .ps1 and run from Powershell as Admin

$Destination = "\\NETWORKSHARE\FOLDER"
Get-ChildItem -Path $path | Where-Object {$_.CreationTime.Date -eq (Get-Date).Date} | Copy-Item -Destination $Destination -Recurse -Force
Write-Host "I've just copied the file to $Destination"