Tuesday, May 31, 2022

cloning disks on Linux

Just a reminder to myself - dd can clone not just partitions but entire devices as well. https://linuxhint.com/clone-disk-using-dd-linux/ So, if only one partition needs to be cloned,

sudo dd if=/dev/sdb1 of=/dev/sdc1 status=progress

This will take only as much time as needed for the data present that one partition. 

If we want to make a complete clone of all partitions of one USB drive into another,

sudo dd if=/dev/sdb of=/dev/sdc status=progress

This will take much longer, even if the devices are mostly empty. For example, for 16 GB flash drives with only 2 GB of data, it took around 90 minutes on the Macbook Pro, using the default block size, going at around 3 MB per second.

16000 / 3 / 60 = 88.89 minutes.

Monday, May 30, 2022

checking battery cycles in Linux

Via https://forums.linuxmint.com/viewtopic.php?t=144301 
apt install tlp
and suggested packages
sudo apt install tp-smapi-dkms acpi-call-dkms smartmontools linux-tools-generic

sudo tlp-stat --battery
--- TLP 1.3.1 --------------------------------------------

+++ Battery Features: Charge Thresholds and Recalibrate
natacpi    = inactive (no kernel support)
tpacpi-bat = inactive (laptop not supported)
tp-smapi   = inactive (laptop not supported)

+++ Battery Status
No battery data available.

upower -i /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          (null)
  power supply:         no
  updated:              Thursday 01 January 1970 05:30:00 AM (1653903861 seconds ago)
  has history:          no
  has statistics:       no
  unknown
    warning-level:       unknown
    battery-level:       unknown
    icon-name:          '(null)'

Sunday, May 29, 2022

suspend to RAM - sleep mode - issue with Linux Mint 20.3

After an upgrade to Linux Mint 20.3 from 19.3, the Macbook was showing a garbled screen when waking up from sleep - i.e. suspend to RAM had some issue, probably with the graphics card. The suspend would also take 1 to 3 minutes to complete, with the fan being on for that time with a blank screen. Ctrl+Option+Fn+F2 was allowing a text-mode terminal to be opened, and syslog showed "Buffer eviction failed" before the suspend was taking effect.

 
After waking up, the display driver nouveau would complain of invalid op-code.

At first, I thought it might have something to do with the two displays being detected on the Macbook as mentioned on this post,
https://hnsws.blogspot.com/2021/03/linux-mint-workspace-size.html
since I had mirrored displays instead of disabling one display. But even after disabling one display, the same issue continued. 


The workaround was, as that thread suggested, adding the kernel parameter  init_on_alloc=0 on boot. Since I use refind to boot, in my case, the adding of the kernel parameter was done by editing the /boot/refind_linux.conf as in my previous post,
https://hnsws.blogspot.com/2021/08/verbose-display-while-booting-with.html

After doing that, I could check the parameters passed to the kernel in various ways as listed here,
https://www.cyberciti.biz/faq/display-view-linux-kernel-parameters-for-booted/
like 
dmesg | grep "Command line"
[    0.000000] Command line: \\boot\vmlinuz-5.4.0-113-generic root=UUID=65c50557-my-disk-uuid-c7b5d84509d2 ro init_on_alloc=0 initrd=boot\initrd.img-5.4.0-113-generic

And now suspend to RAM works.


Friday, May 27, 2022

mapping custom domains to github pages on multiple repositories

I was under the impression that one user can only map one custom domain to one repository with Github pages. But this post shows how to map multiple custom domains to multiple repositories for the same username -
https://deanattali.com/blog/multiple-github-pages-domains/

So, instead of Nettigritty's flaky domain redirection which doesn't work half the time, I've now used a meta redirect on another repo which has only index.html to redirect one of our websites. So the steps are:

  1. Add A records with IP addresses obtained by dig username.github.io
  2. Add CNAME record pointing to username.github.io (this is the tricky part which people miss out)
  3. Enable github pages in the Github repository settings
  4. Enable custom domain in the Github repository settings.
  5. After site works, enforce HTTPS in the Github repository settings - if necessary, wait 24 hours before doing this for DNS to propagate.


