Sunday, May 24, 2020

My Linux Journey

It started out innocent enough. Back around 2003 or 04, I ended up with an old laptop that I had no use for. I’d been interested in Linux, so I decided to obtain the installation files for Debian and install it on this laptop. This all happened prior to getting a cable modem; it would have probably taken a week to download them using my modem. So I paid to obtain the disks for the cost of the CDs and shipping. They arrived one day, and I attempted an install. After some time, I finished the install, and I was staring at a command line. The little cursor blinked at me, or was that a sarcastic wink?

It’s not that I was unfamiliar with working from a command line. I learned my chops first on a DCL machine (that’s Digital Command Language) back in the 80s, and after that, on MSDos. I reluctantly bought in 1994, a laptop with Windows 3.11; I was so reluctant to give up my command line, familiar as I was with typing a program’s name into the terminal to run it. Of course, I grew to love Windows, in a love/hate sort of way, and became an “expert” in that interface even as I had in MSDos.

But this wasn’t MSDos. Only one or two of the commands I recalled from my MSDos days appeared to work in this alien world. So I started the process of figuring how to access the help pages and began the task of learning a new system. However, I didn’t get very far. I tried to install X-windows, a graphical “windows manager” (which I now know is not the same thing as a complete desktop environment). All I ever did back then was to see a big “X” across the screen. No menu, no buttons, nothing. Then, as fate would have it, I did something that trapped me in the X-window. I couldn’t use the command line nor do anything. Even reboots would log me back onto the giant X window. I finally gave up.

Ironically, these last two days I’ve been testing out installing the “Vanilla” Debian first in VirtualBox, then on my living room backup laptop, which I had before I received my current one—about a month before we moved to Colorado in 2018. I’ve successfully installed it, though it has a long install process compared to your average Linux distro.

It ended up crashing it in Virtualbox. But not before I learned enough that I was ready to install it onto my living room laptop. So I did, and it is now up and running. It has progressed a lot since the early 2000s. For instance, when a newbie like myself starts tinkering with attempting to pull together a desktop environment, not knowing that was what I needed, I was lost, alone, and clueless about what direction I needed to go. But, the Debian I installed lately had several desktop environments that I could use. So, I picked my favorite so far—Cinnamon--and when it was finally done, I booted up into a fully functional graphical interface that I was already familiar with along with a system that I only had to make about two or three tweaks to obtain a fully functional system.

“Tweaks to obtain a fully functional system? What?”

Yep, you heard right. And my experience probably only will go to show why installing a system like Debian is a bigger task than Linux Mint, especially for someone who is unfamiliar with how Linux works. I, on the other hand, have been using Linux by this point for 9 years. I realized it had been that long when Facebook offered up one of those “Remember When” post for me to share with everyone (which I didn’t share; you can thank me later) that was 9 years old, and wanted me to share a post I had done on my experience of getting a fully functional Linux system up for the first time that had become my default operating system I used on a regular basis. I kept a dual boot into Windows to run QuickBooks, which doesn’t play very well, even using Wine. I’ll give you one example of what I had to do, right out of the box.

Once the install on Debian was done, I started to work on setting up the ssh server. Ssh is a way for a user using a computer, to log in and work on another computer. One can open it up to the Internet, but in my case, I only needed to go over the network. At any rate, one of the first task in setting up an ssh server is adding a user to the new system that will give me the ability to log in from the other computer. I like to use the adduser command. So, I typed in the command, followed by my user name and group. Well, Debian couldn’t appear to locate the command. I thought “What? How could the system be missing such a foundational command?” It didn’t make any sense. I tried useradd, with the same results.

So after a bit of exploring, I attempted to install the adduser command. It said it was already installed. “Ahhhh!” the problem appeared solved, to a degree. Because Linux has at least one similarity with Windows, the PATH variable. It does the same thing as it does in Windows as well, which is to tell the system where to look for executable programs that you want to run, no matter where you initiate them from in the directory structure. So I went to Google and did a search on what directory adduser would be found in (it was in the /usr/sbin directory). Then I printed out the PATH variable, and sure enough it wasn’t there. So, all I had to do was to include it in the PATH directory, and all would be right in the Debian world, right! Well, sort of, in that even that task became something of a problem.

You see, in Windows, there is one file that the path command goes in. The commands for it are very similar. In windows, it is:

PATH=%PATH%;C:\\directory to add to the path statement

