From the course: Advanced Linux: The Linux Kernel

Discover and control hardware - CentOS Tutorial

From the course: Advanced Linux: The Linux Kernel

Start my 1-month free trial

Discover and control hardware

- [Instructor] Let's survey the Linux kernel and discover and talk about controlling some hardware from the command line. An application makes calls into libraries like the standard C library. So it's calling functions, right. Some of those functions we call system calls because they invoke corresponding functions in the Linux kernel. Some of those system calls interact with hardware. So an application interacts with hardware like reads and writes from the disk by calling functions that end up being in the standard C library, that invoke functions in the kernel that actually interact with the disk. Now from the command line we can find out a good bit about hardware on our system. We can list hardware and PCI devices and USB devices and block devices, information about the CPU, and so forth. Now, not all Linux distros might have these commands installed, right. Your version running on your computer or Linux might not have these commands. You might have to install them. You might have to do a little bit of checking to see what package provides them. But these are generally available and some of these I use pretty often. I like lspci, that's kind of cool. And if I'm changing machines like lscpu. Now if you want to find out about your disk, even your SSD, you can find out stuff and you can even do some benchmarking with the hdparm command. And you can change stuff about hardware even from the command line sometimes. So there's special files in the filesystem that actually when you write into them tell the kernel to interact with the device. So you can say, configure a device. And we're going to look at that quite a bit later, but stuff in the proc directory, proc files and device files and stuff in the sys files, sysperm/sys. Lots of interesting stuff there. And something quite a bit different, there's some devices, kind of legacy devices like keyboards that were on a different kind of bus, the IO bus, and you could read and write bytes to those things. Like you could disable the keyboard by writing a value in a particular place with the outb command. You could read in stuff with the inb command like say on some sort of serial device. And it's even possible to configure and get information and change stuff with the setpci command from the command line. So there's quite a bit you could do in Linux on the command line with respect to hardware. You can even do kind of a device driver from the command line with Linux. So let's look at some of these commands. Let's try lspci. And we don't know how much output it's going to produce so let's pipe it into more just in case it's a lot. Whoa, it is a lot. We got lots of devices. So this is as expected. Cryptic in some places. Way on the left side we see some numbers, bus addresses, stuff like that, but there's, right, a lot of text here and we can make some sense of that. We see we've got VGA compatible controller and we got a USB controller. And we've got lots of PCI bridge stuff but let's scroll through. We've got a communication controller, we got a SATA controller, a disky thing. We got a ISA bridge. But down toward the bottom there we see we have an audio device. That might be helpful information. We have an ethernet controller. We have a SDMMC card reader, and we have a wireless network controller. Now this sort of information is handy sometimes because maybe that thing's not working. Maybe your wireless thing just, it's just not showing up. So now you got a little information. You got this Intel Corporation Wireless 8260 Rev 3A and you could Google that and maybe get some information. Maybe find out you need a new driver. So devices identify themself to Linux, PCI devices identify themselves to Linux in a standard way so that even if you don't have a driver, Linux can get this information from the device. And then you can use that information hopefully to help yourselves out of a spot sometimes. Let's look at what USB devices you have on your system. I'm going to look on mine with lsusb. Oh, I don't have a lot. I got this hub and then I've got a cryptic something from Intel corporation. Notice the identifier there in that Intel Corporation starts with 8087. An old Intel thing. They got the standard numbers that are kind of cool for things. For PCI devices they got 8086 for a number. But anyway, that's a bit of trivia, right. So here we see I've got a USB mouse and a USB keyboard and they say Chicony Electronics. If I look at my mouse and my keyboard they say some major brand name on them. They don't say that. So this is kind of interesting. To Linux looking at the device it needs to know really the underlying chip or whatever is in there so it knows what driver needs to be loaded. So these codes like the 04f2:0909, that ID can be used by the Linux kernel to look up what driver. And so different companies that build, say, a mouse with the same chip from Chicony, they're going to need the same driver. So that's the critical thing that you want to know. Now what about CPUs? Now lscpu is a pretty cool one. Let's pipe that into more as well, see if we got a lot of output. Yup, we're going to have a fair amount there. We see on this computer I'm using that the architecture is this x86_64. Pretty common, right. And vendor ID, it said its' a GenuineIntel. And then the model name, it's an i7 and we got some speeds and then we got this BogoMIPS which always amuses me. That comes from bogus MIPS, telling you this isn't real MIPS, this is kind of bogus, but it's related to MIPS. This is a Linux thing. When your kernel boots, it actually runs a little loop in it, measures the performance and it's got this calibrated value it calls BogoMIPS and it uses that so it knows how long it takes to do certain things for example. So you can use that number to compare different computers, bigger is better, but it's not really MIPS. And then there's lots of other information about your CPUs. Does this CPU support virtualization and what kind of caches it has, what the sizes of them are, and then it's even here got some vulnerability information stuff. Might be helpful.

Contents