Wednesday, May 25, 2022

privacy policy and other policies in Moodle

There was a request to add an amended privacy and usage policy on one of our Moodle servers. It was desirable that users click to agree to the policy on their next sign-in.

Under Site Administration - Users tab - Privacy and Policies - Policy settings,
there is the option to change from the Default policy handler (which has the option only for a single site policy and a single site policy for guests)
to the policy_tool policy handler, which has the option to add more policies.

https://docs.moodle.org/400/en/Policies
According to this page, when a new policy is added using this tool, all users will be required to agree to that policy on next login.

After the policy handler is changed to policy_tool , then
The new policy can be added using the page
Site Administration - Users tab - Privacy and Policies - Manage policies
https://our.domain/admin/tool/policy/editpolicydoc.php

The policy can be of type
Site policy
Privacy policy
3rd party policy
or
Other policy




Monday, May 23, 2022

dos disk repair on Linux

 https://askubuntu.com/questions/147228/how-to-repair-a-corrupted-fat32-file-system

So, either

sudo apt-get install dosfstools

sudo dosfsck -w -r -l -a -v -t /dev/sdc1 

or

fsck.vfat -a /dev/sdc1

fsck.fat 4.1 (2017-01-24)
Logical sector size is zero.


https://ubuntuforums.org/showthread.php?t=1908329

Apparently

testdisk is the solution. 

Disk /dev/sdc: 232.91 GiB, 250059350016 bytes, 488397168 sectors
Disk model: External USB HDD
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4d2b50bb

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdc1  *       63 488392064 488392002 232.9G 83 Linux

(In this case, found that the partition had been overwritten by a linux partition :)

Sunday, May 22, 2022

installing a printer on the samsung galaxy book go LTE laptop

Downloading and installing the drivers for the Pixma MG2440 multi-function device - printer and scanner - from Canon's website, the installation did not give any warnings or errors on the Samsung Galaxy Book Go LTE laptop, but the device did not work. No suitable driver found was the error message from the scanner / printer utility. This is probably because this machine has an ARM processor, and the Canon drivers are probably for x86. Even though the ARM-based Windows 11 is supposed to be able to run in emulation mode for 32-bit x86 apps, either the installer was installing 64-bit x86 drivers, or maybe 32-bit drivers don't work in emulation mode.

Anyway, the solution was to get Microsoft's generic Canon inkjet drivers from Windows Update. But the way to do this was not very intuitive. After clicking on "Update driver" in Control Panel, the Windows Update screen is shown, and after "Check for Updates", it shows "No updates found." But lower down, clicking on "Optional updates", it finds two drivers. Installing these made the printer work, albeit with a blank printout due to the ink being exhausted.

Saturday, May 21, 2022

troubleshooting ad-hoc query reports in Moodle

Number of files downloaded per user query

The following was my procedure for making corrections to this ad-hoc Moodle query:

Expanding out the sub-query and running it in DBeaver, could see the discrepancies in the count. Changed the select count() to just select, then went step by step to identify which rows were causing discrepancies, copy-pasting the filenames to adjacent columns on a temporary google sheet for easy comparison. 

It turns out the bugs in the query were due to some assumptions which I made about the prefix_logstore_standard_log table:
1. I assumed each file download led to a single log entry - no, there are multiple log entries for each download
2. I assumed that the shorter query which I used for counting the number of files will be sufficient, apparently it is not.
3. There were also overcounting in case the user was downloading the same file multiple times.

So, I have made some modifications to both the queries, now they shows the number of files downloaded which are of non-zero size. The files listing only shows one filename for each download and does not indicate multiple downloads, so now I have modified the number of files counted per user also to ignore multiple downloads of the same file.
 

In the case of these users I tested, one user has download some files many times, like

Even after this, there were mismatches in the count. The reason is that was, the query "Number of files downloaded per user" counted only distinct filenames.
Now, there are some files with the same name, but with different content, like Fractions.pdf which occurs with different content in different courses. The listing of files shows these separately.