Pre-XP, to make it permanent, one would add it to the “autoexec.bat” file, a file Windows would run every time the system booted up. XP and those that followed, it was added to the advanced system under “Environmental Variables” graphically. So, in Windows, for any one version, there was only one file or place you had to edit to add a directory to the PATH variable and have it stick from session to session.

Not so in Linux. First you have several spots you could add it to for the individual user (at least 3 files), or several spots (at least 4 files) for every user. Now, these are easy enough to find upon searching on the internet, as I did. However, whether it was due to it being entered in at the wrong time so that it was overwritten, or the system ignored each file that I put the path statement in, for whatever reason, None of them worked. I believe I tried every file I could find to put my path statement in, which was:

Export PATH=$Path:/usr/sbin

The export command is the part unique to Linux, but it shouldn’t always be used, as I soon discovered. One of the system-wide files I entered this command into was located in the file: /etc/profiles. Once I entered the command in and rebooted, it booted up as far as the login screen. I entered my password, and it went away, only to have the login reappear. So, figuring I must have entered the password in wrong, I entered it again only to have it do the same thing. I must have entered my password in 5-7 times, the last couple of times carefully entering in my password. It still came back. I had to come to one conclusion: that the file required the path statement without the export command. Why? I don’t know. That’s just the way it is.

Now, I could have just deleted the system off of Virtualbox. It was, after all, just a test. However, I wasn’t ready to give up on it, just yet. I had to figure out a way to get into the system, edit that file, and take the “export” part out. After doing a few searches on the internet, the only solution I had found was a cryptic editing of the kernel, by adding a -l on the end of it, that would allow me to bypass the login screen. However, when I reached the point of adding that to the kernel file, it didn’t quite look the same. I was unsure where to put the -l and I said to myself, “There has to be an easier way to do this. Editing the load kernel command was too deep and crazy way to do this.” And, behold! There was an easier, more user friendly way to accomplish this.

I sort of stumbled upon it, though it is probably common knowledge among experienced Linux users. Once the grub boot menu appeared, I selected the “Advanced” option of the operating system. Then I opted for the recovery/command line to go into root. I was in! I edited the “export” off the file, saved it, then rebooted. I went into the login screen and upon entering the password, I stood on the pathway to success! All was well, once again, in the Debian world.

Sort of, because when I checked the PATH variable, it still didn’t show the sbin directory under the usr directory. So I was back to square one. I checked the websites once again, and there was one file I had yet to try: bashrc in the HOME directory. However, the preferred way to add any changes to that file was to enter them in a different file, under a different directory, and include them in the bashrc file. I knew the system processed this file too, because I had already done this with some aliases I had set up. Aliases like twifi, which ran the command:

bash /home/rick/MyScripts/ToggleWiFi.sh

To turn on and off my wifi. All I would have to do in a terminal window to run that would be to enter twifi.

I started to edit the .bashrc file to have it include a different file, when it dawned upon me that the first system upgrade would replaced that file, then I would have to add those lines back in. Though it was sort of like cheating, I knew the .bash_aliases file would to included by default in any new file. So I edited that file to add to the path the desired directories. Once I had saved it, rebooted, and checked the path statement. I held my hands up in a victory shout as the desired directories were in the PATH variable, finally!

That is just one example of my “tweaks” I did to get a more fully functional system. I do have to say, that a major Linux distribution upon which Ubuntu (and several others that are based off of Ubuntu) as well as a smattering of others, who has been around for this long, could have such a simple-to-fix-bug in it. This is exactly the kind of experience that keeps Windows users from moving to Linux. But be assured, Windows user, that distributions such as Ubuntu and Linux Mint don’t have this problem. They generally work like you would expect them too. I’d point any Linux newbie to install one of those distros as your first one. But in Debian’s favor, it has come a long way toward being more user friendly than when I installed it almost 20 years ago.

But between my first attempt at installing Debian and the last successful attempt to install it on my backup laptop—an Acer Aspire—I’ve installed several different distributions on the old laptop. All of the distros, a small handful requiring some tweaking, have been successful installs. I’ve used them for various lengths of time. Most all of them picked up my Brother network printer without a hitch, which for my previous experience is very, very good. In the past, I’ve had to fiddle with the drivers and various settings before I could get it to work.

