WSL Issues

How to fix “Access is denied” error when starting WSL?

Shutdown WSL using the following command in any terminal. Don’t worry, this will NOT shutdown your windows PC.

wsl --shutdown

Once the above command returns, start bash as administrator. WSL should greet you with Linux prompt.

How to upgrade WSL – Ubuntu LTS Linux distribution?

Update and upgrade apt repositories using commands below.

sudo apt update
sudo apt upgrade

Check availability of upgrade using the command below.

sudo do-release-upgrade -c

If upgrade is available, upgrade using the command below.

sudo do-release-upgrade

If for some reason it does not work, try with -p option like below.

sudo do-release-upgrade -p

To see what options available using the upgrade tool, run the command below.

sudo do-release-upgrade --help

How to fix “Restoring original system state. Aborting” error when upgrading WSL – Ubuntu distribution?

Sometimes, when upgrading the Linux distribution, the upgrade fails silently with the below messages.

Restoring original system state

Aborting
Reading package lists... Done    
Building dependency tree          
Reading state information... Done

See why the upgrades are failing by running the following command.

cat /var/log/dist-upgrade/main.log

Most likely, snapd and screen are causing the upgrade to fail. Remove these programs by running the below commands.

sudo apt purge snapd

sudo apt purge screen

If this is not the reason upgrades are failing, check the log and resolve any other issue that is reported in the log. Once all the issues are resolve, the release upgrade should complete successfully.

Replacing Bad Hard Drive in Linux

This is an eventual possibility that one has to deal with someday when dealing with self maintained Linux systems. Due to many possible reasons a hard drive may develop unrecoverable bad sectors. The easiest approach to the solution is described here, not to mention that you have to be a little lucky for the drive to not fail on you in its totality.

If you want to try out your luck, please follow below steps:

  • Buy a new hard drive of equal or greater specifications.
  • Create a USB flash drive or USB hard drive for Clonezilla following instructions given here.
  • Shutdown the system.
  • Connect the new hard drive to the system. Do not remove the bad hard drive yet, as we are going to use that as a source for cloning the disks/partitions to the new hard drive.
  • Now connect the Clonezilla live USB hard drive to the system and boot.
  • System will boot into Clonezilla.
  • Follow the guidelines and select device to device or disk to disk path.
  • On the source disk/partition option select the old bad hard drive/partition.
  • On the destination disk/partition option select the new hard drive/partition.
  • Make selections based on your preference on next few steps.
  • Start the cloning process.
  • This will complete successfully, if Clonezilla reports bad sectors and cannot clone a particular partition, do not worry yet, let the process complete. Clonezilla will now suggest running the command with rescue option.
  • Restart Clonezilla and follow the same process (except now you can select the particular partition that failed in the previous step instead of the whole disk), but on the confirmation step at last, after every option was supplied, select NO to proceed. Clonezilla will save a file with the command it created.
  • Given an option to go to Clonezilla command line, go there.
  • Copy the command that is saved in the file and append the –rescue option and run the command.
  • Clonezilla will report warnings but will complete successfully.
  • Once Clonezilla completes, shutdown the system and remove the Clonezilla USB hard drive from the system.
  • Remove the old bad hard drive from the system.
  • Reboot.
  • The system should now have a valid and good hard drive with few missing data. This is at least a better option when you have to choose between entire loss versus loosing a little.

One of the helpful articles about finding bad sectors on a hard disk is referred below.

How to Check Bad Sectors or Bad Blocks on Hard Disk in Linux?

Linux: Setting static IPv4 address using terminal

Once logged into the linux machine, edit /etc/network/interfaces file using your favorite text editor. You would see something like this at the end of the file:

iface eno1 inet dhcp

Change the content of this line to say static instead of dhcp. Also add the other parameters as shown in the below code.

iface eno1 inet static
    address 192.168.1.10
    gateway 192.168.1.1
    netmask 255.255.255.0
    dns-nameservers 192.168.1.1

Additionally to set IPv6 address to auto after the above set of lines as shown below.

iface eno1 inet6 auto

Save and exit the editor. Reboot the system.

Linux: SSH login without password

Remote Linux servers can be administered using SSH. Normally, local machine can connect to these servers using SSH using user id/password combination. Local machine can also be configured to remote into these servers using SSH without password.

To make it work we have to generate a public/private key pair using ssh-keygen, and subsequently copy the public key using ssh-copy-id to remote server’s authorized_keys file.

The simplest use is:

$ ssh-keygen

$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote_server

For more information, there is a very informative blog written about this here.