You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
7.3 KiB

import { addBanner, addArticle, addTitle, addHeader, addParagraph, addSubHeader } from '/scripts/article.js';
import { addInset, addInsetList, addInsetCodeListing, addInsetBulletList } from '/scripts/inset.js';
import { addImageWithCaption, addButtonGroup } from '/scripts/visuals.js';
import { addSidebar} from '/scripts/sidebar.js';
import { addSyntax } from '/scripts/code.js';
import { menu } from '/scripts/web_dev_buttons.js';
const heading = document.querySelector(".heading");
const global = document.querySelector(".global_menu");
const local = document.querySelector(".local_menu");
const sidebar = document.querySelector(".sidebar");
const main = document.querySelector(".main_content");
heading.append(addTitle("Advanced Linux: The Linux Kernel"));
heading.append(addParagraph("Kevin Dankwardt - LinkedIn Learning - April 2020"));
heading.append(addParagraph("Chapter 1 - SURVEYING THE LINUX KERNEL"));
main.append(addHeader("Discover and Control Hardware"));
main.append(addParagraph("Applications can interact with the hardware, but they do that by making calls to the standard C library. The library makes calls to the kernel and the the kernel interacts directly with the hardware."));
main.append(addParagraph("For example, an application might invoke a C function to write something to the disk. The standard C library makes a call to the kernel to write the users data to the selected disk and, if all goes well, the kernel handles the necessary disk write operation."));
main.append(addParagraph("So the app can read data from or write data to a disk, but it can't do it directly. The kernel handles the direct interaction with any hardware including a disk drive."));
main.append(addParagraph("There are a number of commands we can use from the command line to get some more information on our hardware."));
main.append(addInsetList(["lshw - lists hardware devices", "lspci - lists pci devices", "lsusb - lists usb devices", "lsblk - lists block devices", "lscpu - provides info on the cpu", "lsdev - also lists hardware devices but dispalys its info in a different format"]));
main.append(addParagraph("Note that not all distrubutions of Linux will have all of these commands by default, but ias a general rule, you should be able to install any missing commands. For example, I am using a Virtual Box VM for this course which is running Ubuntu and this had all of the commands listed above with the exception of lsdev, which I was able to install with the command"));
main.append(addInsetList([" sudo apt install procinfo"]));
main.append(addParagraph("This might not be exactly what you would expect, but in this case, if you try to run lsdev, the shell will respond with an error message that includes this command. If you get an error message that doesn't give you the installation command, you will most likely find that you can install it with a command such as"));
main.append(addInsetList([" sudo apt install missing_command"]));
main.append(addParagraph("where missing_command is the name of the command that is not installed."));
main.append(addParagraph("Another usefful command is hdparm - this is a command that I didn't have installed on my Raspberry Pi so I installed it with the command"));
main.append(addInsetList([" sudo apt install hdparm"]));
main.append(addParagraph("The command was already installed on my Ubuntu Virtual Box. The command returns a good bit of information on the hard drive parameters and it also allows you to set some of those parameters. This is a useful in that it demonstrates the fact that we can use commands at the command line to configure hardware as well as get information on it. We will look into that in more detail later."));
main.append(addParagraph("Some older devices such as legacy keyboards and so on used the I/O bus and it was possible to read and write to these devices via the command line. For example, you could disable the keyboard by writing a value to a specific locationusing the outb command and you could also read in data with the inb command."));
main.append(addParagraph("Let's now look at one of these commands, lspci, in a little bit more detail. The amount of information this generates will depend on the extend to which your machine uses PCI devices. On a desktop PC, this can be quite a lot so it us probably a good idea to pipe it to a command that will allow you to page through the data such as more. On my Raspberry Pi, it generated two lines of data as shown in figure 1."));
main.append(addImageWithCaption("images/figure1.png", "Figure 1 - the output from running lspci on my Raspberry Pi."));
main.append(addParagraph("The information you can get form this can be very useful for troubleshooting, particularly because you can use it to get information on a device even when that device doesn't have a driver due to the fact that devices identify themselves to Linux, usually in a standardised way as is the case for PCI devices."));
main.append(addParagraph("We can also use a similar command, lsusb, to get some information on USB devices and the output of this command is shown in figure 2."));
main.append(addImageWithCaption("images/figure2.png", "Figure 2 - the output from running lsusb on my Raspberry Pi."));
main.append(addParagraph("Note that this is not the same Raspberry Pi as shown in figure 1. We can see some device ids here and these are specific to the manugfacturer so, for instance, an Intel device would start with something like 8086 or 8087. In this case, we don't have any Intel devices, but we can see that there is a mouse, a keyboard, a usb stick (that's device 003) and a USB root hub. Note that the USB root hub is software that allows you to connect multiple USB Cdevices so it's really a virtual device and we have separate hubs for different version so we have, for example, hubs for USB 2.0 and USB 3.0 and the Raspberry Pi (which is a model 4B in this case) does have both USB 2.0 and USB 3.0 ports."));
main.append(addParagraph("The kernel can use the id to look up the device driver so this can be very useful information, particularly when a company is using licensed hardware to produce peripherals or the device is rebranded. For instance, my mouse and keyboard, in this care are both official Raspberry Pi products, but with lsusb I can see who made them and this is more useful when determining what drivers you need."));
main.append(addParagraph("The lscpu command can be very useful for getting info on the cpu. Again, it can produce a lot of output so you may need to pipe it to more, on the Pi, there isn't enough data to require that and you can this output in figure 3."));
main.append(addImageWithCaption("images/figure3.png", "Figure 3 - the output from running lscpu on my Raspberry Pi."));
main.append(addParagraph("Some of the particularly useful bits of info here include the architecture, vendor, number of cores, speed and so on. One interesting piece of data is the BogoMIPS which is a slightly shortened form of Bogus MIPS. As the machine boots up, the kernel runs a loop to measure performance so that it knows how long certain tasks will take and it calls this value BogoMIPS. So it's not really MIPS but it can be used to compare the performance of different machines. There is also some information relating to the vulnerabilities that affect (or don't affect) that CPU."));
main.append(addHeader("Understand System Call Mechanics"));
addSidebar("linux");