My first working Linux distro (short for distribution) was Lubuntu using the LXDE desktop environment. I used it on a test laptop that was “resource challenged” before being confident that I could install it on my main laptop. I worked on and off for over 4 or 5 months of setting it up just the way I liked it. This is when I made that Facebook post 9 years ago. I stuck with that OS (operating system) for quite some time before trying other distros. From there I installed Xubuntu (uses the Xfce desktop environment) on my main computer. Then a few months ago, back around Aug. 2018, I ordered a new computer, an HP Laptop with 2 T of HD space. It had Windows 10 installed on it. Up until then, I had a dual-boot system, MS Windows 8 and Xubuntu on my Aspire. With this computer, however, I decided to go totally Linux, something I could do since I no longer needed to use Quickbooks. More on that in a future post. And, I decided to go with a totally new distro, Linux Mint. I was impressed with Mint’s Cinnamon desktop, which I fell in love with. Mainly because of both the slick looking interface and the flexible and intuitive structure of the settings menus. In short, it simply works as a desktop environment.

I also need to back up a bit to describe my Linux HD transplant. My son had bought, some years ago, a new Asus laptop. After a period of use, his hard drive crashed and he was ready to throw it away. I told him to hold on, I would take it. I figured I would get a hard drive for it and I would have a new computer. But, I promptly forgot all about it. Then, a few years later I discovered Lubuntu, a version of Ubuntu that used the memory efficient LXDE desktop environment. While I was on it, I accidentally spilled some coffee on the keyboard, effectively causing the keyboard to be near usable. My immediate solution was to go and get a usb keyboard, and I continued using the computer that way.

Meanwhile, I came across my son’s old Asus laptop. It had been long enough that I forgot what was even wrong with it. An attempt to boot up failed, reminding me that it was the hard drive’s boot blocks on the disk that caused the issue. So I did a search on Amazon for hard drives, and discovered a 1 terabyte drive I could obtain for a reasonable price, so I bought it, and I installed Lubutu on it successfully. Once I had it up and running, I liked using it better than my old Acer computer. So after transferring my files over to the Asus laptop, it became my primary laptop that I used day in and day out. That is, until another cup of coffee, or it may have been sweet tea, was dumped over the keyboard, yet again. This time, it totally made the keyboard unusable as well as affecting the computer itself. I could use the external keyboard, but it became difficult to get around to the point that it was an unusable computer.

Problem was, I didn’t have enough money to buy a new computer. All I had was my Acer Aspire computer to fall back on. The problem with that was my current files and work was on the hard drive now trapped inside an unusable computer. What to do?

Then I had an idea, though I didn’t know if it was even possible at the time. So I did a search on the Internet to find out if it was possible to move a hard drive, and transplant it into a different laptop, and have it work. I expected to find a big negative to that question, but to my surprise I discovered that it was indeed possible. However, in my case, since I was moving from a “Legacy” computer to an EFI booting computer, that I would need to go in and adjust the partitions on the drive to make space to create an EFI partition. Naturally I found this out after I attempted to simply move the HD over to the new computer and it failed to boot. I was successful in reducing the size of the main partition, and creating an EFI partition, and installing the boot software to it, that when I plugged it in the next time, I saw my old system’s login, and after a little checking, I could access all my files. I hadn’t lost one of them. I breathed a big sigh of relief.

For the record, just know that this is something that cannot be done if I still had a Windows system. They link their OS to the computer it comes with. You take that HD out and stick in another computer, you’ll have two broken systems. I was a wee bit proud that I had successfully navigated the “Linux rapids” and had pulled off such a major operation that when I turned on the computer and it began booting up into my familiar system, I said, “It lives! It LIVES!!! Haaaaaa, ha, ha, ha, ha!”

Of course, I was back to using my old computer which required me to use an external keyboard. But hey, at least I was operational again, except this time with a full terabyte HD. So I used it until I had the money for a new computer which happened in the summer of 2018. By that time, I had installed Xubuntu on my old Acer Aspire and had been using it for a few months. So when I bought this HP laptop, that I am currently using, I decided I would move the pre-installed Windows 10 from a dual boot situation and install it in VirtualBox once I had my new Linux system up and running.