I can correct for this by choosing
count(distinct f2.contenthash) instead of
count(distinct f2.filename)

But still the numbers won't match. This is because there are some files with exactly the same name and same content, in different courses.
For example,
VI Maths || Fractions || VC_Way of Sharing from the Whole.pptx || 779583
VI TNSSE Maths || Fractions Term III || VC_Way of Sharing from the Whole.pptx || 779583

which have both been downloaded by the user we checked.

So, in order to count these files also separately, I will count
count(distinct concat(f2.contenthash,l2.contextinstanceid) instead of simply
count(distinct f2.contenthash)

Then it matches for this user.

Files downloaded per user query

The reason for the "short name of the course, resource reviewed and files downloaded mismatch" for the other query was wrong mapping of resourceid in the log.

In our query, we have
left join vv_resource r on l.objectid = r.id
i.e. we are mapping the objectid to resourceid. But this seems to be wrong.

To see why, I went through all the columns in the logstore log table.
There is a column which says objecttable. For those entries where objecttable says resource, the mapping is correct. For example, pdf files. The contextinstanceid seems to be unique to each course section.

So, I modified the query so that instead of "Resource viewed", I have put the column "Course Module" which shows the correct course module -
vcs.name, from
left join {course_modules} vcm on l.contextinstanceid = vcm.id
left join {course_sections} vcs on vcm.section = vcs.id

Then the query gives correct results for pdf files as well as other file types like pptx.

 


Thursday, May 19, 2022

usrmerge message after fresh Linux Mint 20.3 Install

After a fresh installation of Linux Mint 20.1, which auto-updated to 20.3, there was a system report about usrmerge - 


https://community.linuxmint.com/software/view/usrmerge

This forum post
indicated that the command to be run, in case usrmerge had not yet happened,  
There are two scripts:
/usr/lib/convert-etc-shells
/usr/lib/convert-usrmerge
which execute the needed changes, in case they have not been done already.

But in my case, ls -l / was showing all the symlinks like bin -> usr/bin etc.  So I asked Mint to ignore this report and not show it again. 

Friday, May 13, 2022

Samsung Galaxy Book Go LTE - no wifi after factory reset

After a factory reset, I had shut down a Samsung Galaxy Book Go LTE laptop in order to give it to someone else. After a couple of days, when they were trying to set it up, initial setup was not proceeding after the point where it tries to connect to the network. Checking with a 4G SIM inserted, setup proceeded, and the laptop booted up into Windows 11. But no wifi networks were being detected. The wireless networking device was being flagged in Control Panel.

So, deleted the "Unknown device" in control panel, restarted the machine - now it recognized the wifi adapter, asked to connect to the network, and worked fine. 

Thursday, May 12, 2022

blocking phishing emails from Google Workspace

I was asked how an institution could block some phishing emails, which had the name of the current Vice-Chancellor in the "From" field, with some random gmail id. Excerpts from my reply:

1. Report phishing - You could ask the user to follow these steps - 
image.png

2. From admin.google.com , blocking this particular email - 
You can set up rules using the method at

For example, you could put in a filter so that any email which has
  • simple content search NameOfVC in headers
  • AND is from @gmail.com
  • should be blocked

Thursday, May 05, 2022

printing with HP LaserJet Tank 1020w with Android and Linux

Instead of just connecting the USB cable and using plug-and-play on Linux to install the drivers, thought I would directly try HP's Smart app on Android to install the printer. Worked OK, though it was nearly 100 MB in size. While printing documents shot as photos, my phone makes the background of the pics excessively grey - so probably need to edit the image, bump up brightness and contrast.

Trying to print from Linux Mint 19.3 Tricia, though the network printer was found, and as prompted by the wizard, I had installed the drivers it prompted, giving the print command did not lead to any action on the printer. Pressing the "i" information button was giving a test print on the printer, so the printer itself was fine. 
 
Found a youtube video detailing the installation of the HP Linux Imaging and Printing software hplip, which described the problem I faced exactly. In my case, it looked like hplip version 3.17.10+ was already installed by Linux Mint, but the printer needed a newer version as per

But going through the install process, came across multiple devel packages which the installer was not able to install for Linux Mint 19.3 - like SNMP devel package. 


Some forum posts indicate can make it work without the hplip package. Using the foo2zjs instead, method like
but using github as the source as indicated at

So, I first uninstalled the old version of hplip with apt (I had done this before trying to install the new version of hplip), and then

sudo apt-get update
 sudo apt-get remove cups hplip cups-filters hplip-data system-config-printer-udev
 sudo apt-get install cups build-essential tix groff dc axel
 sudo apt-get install cups-filters cups unp system-config-printer-gnome
 sudo rm -rf /usr/share/hplip
 cd /tmp
 rm foo*
git clone https://github.com/koenkooi/foo2zjs.git
cd foo2zjs
make

# Also, since source code from github already contains all firmware images,
# there is no need to run getweb, as per the askubuntu link above. 

sudo make install
sudo make install-hotplug

# Unplug and re-plug the USB printer into the PC
 # add new HP Laserjet 1020 printer via system-config-printer tool
 # and choose to use foo2zjs foomatic printer driver :

 system-config-printer

# at this step, my system was silent, since I did not connect via USB, but instead on network

Now when I tried a test page print via the network printer shown in Ubuntu, it worked. 
 
Edit 22 May -  On Linux Mint 20.3, which is based on Ubuntu 20.04, the printer installed automatically flawlessly. I just switched on the printer, which had already been set up on the wifi network, Linux automatically detected it and added the printer without me having to do anything, and a print from Gimp worked fine.

Monday, April 25, 2022

fixing an error in a moodle ad-hoc query

One of the ad-hoc queries in one of our moodle servers was returning "Error reading from database" when executing certain queries with certain parameters, working with other parameters.

Troubleshooting - The general issue is that with ad-hoc queries, only the generic error "Error reading from database" is shown, and not the exact cause of the error, which would be some problem with the SQL query. Running the same query using DBeaver, (I had to find/replace { with ourprefix_ and } with a space) 
I get the more helpful error message

SQL Error [1242] [21000]: Subquery returns more than 1 row

Commenting out all except the first subquery, I still got the error. So, there was an issue is with the first subquery.

Looking at the table ourprefix_feedback_value I saw that there are some entries where the name field with match
like '%Chapter%' but the typ field is not a textfield.

Assuming that this is what is causing the problem, I modified the query by adding an additional line in bold below
where
fc.timemodified = fc2.timemodified
and fi2.name like '%Chapter%'
and fi2.typ = 'textfield') as "Chapter name",

