Wednesday, March 14, 2018

Using Apt-offline to routinely install apps on live sessions

To conveniently add apps to live sessions of Debian-based versions of Linux, such as to add an app every time you boot up, you can use a very simple shell script (a program consisting of Linux instructions in a text-file with a ".sh" extension), which is fed into "bash," the Linux command-interpreter), combined with the file extracted from an Apt-offline tar.xz or .zip source-file, and a folder containing the packages to be installed. I came up with this trick as a result of wanting to install Mousepad on live sessions of KDE-Neon. These items would be stored in a folder in a fixed location on a flash drive, and to install the app, all that would be necessary would be to plug in the flash drive, give the shell script permission to run as a program, and then open it with bash (details below).

I decided to name the main folder for this purpose "ForAddingAppsToLiveSessions," and in this folder to put a sub-folder for each case (such as for one named Mousepad-Neon for installing Mousepad on KDE Neon), and put the following items in the sub-folder:

1) a copy of the folder extracted from the Apt-offline tar.xz or zip-file which is downloaded from the official Apt-offline site. I used version 1.7 for this example because I had a copy on hand, and the extracted folder in this case is named "apt-offline-master."
2) a folder named Mousepad to serve as a repository for the Mousepad-related packages to be installed 
3) the aforementioned installation-script, which reads as follows:


#!/bin/bash

cd /home/neon/ForAddingAppsToLiveSessions/Mousepad-Neon/apt-offline-master

python setup.py build

sudo python setup.py install

sudo apt-offline install /home/neon/ForAddingAppsToLiveSessions/Mousepad-Neon/Mousepad

sudo apt-get install mousepad

[end of script]

The first line starts bash, which the reads the subsequent lines. The first "cd" command tells bash to look in the apt-offline-master folder for the setup.py module used in the subsequent commands (to install Apt-offline). ("Python" tells bash to feed setup.py into the installation's Python interpreter, one of which is included with every Linux distribution I've checked. To check it yourself, enter "python." Apt-offline requires Python 2.x, and is not compatible with 3.x, at least as of this writing.) The "apt-offline install" command tells Apt-offline to "install" the packages contained in Mousepad, i.e. to copy them to the /var/cache/apt/archives folder. (If only one packgage had to be installed in order to install Mousepad, it could installed by opening it anywhere, such as on a flash drive, as long as it's connected to the target installation, but when multiple packages have to be installed in order to install a particular app, it is my experience that they must be placed in the aforementioned archives folder, which requires "superuser" privileges and is typically inconvenient at best, and very inconvenient in the case of KDE Neon, if this is done by using the file manager.)  The "apt-get install..." command performs the actual installation.

To run the shell script, give it permission to run as a program (right-click on the file, click on Properties in menu which appears, then on the Permissions tab in the window which appears, etc.). Then close the Properties window, right-click on the script and select "Run with," then in the window which appears, enter "bash" in the box at the top of the window, select "Run in terminal" below, and click on OK.  Then all you have to do is enter "y" when the package manager asks whether you want to proceed with the installation. (You could add a "-y" to the end of the "sudo apt-get install mousepad" instruction so that the question would be answered automatically in the affirmative, and avoid the need to run it in the terminal, but I prefer to monitor the progress of the process.) When the process is complete, the terminal will close.

Monday, March 5, 2018

Etcher could be the ultimate USB-installer for Linux

Rev 3/9/18 (see Revisions)

My motive for experimenting with manually creating flash drive installations (which turned out to be a failure in many cases, due to boot-process subtleties which are over my head) was that I had tried Etcher (after trying every other major USB-installer that runs on Linux) and concluded that there is no reliable USB-installer that runs on Linux.

However, it appears that the problem was that I was using a live installation to run Etcher, and to run Brasero for purposes of generating ISO's (from bootable DVD's) to use as inputs for Etcher. Since switching to a full installation of Linux Mint for these tasks, Brasero has so far produced error-free ISO's from bootable DVD's, and Etcher has so far handled everything I've thrown at it, except Ubuntu 1510, perhaps due to a problem with the ISO (it was able to install Ubuntu 16.04 and 17.10). However, Startup Disk Creator (SDC) in Ubuntu 1710 was able to install 15.10, and it boots (it also works on Debian and Ubuntu-derivatives, although it won't recognize ISO's with certain types of problems). I don't know why Etcher failed in this case, but the important thing is that I was still able to perform the installation without using Rufus and Windows.


Notes

Revisions

3/9/18 - Added reference to my experience with attempting to install Ubuntu 15.10.

Friday, March 2, 2018

Manually creating Linux USB flash drive installations

Rev 3/4/18 (see Recent Revisions at end)


In the interest of becoming less dependent upon USB-installers to create the simple flash-drive installations which I prefer for running my "secure" PC (a Zbox without any internal storage, internet connection, or wireless capability, running a nonpersistent flash drive installation of Linux - data is stored on small, easily-concealable encrypted flash drives), I decided to try to create one manually, and found that it's easy to do in some cases, but that in general it requires a lot of knowledge about the subtleties of the boot process and about configuring bootloaders. In cases where it works, however, changing installations might be as easy as deleting the existing version of Linux from the flash drive and replacing it with another.

