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.