This also did not solve the issue. Then, checked the ourprefix_feedback_completed table looking for duplicates in the timestamps like
select fc3.timemodified, count(fc3.timemodified)
from
ourprefix_feedback_value  fv3
left join vv_feedback_item  fi3 on fi3.id = fv3.item
left join vv_feedback_completed  fc3 on fc3.id = fv3.completed
where
fi3.name like '%Main%Script%'
GROUP BY fc3.timemodified
HAVING COUNT(fc3.timemodified) > 1

found 1646480361 was repeated twice. Two feedback items had exactly the same timestamp. Changed the second one to 1646480362 and the problem was solved.


 

Saturday, April 23, 2022

troubleshooting a php framework / cms based site

A couple of websites went down after a server upgrade. Checking out the contents of public_html, found some directories named fuel and codeigniter. Initially thought it was a codeigniter-based site, 

Later, found some function calls like fuel_set_var() which on searching github and google led to FUEL CMS - 

My first impressions were that upgrading from the existing 0.9x version to 1.5x was not so straightforward - the migration tool, mentioned in the documentation above, did not run. Then there is the part of the documentation which says that it needs MySQL 4.x + - 
Hopefully it works with 5.x? Will have to try manually capitalizing filenames and class names as needed for codeigniter 3+. 
"If you have a current installation of 1.3x or less and are wanting to upgrade, there are a few things to be aware of. FUEL 1.4 uses CodeIgniter 3.x which includes a number of changes, the most prominent being the capitalization of controller and model names. Additionally it is more strict on reporting errors."


