20200223

The upload size in bytes # - 512 bytes for the VHD footer (# in this case) must be a multiple of MiB.

$ wc -c os_disk.vhdx
5272240128 os_disk.vhdx

The vhd file size needs to be a number divisible by 1024.

5272240128 / 1025 / 1024 / 1024 = 4.91015625

4.91015625 is not divisible by 1024. We are going to round the number to 5.

5 * 1024 * 1024 * 1024 = 5368709120

And add 512 bytes for the VHD footer.

5368709120 + 512 = 5368709632

Reference: Reddit

20191221

Azure Terraform Role Definition

For security purpose, we tend to create service principal that can performs Terraform operations only within a specific resource group without able modify resource outside the resource group within the same subscription.

Reality is we still need to allow the service principal to run few actions within the scope of the subscription.

Therefore here is the role definition with actions required that Terraform operations need to execute successfully.

{
    "Name": "Terraform",
    "Description": "Role definition has actions required that Terraform operations need",
    "Actions": [
        "*/read",
        "Microsoft.Sql/register/action",
        "Microsoft.CognitiveServices/register/action",
        "microsoft.insights/register/action"
    ],
    "AssignableScopes": ["/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
}

With this as json content, we may run the following command to create the role and assign it to the subscription.

az role definition create --role-definition terraform-role-definition.json


Reference

Schedule Dark Mode













To schedule dark mode at 7 PM:

schtasks /CREATE /SC DAILY /TN "Enable Dark Mode" /TR "C:\Windows\System32\reg.exe add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme /t REG_DWORD /d 0 /f" /ST 19:00

To schedule light mode at 7 AM:

schtasks /CREATE /SC DAILY /TN "Disable Dark Mode" /TR "C:\Windows\System32\reg.exe add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme /t REG_DWORD /d 1 /f" /ST 7:00

Execute these commands in Command Prompt or PowerShell. There are additional steps you need to do to ensure it is enabled even if you turn on your laptop after the scheduled time.

  1. Launch Task Scheduler.
  2. Open the Properties dialog of the tasks we created.
  3. Go to Settings and check the box "Run task as soon as possible after a scheduled start is missed."


Reference

  1. How to Auto-Toggle Windows 10 Dark Mode at Night
  2. Schtasks.exe /Create

20191213

Generate self-signed certificate

openssl genrsa -out www.example.com.key 2048
openssl req -new -x509 -key www.example.com.key -out www.example.com.cert -days 3650 -subj /CN=www.example.com

20170627

apt-add-repository: invalid HTTP proxy, unsupported URI

Had this error on a Ubuntu which runs behind a proxy. Your $http_proxy environment variable must contain "http://"

root@ubuntu:~# echo $http_proxy
http://proxy.company.net:8080

20141220

handy script to quickly backup a file

#!/bin/bash
# backup a file (somefile to somefile.yyyy-mm-dd.tar.gz)

FILE="$@"

#debug
echo $FILE

if [ -f $(which tar) ]
then
        tar zcPf "${FILE}".$(date +%s).tar.gz "${FILE}"
else
        echo "sorry, do you have 'tar' installed?"
fi

20141020

find files that contain string

# grep -Hirn "mystring" /path/to/dir
find . -print0 | xargs -0 -n1 -P8 grep -Hirn 

thanks to sifu enshu

20141019

error: Diskfilter writes are not supported

# cp -p /etc/grub.d/10_linux /etc/grub.d/10_linux.`date +%Y%m%d.%H%M`
# sed -i 's/quick_boot="1"/quick_boot="0"/' /etc/grub.d/10_linux
# update-grub
# reboot

share internet connection in linux via terminal


On access point side
  1. disable firewall
  2. enable packet forwarding
    # echo 1 > /proc/sys/net/ipv4/ip_forward
  3. set iptables rule for port forwarding
    # iptables -t nat -A POSTROUTING -o -j MASQUERADE
on client side:
  1. configure network interface so you can reach the access point
  2. set the access point as default gateway
    # route add default gw
  3. set dns resolution
    # echo nameserver 8.8.8.8 >> /etc/resolv.conf

20140507

Converting the numbers to decimal makes it easier to see which can be used:

# egrep "^ .*|System RAM" /proc/iomem | sed -e 's/ : / /g' -e 's/-/ /g' | awk '{;printf("%d bytes to %d bytes (%d M to %d M) - %s %s\n", strtonum("0x"$1), strtonum("0x"$2), strtonum("0x"$1)/1024/1024, strtonum("0x"$2)/1024/1024, $3, $4)}'

20140410

bind for chroot

cd /mnt/sysimage
mount -t proc proc proc/
mount --rbind /sys sys/
mount --rbind /dev dev/

20140401

mbr

446 bytes - Bootstrap
64 bytes - Partition table
2 bytes - Signature

deletes mbr only
# dd if=/dev/zero of=/dev/sdc bs=446 count=1

20140311

rename disk group

ensure file systems are not mounted
# vxvol -g currentdg stopall
# vxdg deport currentdg
# vxdg -n newdg import currentdg
# vxdg list
# vxrecover -g newdg -sb

20140116

20140115

increase vmware disk size and resize PV

increase vdisk size (vsphere client)
echo 1 > /sys/class/scsi_device/*/device/rescan

pvresize 

20131207

Could not sign in. Please check your network connection and try again.

Key applications on Mac such as iMessage, FaceTime and even Facebook integration with Notifications depend on your Mac's Serial Number. If the System Information is showing #Serial Number, you will not be able to sign in.

To solve, search for Blank Board Serializer.

20130913

redhat disable ipv6

* /etc/sysconfig/network - add "NETWORKING_IPV6=no"
* /etc/sysctl.conf - add "net.ipv6.conf.all.disable_ipv6 = 1"

20130911

# hdiutil convert -format UDRW -o ~/path/to/target.img ~/path/to/ubuntu.iso
# diskutil list
# diskutil unmountDisk /dev/diskN
# sudo dd if=/path/to/downloaded.img of=/dev/rdiskN bs=1m
# diskutil eject /dev/diskN

20130826

Re-build Grub on Proliant

/etc/grub.conf
boot=/dev/cciss/c0d0


/boot/grub/device.map
(fd0)     /dev/fd0
(hd0)    /dev/cciss/c0d0

/sbin/grub --batch --device-map=/boot/grub/device.map \
   --config-file=/boot/grub/grub.conf --no-floppy
grub> root (hd0,0)
grub> setup (hd0)
grub> quit

original