I also decided I would install a completely new distro, and I decided to first try Linux Mint. After installing that distro, I immediately fell in love with it. It simply worked out of the box, and it was fairly intuitive. I’ll probably do a post on why I like Linux Mint and why I recommend it to Linux newbies in a later post. I’ve also installed and used briefly the following Linux distros, in no particular order: Linux Mint Debian (this is a version of Linux Mint based on Debian instead of Ubuntu, which the standard one is based on Ubuntu), PCLinusOS with the MATE DE (desktop environment), POP OS, Ubuntu Studio (current installed as a dual boot on my main computer)Ubuntu Bungee, Zorin OS, Manjaro (this is the only Arch-based distro that I tried), and possibly one or two others I might have forgotten. Distro hopping? No, not really. I basically wanted to get a good feel and flavor of the different distros out there. So for a time I was installing a new distro nearly every week. I’ve had Debian installed on it for 2 or 3 weeks now. I’ll probably stick with it, using it to test out desktop environments as well as other distros in a VirtualBox. No more crashed on my main computer in VB. This last crash took out my Windows virtual drive. Luckily I didn’t have much on it of importance.

If you have any suggestions as to topic I could tackle, let me know in the comments. Thanks for reading. My posts are usually not this long.

Friday, May 8, 2020

How to Modify Your Keyboard in Linux Using Xmodmap

Like me, you may have used or are using Quickbooks. If you have, you may have also used the “Use keypad key as a Tab key” function of QB. I used it extensively, like all the time, when I regularly worked in the program as a bookkeeper. Some people prefer having the key set that way, others will simply stick to the Keypad Enter key functioning like the return/enter key when pressed.

When I started using Linux, I discovered GNUCash, which is close (close, but not identical) to QB. One of the ways it isn’t identical to QB is with the keypad enter key being able to act like the Tab key. So, naturally, I looked for a way to make it happen. And I did, as follows. Note: you can use this to reassign most any key on the keyboard to function as a different key; it is known as the “xmodmap” command.

I’ll use Linux Mint’s Cinnamon desktop environment as an example, but you can enter in these shortcuts according to the shortcut-keyboard’s entry process of your particular desktop environment. In Linux Mint, you’ll want to go to your menu → Preferences → Keyboard, then click on the shortcut tab. Once that is open, select “Custom Shortcuts” on the left panel, then click on the button at the bottom of that window where it says “Add custom shortcut.” That will bring up a window. In the first field, it wants the name this will go by. I’ve used the description of the shortcut’s purpose for that field. For instance, in this case, I’ve called this function: KP_Enter → Tab. In the next field goes the actual command. Enter:

xmodmap -e "keycode 104 = Tab"

A keycode is a number given to each key on one’s keyboard. Code 104 is the one listed for the Keypad’s Enter key by my keyboard. A keysym, on the other hand, is a name given to main keys used that are control and function keys. Common ones are Tab, Return, Control_L and Control_R, Alt_L and Alt_R. Note, these names are case sensitive. If you enter “return” or “RETURN,” it will not work, it must be “Return.”

To discover what the keycode and keysym of any key is, enter in a terminal window the following:

xev | grep keycode

Then press a key. It should show the line with the keycode, as well as the keysym name (last entry within the parenthesis) for your keyboard. When you’re done, click the X in the box with your mouse to return to the command line.

Now, you could use keysym alone to do this:

xmodmap -e “keysym KP_Enter = Tab”

Problem is, when you go back, you have to use the keycode 104 as any attempt to point to the Keysym Tab will point one to the wrong key to change. So, to change the key back to operating as an enter or a Return key (Use xev as above to know what the keysym for your main enter key is), you would enter the following:

xmodmap -e “keycode 104 = Return”

Once those two fields are filled in, click the “Add” button. Then you will want to double-click in the first unassigned keyboard binding for the new custom keyboard shortcut you just created, and press the key combinations you wish to assign to that function. For instance, in my example, I use Ctrl-Shift-{ to turn on the Tab functionality of the keypad’s enter key, and Ctrl-Shift-} to return it back to working as an enter key.

Now, it is important to know that this changes the key for all operations and programs. Not just GNUCash. That’s why you’ll want to have a key to change it back, if you tend to use it in some applications as an enter key. Like the calculator, for example. You may be used to hitting that key in doing 10-key entry, expecting it to perform as an enter key to get a total. Thus, the key to change it back on the fly. I, however, tend to leave it on the Tab functionality and use the main Enter key to add the total in calculator or other programs. It’s what you are used to.

Another tip, you can start any preferred changes by entering the appropriate command in your startup file (Menu → Preferences → Startup Applications).

That’s it. You can change most any key to do the job of a different key using the “xmodmap” command.

Happy Linuxing!