01 December 2019

Converting webp files to more familiar formats in Ubuntu

With Google's efforts at better image compression, came an acquisition that gave rise to the webp image format. Although it was announced in 2010, I was surprised that Ubuntu 16.04 didn't support it natively.
To use it with Gimp, you need one of the latest versions. Good news is, ImageMagik supports it if you install webp. Once installed, you can batch convert your webp files to png too. Two simple steps.

To install:
sudo apt-get install webp

To convert all webp files in a directory to png:
find ./ -name "*.webp" -exec dwebp {} -o {}.png \;

To delete the original webp files after converting to png (though I'm sure there has to be a better way):
find ./ -name "*.webp" -exec dwebp {} -o {}.png \;; find . -type f -name '*.webp' -delete

12 November 2019

The precious thing frequently stolen from you: Sleep



More than seven years of noting observations and trying to correlate the causes of severe eye strain and poor vision, led me to the root cause: The lack of uninterrupted deep sleep for seven to eight hours every night. The funny part is, that if you ask anyone if they are getting enough sleep, they'll immediately say "yes", even though they are actually getting only around four or six hours of bad sleep. Even I said "Yes" to the first doctor who asked if I was getting sufficient sleep (when my eye strain was at its severest and I was getting only 4 hours sleep).

There are bodily repair processes that do not get completed if deep sleep is interrupted before 8 hours, and the debt accumulates over the years. I've confirmed this multiple times. There's a huge difference between "resting" and "8 hours uninterrupted sleep". I have good reason to say it's the lack of sleep and lack of proper nutrition that end up giving people weak vision and a lot of other health issues. Six hours or four hours sleep is not enough. The people who have been insisting for all these decades about seven to eight hours, were always correct.

Did these affect you?
  • Children being woken up early for school.
  • Children being told to stay awake late or wake up early to study during exams.
  • Children staying up late to watch TV or play video games etc.
  • Adults being forced to work late due to deadlines.
  • Having to use an alarm clock to wake and not be late for work or to cook breakfast.
  • Doctors being woken up for emergency cases.
  • Family members of patients being woken up during a hospital stay.
  • Taxi drivers and auto-rickshaw drivers losing sleep to make ends meet.
  • Phone calls and extraneous noises when sleeping.
  • Health issues that cause people to wake up once or more at night.
  • Improperly cooked food or adulterants or burnt particles in food affecting the digestive system and causing sleep loss.

Sleep Requirements researched by the National Sleep Foundation.

Is there anything we can do to change the culture of sleep loss?
  • Insist on properly cooked, unadulterated, un-burnt, healthy food and water at home, canteens and restaurants.
  • Allow for flexible work cultures and work-from-home options.
  • Allow schools, colleges and offices to begin at 11am for some people (night-birds) and at 9am for other people (larks). 
  • Spread awareness of this at school level and get a buy-in from parents and employers.
  • Arrange for better work shifts and recruit more people to handle workload.

We need to create ways to make this happen in a cut-throat rat-race. We've been through centuries of brainwashing about the heroics of equating hard-work with not sleeping. "How many people's health are you permanently willing to ruin in order to make a living?". Losing sleep even occasionally is not good. Don't allow people to nudge you into it. Don't nudge children into it.


There's no heroism in losing sleep.



Healing eye strain: https://nrecursions.blogspot.com/2020/11/the-real-cure-for-eye-strain.html


02 October 2019

Copy pasting and clearing screen in the Ubuntu terminal

Copy pasting with Ctrl+c and Ctrl+v works fine on the MacOS terminal, but doesn't work in Ubuntu. I assumed this may be some security feature or because Ctrl+c is the age-old command for an interrupt, so I didn't give it much thought and just used the mouse to copy paste.

But today it just struck me that I should find out the real reason, and viola! It's just a matter of pressing Shift.

To copy:
Shift+Ctrl+c

To paste:
Shift+Ctrl+v

and as a bonus:
To clear screen on the terminal:
Ctrl+L

This clear screen also supposedly works in Matlab, MySQL etc., though I can confirm it works on the Python terminal.

01 October 2019

Aquaplaning, and how to avoid it

Long back, I was curious about why Formula One racing cars had such "smooth" tyres. The racing slicks. Turns out, when there's no water on the road, it's actually more beneficial for more of the tyre to make contact with the road and provide more grip. Having grooves would lessen the grip. When the road is wet however, the grooves/treads on the tyres are absolutely necessary to prevent aquaplaning. The rain tyres allow water on the road to enter the grooves, thus allowing the remaining part of the tyre to make contact with the road and give better grip. Without this, the car would go completely out of control.

Exactly the same principle is used when designing footwear. The process of cutting such slits is called Siping. Recently, I purchased a new pair of rubber slippers and noticed that it didn't give any grip on wet surfaces. I even slipped and fell down once.

On examining the sole, I realized why.


No grooves.


So I took a knife and cut out some crude grooves all along the front, mid and back portions of the slippers. Just these crude grooves were enough to give a good grip on wet surfaces. I also wrote to the company, chiding them for not considering this basic design element. They wrote back thanking me for the valuable feedback and stating that they were the number one footwear brand in the country. The number one brand? With a safety aspect like this disregarded, I definitely don't consider them number one, but I'd be willing to consider it if they make the necessary design changes.

Update: The horizontal groove I made was a mistake. When the slippers flex when walking, the groove deepens and causes the rubber to break at that point. So the better option is to either cut grooves vertically or just buy new slippers with better soles.


02 September 2019

Realtime plotting in Python

If you intend to create plots/graphs with Python, your first choice may be Matplotlib. Don't use it unless your plots are extremely simple and isn't expected to grow more demanding with time. I used Matplotlib for realtime graph plotting for a really tiny graph and it was disappointingly slow. Moreover, it required installation of Python 3.6, which wasn't available readily for Ubuntu 16, and caused even more problems.

Then I came across PyQtGraph, and was impressed by the super-fast plotting speed and the mind-blowingly impressive variety of graphing functionalities. Really. You gotta see this.

Install it using: pip install pyqtgraph
Run the examples with: python3 -m pyqtgraph.examples
And prepare to be impressed!!!




I've come to understand that the rendering is quick because the underlying code is in C/C++ and the Python bindings are merely meant for invoking that code.


Still, even though the graphs are very impressive, the non-linearity of the code examples and the lack of code comments make it really hard for a newbie to understand how to get a basic graph running.

Here's where I help. After spending an extraordinarily long time figuring it out on my own, I've created a simple, basic example with which you can create a realtime graph. Hope it helps...


import time
import random
import pyqtgraph as pg
from collections import deque
from pyqtgraph.Qt import QtGui, QtCore

class Graph:
    def __init__(self, ):
        self.dat = deque()
        self.maxLen = 50#max number of data points to show on graph
        self.app = QtGui.QApplication([])
        self.win = pg.GraphicsWindow()
       
        self.p1 = self.win.addPlot(colspan=2)
        self.win.nextRow()
        self.p2 = self.win.addPlot(colspan=2)
        self.win.nextRow()
        self.p3 = self.win.addPlot(colspan=2)
       
        self.curve1 = self.p1.plot()
        self.curve2 = self.p2.plot()
        self.curve3 = self.p3.plot()
       
        graphUpdateSpeedMs = 50
        timer = QtCore.QTimer()#to create a thread that calls a function at intervals
        timer.timeout.connect(self.update)#the update function keeps getting called at intervals
        timer.start(graphUpdateSpeedMs)   
        QtGui.QApplication.instance().exec_()
       
    def update(self):
        if len(self.dat) > self.maxLen:
            self.dat.popleft() #remove oldest
        self.dat.append(random.randint(0,100)); 

        self.curve1.setData(self.dat)
        self.curve2.setData(self.dat)
        self.curve3.setData(self.dat)
        self.app.processEvents()  
       

if __name__ == '__main__':
    g = Graph()

   
    
 
________________________________


The fact that you are here means that you use the computer a lot. So please also take some time to understand the real cure for eye strain. Yes, it matters.




28 August 2019

Unable to signout / logout of GMail?

The fact that GMail used via the mobile web browser has such a silly bug that didn't get fixed even after I reported it thrice, is a sad state of affairs.

Anyway, if the signout menu isn't appearing, simply type "google.com" in the address bar and you'll see a signout button at the top right corner.

That's it!

07 August 2019

The 10X programmer


Can you call yourself a 10X programmer if you get work done ten times faster than other programmers or can do the work of 10 average programmers?
I don't think so.

There have been some discussions recently about 10X programmers, where some say it's a myth, some say it isn't, and some examine the logic of it. Even a CEO I knew, used to wish for a 10X programmer. He was completely bought into the concept, thinking that such programmers existed at top companies.

Here's my take on it:

Yes, there are programmers who can get work done faster than others.
Yes, there are programmers who are more expert at specific languages and skills than others.


But are any of the above programmers 10X? Nope! 


The measurement of 10X is not done based on how quickly a product was delivered with minimal errors.

10X is measured over a long duration based on:
  • Whether requirements have been understood, documented and verified with the customer.
  • Whether the software architecture and design patterns have been subject to peer-review from experienced people and is as future-proof as possible.
  • Whether the software language and tools have been chosen based on careful evaluation, as per the requirements and anticipated changes.
  • Whether version control, test-cases, bug-trackers, continuous integration and quality checks are performed.
  • Whether the programmer and the team share a good chemistry and fit well into company culture.
Face it. It only makes sense to measure 10X over a span of many years. A programmer who delivers poorly planned code quickly may seem like a hero initially, but when (s)he gets hit by a bus or when more members are added to a team or when the client requests more changes and the software suddenly requires a complete overhaul, that's when you realize that the initial 10X advantage you thought you got (even in a startup), is actually much more costly than if you had invested time in ensuring the bulleted points mentioned above were fulfilled.

I've seen plenty of programmers and companies getting stuck with trying to deliver quickly and then ending up wasting more than double that time making up for errors and unaccounted factors. Moreover, working overtime, trying to be 10X can also get people burnt out with severe health problems; some of which may be irreversible.


Don't go for a 10X programmer. Go for good planning, documentation, execution and teamwork. 
That's where the real 10X is.


01 August 2019

Solving the MokManager mmx64.efi Not Found errors and the missing Mok menu problem

Until I used Ubuntu 16.04, I didn't have much of a problem with UEFI. Just the first time it was confusing and took a while to find the solution, but everything else, like third party drivers and VirtualBox worked without problems.

But when trying to install Ubuntu 16.04.6, the system wouldn't even start. It showed the below message and shutdown.

Unable to find mmx64.efi file:


Failed to open \EFI\BOOT\mmx64.efi - Not Found.
Something has gone seriously wrong.

It sounded like Russel Peter's Dad saying "Somebody's gonna get hurt real bad".

For a long time, searching the internet didn't yield a solution, but some posts mentioned renaming grubx64.efi to mmx64.efi. The trouble with that is, that if you try to rename the file in Ubuntu, it won't work. Ubuntu shows you a totally different filesystem. You have to go to Windows. In Windows, you won't be able to see all the files in the pen drive. It just shows you one folder into which you have to navigate into, find the grubx64.efi file and rename it to mmx64.efi.
Viola! You'll now be able to boot from the pen drive.

Funny thing is, after installing Ubuntu, you have to rename that file on the pen drive back to grubx64.efi (and you have to do it in Windows; not in Ubuntu), or else you won't be able to boot from the pen drive.



Need to set the Mok state after reboot but the screen never shows up:

When installing VirtualBox or the third party drivers in Ubuntu, the screen says that on reboot, you'll have to type a password to enroll mok.


You'll notice VirtualBox generating a private key for Mok

However, when you reboot, you are never presented with any such mok screen.
What you are supposed to do to be able to see the mok screen is this:
  • Go to BIOS. 
  • In the security page, select the option to "specify a trusted key".
  • Navigate to "Ubuntu".



  • Select "mmx64.efi", give it a name like "MokManager" or anything you like, save and exit BIOS and come back to BIOS again.


  • This time in the Boot screen you'll see new boot options. Select the "MokManager" option and move it to the top so that it boots first. Save and exit BIOS.


  • Now when you boot you'll see the Mok menu from which you can enroll the mok key that was generated by Virtual Box or the Ubuntu installer.

That's it. That's the secret of how to do MokManagement. There's no need of disabling UEFI. There's no need of disabling secure boot.

I just wish the OEM people and OS manufacturers came up with a standard which wouldn't require such complicated workarounds.

Say thank you or donate

07 July 2019

Ather. My first impressions on my visit and test ride

I had been hoping to visit the Ather center at Indiranagar for a little more than a year. Was passing by today, so dropped in. I'm not a bike expert or enthusiast, so these are just my first impressions. I've also mentioned a lot of the questions I asked them and what answers I received. I haven't yet verified the veracity of the replies.



Took the bike for a test ride and noticed a lot of heads turning when they heard the unique "whoooieeee" sound of the bike :-) The disc brakes can bring the bike to a halt quite fast, and can make the bike skid a little. When this happened, the noise irritated a dog, and it began barking and chasing me. The acceleration from the bike was so good that the dog couldn't keep up. I would've never escaped this easily on my geared bike :-)

  What's good
  • The bike looks smart from the front and side.
  • Good acceleration.
  • Good quality belts (they say it's reinforced with carbon-fibre and can last 60K to 90K kilometer).
  • Low center of gravity, so could ride it at even 3 kmph.  
  • A reasonably pleasant experience when riding.
  • Good road grip and balance.
  • Reasonable turning radius.
  • Good control.
  • In general, body parts seem to have a reasonably good quality.
  • Reasonably smooth ride. 
  • Hassle-free test ride process, polite, intelligent, helpful and down-to-earth people.
  • Indicator lights switch off automatically when a turn is detected or after a certain number of seconds.
  • Large boot area to keep even a full-face helmet, and extra pockets for keeping documents, first-aid-kit etc. below the seat.
  • There don't seem to be parts that would need frequent replacement like in petrol bikes. 
  • The dash provides info about tyre pressure (okay, this is super cool!). There's an extra attachment that enables this functionality.
  • Headlight seemed bright enough.
  • Alloy wheels and tubeless tyre.
  • The onboard map was a fabulous feature (though I could do without it).
  • The functionality to move in reverse was superb! Not really necessary if you have strong legs, but useful.
  • They show you details of your test ride with some lovely graphics. 

(I'm not entirely sure this was the ride I took, because it certainly didn't feel like I rode for 31 min, and the screen showed that I didn't go on 80 ft road, but I actually did, immediately after the dog-chase).


What can be improved
  • The rear area of the bike is kind-of exposed and high above the wheel, which makes it look ugly.
  • The noise produced by the bike is loud and annoying. Some kind of a silencer would be nice. An Ather representative mentioned that some people like the sound, and it's like how the Bullet bike had a signature sound. Well, no point telling me that. I dislike the sound (later I found that the iQube and Chetak electric bikes were much quieter. I don't see why Ather can't be quieter, even if it requires a re-design). The last thing you'd want is to have a road full of noisy vehicles!
  • The physical buttons are a bit hard to reach with the thumbs. 
  • When moving on a road hump, the rear suspension clangs, which makes it feel like as though a helmet in the boot is getting jostled around even if there's nothing in the boot (As of 2021 they've fixed this).
  • The company knows your exact travel path. Data privacy issue.
  • The handle grip felt too hard and straight. I'm not sure if it was the fact that it was too thin, that made me need to grip it harder or just the hardness, but it felt uncomfortable for long duration use (In 2021 I realized that the real problem was that it was hard to twist the acceleration throttle and keep it twisted).
  • When the bike is driven with uneven speeds for a while, a fan turns on for cooling. The noise from it can be extremely annoying (As of Oct 2019, I hear they've made it less noisy).
  • Although the bike has an incognito mode, it gets disabled the next day and data about your ride is transmitted to the company server again unless you remember to disable it.
  • When using the key to lock or unlock the bike, the quality of the locking mechanism didn't seem as good as I would've expected from such an expensive bike. There was a certain amount of shakiness or some odd feeling that didn't lend it a perception of excellent quality (although you could say it was good-enough quality). The physical buttons also seemed to be of ordinary quality. As of 2021, it's good.
  • Slight chance of the bike being difficult on your back muscles due to the positioning of the handle, and the seat design.
  • At speeds below 20kmph, there can be a bit of a dragging/rough feeling, which is probably because of the belt, but it's tolerable. As of 2021, I didn't feel any such problem.
  • The headlight is always on. BIS regulation. I think this rule was discontinued later.
  • The seat locking system was unreliable. It should've just been a mechanism where you can push downward and the seat gets locked, but they designed it so that it needs to be dropped from a height of 1 or 2 feet, and I had to drop it multiple times until it got locked. A bit annoying even if practice makes perfect. 
  • I was not informed of what the procedures would be if I encountered an accident during the test ride. (update: In 2021 when I asked, they said the damages to the bike are on them, but injuries to the rider need to be borne by the rider).
  • If parked under the hot afternoon sun for too long, there's a good chance it could be bad for the battery. Heat is always bad for batteries.
  • The suspension was rather stiff, and they said they couldn't adjust it. It's designed that way to strike a balance between control and comfort.
  • If you aren't covered under insurance, the damage to parts or scratches fixing might cost you a bit more than the average bike.
  • Battery life: Will decrease with time. By the 5th or 6th year it may give only 25km on a single charge (this is what I was told by one person and another person said it'd be more than 25km), but the power of the drive won't be affected.
  • Many parts of the bike were quite pointy. A more curved design would look better (just my opinion).

Questions I asked and responses
  • Units of electricity consumed: Per charge, 3 units. Approx. Rs.20.
  • Charging via solar or inverter: Yes, but only if 1KW and can last for 4.5 hours.
  • Space at footrest for carrying gas cylinder or 20L water: Yes.
  • Doorstep servicing charge if not opting for Rs.8000 or Rs.6000 plan: Rs. 1500 to Rs.1800. 
  • Servicing interval: Every 5000km. Doorstep servicing.
  • Battery cost: Rs.35K to 45K (price is reducing).
  • Battery protection from water: Yes. Can survive complete submerging for 30 min.
  • Riding in water-logged road: Yes. Some dirt may get lodged between wheel area, but will come off after riding a while. Roadside assistance also available.
  • Assistance and servicing radius: Within Bangalore only for now. Plans to setup in Chennai and Hyderabad too.
  • Time for charging: For single phase AC, it takes 4.5hr (at your home) and for 3 phase DC (at Ather charging points), it charges at a rate of giving you 1km range per 1 min of charging. Fast charging isn't good for battery life.
  • RTO visit when buying bike: No need.
  • Exchange offer for old bike: No. They've considered it, but found it impractical. As of July 2020, Ather is actually offering a bike exchange via a third party!!!
  • Charging in apartment basement: Difficult unless you have reserved parking space. Their team can provide a fixed charging point for free for 20m from the electricity meter, but any extra length of wire you'll have to pay.
  • If company closes: Unlikely because they are backed by biggies and the demand for EV's is growing, but if a shutdown happens, they are legally obliged to continue offering servicing for 10 years.
  • Lithium availability: At least 10 years or more.
  • Charging stations: They plan to have one every 1.5km by end of one year.
  • Oiling and greasing requirement: No. Will be done during servicing.
  • Theft: Not easy to remove battery. If bike is stolen, when it's switched on, the location will be transmitted.
  • Max weight: 165kg without loss of efficiency.
  • Insurance provider: Go Digit.
  • Cost of insurance: Rs.6000 for 5 years. First year is comprehensive insurance (bumper to bumper). Second year onward, third party insurance only. If you want comprehensive insurance, you'll have to pay Rs.1500.
  • Wait time after placing order: 3 months. You have the option to postpone the delivery/buy date at no extra charge. Now it's 15 days.
  • Lease option: Bike can be taken on lease and returned after the lease period if not satisfied.
  • Portable charger same as fixed charger: Yes. The fixed charger only provides the convenience of being fixed at the parking spot.
  • Not using bike for some time: Bike has a shutdown mode in which it won't draw power from peripherals, and can safely last for around 2 months in this state.
  • Battery explosion possibility: The person said this is unlikely because of the way in which the charging and discharging is managed, but I wasn't fully convinced. In any case, we have been carrying highly inflammable material in petrol vehicle tanks. Whether batteries are safe or not, time will tell. (Update 2020: The government ordered a probe into Ola and Okinawa bikes catching fire)


My wish-list for electric vehicles
  • Matte finish body and options for grey shades instead of just white (Ather 450X is released in a lovely grey shade).
  • Separation of vehicle performance data sent to the company and vehicle location data. I don't mind sending performance data, but sending location data is a violation of privacy. Some people just don't seem to understand why that's a problem.
  • Physical buttons that are easier to access with the thumbs.
  • Option to sell old bike like at Maruti True Value (As of July 2020, Ather is offering an exchange option).
  • A press-to-lock mechanism for the seat (when closing it after storing something in the under-seat compartment) instead of a drop-to-lock.
  • Switching between eco and sport mode without having to stop the bike (as of 2021, this is available).
  • Option to switch off the headlight.
  • Capability to display the driving license, bike registration and insurance certificate on the dash, to show to traffic police when they stop bike for checks (As of 2021, this is available).
  • Safety mechanisms to prevent injury in case of battery explosion.
  • A less noisy cooling fan (as of Oct 2019, I hear they've already made it quieter)
  • Drum brakes instead of disc brakes (I don't want to depend on brake fluid).
  • A covered rear wheel area, instead of leaving it so exposed.
  • Rat-proofing: Sometimes rats chew away at wires or rubber tubes etc. Since Ather's drive belt is made of material that a rat can chew off (and expensive. Each belt costs around Rs.8000), I hope there would be some kind of rat-proofing.  
  • In Bangalore, even the pillion rider needs to wear a helmet, so it'd help if the bike has some kind of a pre-built lock or extra space under the seat to ensure that two helmets could be stored/locked on the bike.
  • Wide-angle camera at the front and back to record the trip (locally; not on the cloud) for safety purposes.
  • Removable batteries that can be exchanged/rented for charged batteries at charging stations, where the batteries can be tracked via blockchain. This would eliminate the need to charge batteries at home (especially helpful if you stay at an apartment complex). The video below shows many such bikes with removable batteries.
  • Fewer (or zero) power-cuts in Bangalore and more solar electricity. Especially on roof-tops and parking spaces (this is of course not a bike feature, but it's part of the wishlist anyway).
This solar parking space was built by Tata Power (as I remember)


Overall, the Ather was a nice bike to ride. Happy that it is designed and manufactured in India. They've got a forum where people share their experiences. Given that there are quite a few points on my wishlist that would remain unfulfilled, the high cost of the vehicle and given the current difficulties in finding charging points and also the person mentioning that they wouldn't be able to make hardware changes (like the handle button position) easily, I'd probably not buy an Ather for a rather long time. If I do decide to buy, the review process is going to be far more detailed than this.


Ather vs. petrol bikes
A somewhat practical analysis of the costs of Ather vs. petrol bikes is done on this website and this website.


Alien and mosquito designs
I had a look at a lot of other electric bike photos, and almost all of them have a pointy, mosquito or alien look. If any designer is reading this post: Please design a bike that looks like something a common citizen would want to buy.



Have you ever tried an Ather or another electric bike? What was your experience like?






06 July 2019

Using dd instead of disk and partition cloners like CloneZilla or PartImage

The problem with applications like CloneZilla is that although they are excellent for disk imaging, they have very un-intuitive interfaces, the number of steps they make you go through is huge and they suffer from problems with UEFI when creating a USB version.

Linux's dd command on the other hand, is projected as being very dangerous and people say it's better to use something like CloneZilla just to be safe. But from what I've seen, as long as you type the command properly, dd is actually far more convenient than the other applications. If you want a safer GUI version, there's GDiskDump and KinDD.

Here are some useful commands:

To compress and clone entire sda onto a folder on sdb or sdc:

*** Caution: Verify all the commands below before executing them ***
*** Caution: The folder paths and partitions will be different for you *** 

When you plugin the pen drive or external hard disk, it'll get mounted as sdb or sdc. Find out where it got mounted. Mine was in /media/ubuntu/Nav/ and it was in sdc, since sdb was the Ubuntu startup USB. Created a folder named "bkp" in Nav and:
sudo dd bs=1M if=/dev/sda | gzip > /media/ubuntu/Nav/bkp/backup.img.gz
Don't worry. Even though sdc and sdb are mounted on /media, which is the root folder (and hence you'd think it's part of sda), Linux knows that these are mounted filesystems, so it won't consider it part of sda.
Instead of using bs=1M, you could speed it up by checking what your disk buffer size is using sudo hdparm -i /dev/sda, and set that as the bs value. So if the buffer size is 8MB, set bs=8M.

If the disk was not automatically mounted, you can mount it yourself using:
cd mnt/
sudo mkdir bkp
mount /dev/sdc1 /mnt/bkp

Now take a backup
sudo dd bs=8M if=/dev/sda | gzip > /mnt/bkp/backup.img.gz

Restoring sda is done via:
sudo gunzip -kv /mnt/bkp/backup.img.gz | dd of=/dev/sda
 
Taking a backup of sda means that even unallocated space gets backed up, and that can take very long (3.6 hours for a 500GB HDD). If you don't need a full disk backup and can manage with just the few numbered sda partitions, then just do a backup and restore of sda1, sda2 etc. To do that you'll have to also backup and restore a copy of the partition table as shown below.

You can take a copy of the partition table info using:
sudo sfdisk -d /dev/sda > my_partitions

Now create backups (these commands are a bit risky because you have to take care to not mess up the "if" and "of". Safer commands are shown below):
sudo dd if=/dev/sda1 of=/media/ubuntu/Nav/bkp/sda1.img bs=8M
sudo dd if=/dev/sda2 of=/media/ubuntu/Nav/bkp/sda2.img bs=8M

Restoring  the partition table info is done via:
sudo sfdisk --force /dev/sda < my_partitions

Restoring backups:
sudo dd if=/media/ubuntu/Nav/bkp/sda1.img of=/dev/sda1 bs=8M
sudo dd if=/media/ubuntu/Nav/bkp/sda2.img of=/dev/sda2 bs=8M

In Ubuntu, you can make use of a default sound file to tell you when the operation completes:
alias beep='paplay /usr/share/sounds/freedesktop/stereo/complete.oga'
 

Okay, so the safer commands are:
sudo dd bs=8M if=/dev/sda1 | gzip > /mnt/bkp/sda1.img.gz; beep
sudo dd bs=8M if=/dev/sda2 | gzip > /mnt/bkp/sda2.img.gz; beep

Restoring sda is done via:
gunzip -c -k /mnt/bkp/sda1.img.gz | sudo dd of=/dev/sda1; beep
gunzip -c -k /mnt/bkp/sda2.img.gz | sudo dd of=/dev/sda2; beep

The "-k" helps avoid deleting the original gz file after it is extracted. The "-c" performs the extraction in memory and writes to the output disk, instead of temporarily extracting to the input disk. The good part about these safer commands is that they also compress the backup, which saves you a good amount of space. I recommend taking backups of each partition separately instead of taking a full disk backup or directly backing up the entire sda, because having separate partition backups helps restore them separately too.


To wipe the first 1MB of any disk:

sudo dd if=/dev/zero of=/dev/sdb bs=1M count=1

Here, the "b" highlighted in bold red should be changed to "a" or "c" etc., based on which disk's first 1MB you want to wipe. The partition information will disappear, so this command is useful when trying to re-purpose any disk. Once the command is run, just use GParted to create the partitions.


To write zeros onto the entire disk:

sudo dd if=/dev/zero of=/dev/sda bs=4096

This is helpful when you want to experiment with whether dd works well for backups. I used this command to fill the disk with zeros, then installed Windows and tried backing up. The 500GB disk with around 20GB of data on the Windows partition got gzip backed up into 12GB. The high compression was because the rest of the disk was full of zeros.
 

To view the progress of dd:
 
pv is the short form of "pipe viewer". It's a handy little program that helps monitor the progress of data through a pipe. When used with dd, it'll show you the progress of the operation in terms of the amount of time remaining for completion and the progress in terms of the number of MB or GB.

sudo apt-get install -y pv
sudo dd if=/dev/sdb | pv | dd of=/thePath/theFilename


14 June 2019

Do you check the checksum's of downloaded files?

It's usually unnecessary, but always recommended. Let's say you download CloneZilla and they've provided their file for download from a website like SourceForge. There's always a slight chance that some hacker/attacker could've altered the file, added some malware to it and replaced the file on SourceForge.

But you can check whether it's the original file that CloneZilla had uploaded to SourceForge, using the checksum.

I had downloaded clonezilla-live-20190420-disco-amd64.iso which had the MD5 checksum: 981841de868ccc0c927dea9ace9460fa as shown on the CloneZilla website.

Now to verify the file I just opened up a terminal and typed
md5sum clonezilla-live-20190420-disco-amd64.iso.

The output was:
981841de868ccc0c927dea9ace9460fa  clonezilla-live-20190420-disco-amd64.iso

A perfect match! It's that simple.
 
If it's SHA 256, do this (it was for verifying the Android studio download): 
sha256sum android-studio-ide-193.6626763-linux.tar.gz

 
Update May 2022: 
The Ubuntu team showed us a new way of verifying the checksum:
echo "b85286d9855f549ed9895763519f6a295a7698fb9c5c5345811b3eefadfb6f07 *ubuntu-22.04-desktop-amd64.iso" | shasum -a 256 --check

If it's verified correctly, it shows the following output:
ubuntu-22.04-desktop-amd64.iso: OK

Even if you download from a mirror, it should show the same checksum. That way you know the image on the mirror was not tampered with.

12 June 2019

Get rid of the Error in appstreamcli: double free or corruption

This is for my personal reference. Immediately after installing Ubuntu 16.04 and trying to update it, this appstreamcli error shows up and it takes a while to search for the solutions to it.

 

The solution is:
sudo apt install --reinstall libappstream3

or

sudo apt-get purge libappstream3

Obtained from here.