The basic procedure is to create a FAT32 partition on a MBR/FAT-formatted flash drive (I use the Disks and/or GParted utility for this), then install the Syslinux bootloader-chain (mbr.bin, ldlinux.sys, and ldlinux.c32 - commands to do this are included below, but there are many approaches to accomplishing the same result), extract an ISO and copy the extracted files to the flash drive (or copy the files from a bootable DVD), and create a text file named syslinux.cfg (contents listed below) to tell the bootloader what to do (if it's different than the default behavior), and place it on the flash drive along with everything else.

I did this, using a Debian DVD which I purchased from OSDisc.com as the source material. The DVD contains some "symbolic links," which are files whose icons include "shortcut"-arrows, which cannot be copied to a FAT partition. So, what you do in such cases is to right-click on them, identify the item to which they link/point, and copy that item to the flash drive. In one case, the symbolic link pointed to the directory in which it was located, i.e. the "." directory. (".." is the parent directory.) So, I just disregarded the link. Some other symbolic links pointed to a certain folder, so I copied that folder.

To do this with an ISO-file, the file has to be extracted first, by right-clicking on it, etc. The extraction-process creates a folder named after the ISO, extracts the ISO's contents, and places them in the folder. The contents (known as the "image"), not the folder, would be copied to the flash drive.

The configuration file is a text file named syslinux.cfg. To avoid having to learn how to write these configuration files, which requires considerable education, I decided to try one which I found on an installation which I made with Rufus. The contents of this configuration file are as follows:

DEFAULT loadconfig

LABEL loadconfig
  CONFIG /isolinux/isolinux.cfg
  APPEND /isolinux/

This essentially tells the bootloader to use the isolinux.cfg file in the isolinux folder (included on DVDs and in ISO's) as its configuration file, and to append certain elements in the isolinux directory to the kernel command line, to add options (which I presume are those contained in the boot-menu).


> The general Linux boot-process using the Syslinux bootloader

The boot-process begins with a few instructions which are built into the PC's firmware and executed whenever the PC is started, which loads mbr.bin from the flash drive's first sector (which isn't part of the file system), and then runs mbr.bin, which passes control to ldlinux.sys, which does some things and passes control to ldlinux.c32, which reads the configuration file and acts accordingly, typically by executing a menu-program to give the user various boot-options. These pass control to the OS-kernel, which creates an "initial ram disk" (initrd), which is a temporary file system to contain such things as drivers for hardware required for the boot-process, and starts the core the of OS, which does a lot of stuff to set up shop, and passes control to user-interface. The kernel has enough intelligence to find what it needs if you just put everything from the DVD or extracted ISO in the root directory of the flash drive.


> Detailed bootloader installation process

To install the Syslinux bootloader-chain onto a flash drive formatted as described above, enter the following commands. (Don't include the quotation-marks which I use to identify the beginning and end of each command. The commands can be copied to a "scratchpad" text-file, edited as necessary to include the specifics, then copied and pasted into the terminal with Ctrl-Shift-V.

A) "sudo syslinux -i /dev/sdX1" (X is typically b, c, or d, depending on the PC's drive-configuration at the time. The specific letter can be found by using the Disks or Gparted utility included with many types of Linux, although typically not in those with the KDE interface (there are exceptions). This installs ldlinux.sys and ldlinux.c32 in the flash drive's first partition (which in this case is the only one).

B) "cd" to the directory containing the mbr.bin file. This directory is typically /usr/lib/syslinux/mbr, and if so so the command would be "cd /usr/lib/syslinux/mbr" (without quotes).

C) Enter "sudo dd conv=notrunc bs=440 count=1 if=mbr.bin of=/dev/sdX" (without quotes). (This puts mbr.bin, which is the primary bootloader, into the master boot record of the flash drive, where the BIOS will find it when the PC is booted.)

D) Enter "sudo parted /dev/sdX set 1 boot on" (without quotes) (this sets the partition's boot-flag to make it bootable, which can also be done with GParted)

E) Simply copy the contents of a bootable Linux DVD or an extracted ISO-file (as mentioned previously) to the flash drive partition/directory where ldlinux.sys and ldlinux.c32 are located.

F) Likewise, copy the aforementioned syslinux.cfg file to the flash-drive partition/directory where ldlinux.sys etc. are located.

That's what I did, basically, and it worked, but it doesn't work in all cases. But if you find that it works for certain types of Linux, you might be able to change the installation on a flash drive by simply deleting one version of Linux and replacing it with another.


Notes

Recent Revisions

Rev 3/3/18 - Pretty much rewrote the entire thing to improve its clarity.

Rev 3/4/18 - Revised the first paragraph to reflect additional experience with the system described in this article.