Friday, April 22, 2022

changing cpanel theme for all accounts in WHM

There was the notification about CPanel Paper Lantern theme being deprecated and replaced with Jupiter theme. Changed the theme for all accounts using

- changed themes for all by going to WHM - Edit a package - and editing all the defined default packages. 

fixing wordpress errors after server upgrade

A wordpress site was not loading after a server upgrade. Just a blank screen. To troubleshoot, first checked database connectivity, database password in wp-config - that was working. Then, tried to get more information about the error by changing the define( 'WP_DEBUG', false ); - changed to true. Then the error showed up - Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 65536 bytes) in /home/websitename/public_html/wp-content/plugins/woocommerce/includes/class-wc-ajax.php on line 1101

Fixed it using the solution at 
by adding 
ini_set('memory_limit','128M');
to the top of wp-config.php

Problem solved. Set the WP_DEBUG variable back to false. 

Wednesday, April 20, 2022

OpenCV with Qt creator

K asked for pointers for this issue - I am trying to integrate OpenCV into the C++ code that I wrote for gamma acquisition. I am facing a problem while integrating it into the software Qt Creator. The headers are included without any errors, but when I initialize an empty matrix it returns "undefined reference to 'cv::Mat::~Mat()'". 

My reply was - 

"Undefined reference in the linking process doesn't mean, that it can't find the declaration in the header file, it means that it cant find the definition/implementation in any of the provided object files."

So the issue is most probably due to some path issue in the Makefile - it depends on what you are using to build the project. If you are using qt creator, then it would be qmake.

The easiest way to solve this would be perhaps a google search on getting started with OpenCV and QT creator.
Perhaps
if you are using windows.

This is an old version for opencv 3 on ubuntu,
but you may get some ideas from it.

He finally solved it himself - "I could link the library and use its functions now. I believe there are a lot of ways to link the library and I figured one way that worked for me.

I have discussed the way I solved it here 
so that it will be helpful to whoever compiles the OpenCV with Mingw 32-bit in Qt Creator."

So, in short, he "had to link the libraries by right-clicking on the project folder on the left-sidebar, selecting Add Libraries and choosing the External Libraries option (added one by one).

win32: LIBS += -LD:/opencv-build/install/x86/mingw/lib/ -llibopencv_core320.dll
win32: LIBS += -LD:/opencv-build/install/x86/mingw/lib/ -llibopencv_highgui320.dll
win32: LIBS += -LD:/opencv-build/install/x86/mingw/lib/ -llibopencv_imgcodecs320.dll 
INCLUDEPATH += D:/opencv-build/install/include
DEPENDPATH += D:/opencv-build/install/include

////NOTE: imgcodecs library is required for imread to work//////

Friday, April 15, 2022

improvMX for domain email forwarding

In a previous post, I had mentioned using our domain registrar's free email service. Now I have moved away from that to improvMX, for a hopefully more stable performance - emails were taking around 20 minutes to be forwarded using our domain registrar's mail severs, and this was causing problems with one-time passwords (OTPs) sent by Github, for example. There is a way to send emails via gmail smtp servers, too (but it displays "via ourdomain.tld" when I use my account@ourdomain.tld ).

Sunday, April 10, 2022

PBX with Raspberry Pi - RasPBX - or with the cloud - AWS

 https://www.youtube.com/watch?v=n_txukfW3uE
How to turn Raspberry Pi into FreePBX-based GSM gateway
(needs 3g modem)

Or, if willing to pay for the SIP trunk termination instead of buying a 3g modem, AWS based method -
https://www.youtube.com/watch?v=n_1wX7kKx7k

Quite interesting. 

Friday, April 08, 2022

youtube live streaming possibilities