August 23, 2017 — 16:45

Author: silver  Category: linux  Comments: Off

perf – performance analysis tools for Linux

Start with:

perf top
perf bench all


To find out why “kworker” process (kernel per-cpu threads) has high CPU usage:

  • record 10 seconds of backtraces on all CPUs to
    perf record -g -a sleep 10
  • analyse recording:
    perf report

More info:

August 23, 2017 — 15:37

Author: silver  Category: linux  Comments: Off

Remote upgrade using aptitude:

  1. echo “defscrollback 10000” >>/root/.screenrc
  2. screen
  3. /etc/sysctl.conf:
    # on kernel panic reboot after 60s
    kernel.panic = 600
    # enable magic sysrq key
  4. In /etc/apt/sources.list: change old to new dist (or “stable” etc)
    ( if needed: apt-get install debian-archive-keyring )
  5. aptitude update
  6. aptitude safe-upgrade
    ( optionally/if needed: full-upgrade, dist-upgrade )

Change default editor:

sudo update-alternatives --config editor

Install build tools:

apt-get install build-essential

pkg install dates:

for file_list in `ls -rt /var/lib/dpkg/info/*.list`; do \
  stat_result=$(stat --format=%y "$file_list"); \
  printf "%-50s %s\n" $(basename $file_list .list) "$stat_result"; \


apt-get -t stretch-backports install “package”
aptitude -t stretch-backports install “package”


Package: *
Pin: release a=stable
Pin-Priority: 900

Package: *
Pin: release o=Debian
Pin-Priority: -10

“testing” packages:

install a pkg from testing:
sudo apt-get -t testing install tmux
show all testing pkgs:
aptitude search -F "%p %V %v" '?narrow(~i, ~Atesting)
( stable, unstable, oldstable, etc )

apt-get install package=version

Windows 10 Licensing
August 23, 2017 — 14:40

Author: silver  Category: windows  Comments: Off

Product Key can now be a “Digital License”. This seems to be true for upgraded Windows 7 keys.
To prevent activation issues after hardware changes: link MS account to digital license asap (Settings > Accounts).

View current license:

slmgr.vbs /dlv
wmic path softwarelicensingservice get OA3xOriginalProductKey

powershell "(Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey"

Update product key:

run slui.exe or goto Settings > Activation

MS Activation servers:

More info:

Windows Uptime
August 23, 2017 — 14:07

Author: silver  Category: windows  Comments: Off

How to find out Windows Uptime?

Using PowerShell:

powershell ((Get-Date) - (gcim Win32_OperatingSystem).LastBootUptime).ToString('g')
powershell ((Get-Date) - ([wmi]'').ConvertToDateTime((Get-WmiObject win32_operatingsystem).LastBootUpTime)).ToString("dd' days 'hh\:mm\:ss")

Also, I cobbled together this little script that looks like the Linux uptime cmd. It’s embedded in a batch file so for ease of running ( for more info). Gist:

@PowerShell -ExecutionPolicy RemoteSigned -Command Invoke-Expression $('[email protected](^&{$args} %*);'+[String]::Join(';',(Get-Content -LiteralPath '%~f0') -notmatch '^^@PowerShell.*EOF$')) & goto :EOF

$d = Get-Date
$upTime = (($d) - ([wmi]'').ConvertToDateTime((Get-WmiObject win32_operatingsystem).LastBootUpTime)).ToString("d' days,  'h\:mm")
$ActiveUsers = @()
foreach($User in (Get-WmiObject Win32_LoggedOnUser).Antecedent) { $ActiveUsers += $User.Substring($User.LastIndexOf('=') + 2, $User.Length - $User.LastIndexOf('=') -3) }
$UserText = "$($ActiveUsers.Count) user"
if ( $ActiveUsers.Count -gt 1 ) { $UserText += "s" }
$TotalProcTime = (Get-Counter "\Processor(_total)\% Processor Time") | foreach {$_.CounterSamples[0].CookedValue}

Write-Host -NoNewLine (" {0}, up {1},  {2},  total proctime: {3}%" -f $d.toString("HH:mm:ss"), $upTime, $UserText, [math]::Round($TotalProcTime,2))

Output looks like this:

 14:45:41, up 5 days,  20:15,  3 users,  total proctime: 2,26%


GUI (Windows 10):

Task Manager (taskmgr) > More details > Performance tab > CPU

Boot Time:

net stats <workstation/server>
systeminfo | findstr "System Boot Time"

We use Matomo free and open source web analytics (opt-out)