Monthly Archives: April 2017

Computer Memory and Linux®

You have memory where you sit and remember, well, computers have a similar thing.  And it’s also called memory.  Sounds kind of silly to also call it memory, but it actually kind of works.

Computers have two kinds of memory.  There’s hard drives, where it stores programs.  You can think of it like the memories you have.  You can sit there and remember watching Star Wars, right?  A computer can save all of Star Wars to its hard drive so you (or it, if it wants) can watch it again and again.

The other kind of memory is the thinking kind.  If I sit here and think about what Luke Skywalker and Rey have to say each other, that’s not the remembering kind of memory, that’s the thinking kind.  When your computer is running a program, it’s thinking.  When you look at a directory, it’s remembering.

So, how much thinking memory does my computer have?  Of course, there’s a command for that!  It’s called free.

Alpha:~ computerlamp$ free -g
             total       used       free     shared    buffers     cached
Mem:            31         29          1          0          0         12
-/+ buffers/cache:         17         13
Swap:            2          2          0

So when I used the -g flag, I wanted to know the results in gigabytes.  If I don’t use that flag, I get the results in bytes.  That doesn’t really mean much to me, so I’ll go with gigabytes.

The man page for free also tells me to ignore the shared column, that’s obsolete.

But back to the results.  The first column tells me I have 31 Gigabytes of memory on this system and 29 are used but 1 is free.  That’s weird, right?  Its because the system actually counts them in bytes and then divides things out (and rounds it off) for the results.  It wants to give you nice pretty numbers to look at.

The bottom row, that’s called swap and we’ll talk about it in the next post.

The Kernel Version

Over the years, Iron Man has had a lot of suits.  The suit he had when he started out looks nothing like the suit he wore in the Civil War movie.  Linux® kernels are something like that, the first kernels don’t look anything like the kernels of today.  There are different kernel versions that depend on what the person who put it together wanted and what hardware you’re running.

In other words, the kernel version of your Linux® system probably doesn’t look anything like the kernel version of the system I’m running.  But you can’t tell just by looking at the system what kernel version you’re running, so it’s not like Iron Man’s suit.  It would be neat if it was, imagine if your system put on a new suit every time you put a new kernel on it.  I think it would be awesome for it to change color at least every time I put on a new kernel, but it doesn’t work like that.

Luckily, there’s a command to find out what kernel version you’re running and it’s called uname.  The man page for it

uname man page

uname man page

Tells you exactly what it’s designed for,  it’s to print system information.

So, what information do I want?  I want the kernel version!

That’s:

Alpha:~ computerlamp$ uname -v
#1 SMP Tue Aug 12 09:58:26 UTC 2014

What else can I find out?

Well, I can find out what machine name I’m running, that’s uname -m

I can find out the name of my computer, that’s uname -b.  I can also find out the name of my computer using a different command.  That one is

Alpha:~ computerlamp$ hostname
Alpha
Alpha:~ computerlamp$ uname -b 
Alpha

Either way I run the command, I get the same result out, which means as usual there’s more than one way to do it!

I can also find out my processor, or my hardware platform, or the operating system.

But wait, you say, of course I know my operating system, I’m using Linux®.  Well, it’s always good to double check that using our friendly comman.

Alpha:~ computerlamp$ uname -o 
GNU/Linux

If you have multiple systems, it’s always useful to find out what kernel version you’re running on each one.  It’s a good idea to keep it consistent, but that’s up to the administrator.

Kernel Modules or Putting it all Together

The Linux® kernel is not one huge thing that can run every hardware ever made and talk to every application ever created.  Can you imagine that? It would be huge and every time something new was added, you’d have to add it on.  Even if it wasn’t anything you needed.  Instead, the kernel is a modular kernel, which means you can add pieces on as needed.  These pieces are called modules.

It’s like Lego® blocks.  You add the blocks on that you need but you don’t have to use every single one.

Lego Blocks

Lego Blocks

Just like that picture.  If I’m making a wall, I don’t need to add this head:

Lego Head

Lego Head

It doesn’t make any sense to add that to a wall, does it?  But if the rule is ‘use every single Lego® block you own no matter what’, then even if you’re making a wall, you have to add that on .  Maybe to the top, it would be good at scaring intruders, or at least making them laugh.

With the Linux® kernel, you don’t have to do that.  You can use modules to build your kernel so it does exactly what you need and nothing more.

It’s hard to find computing hardware that Linux® won’t support.  It runs motherboards, networking connections, webcams, security systems, CDs, DVDs, mice, keyboards, card readers, I could go on and on.  In fact, it might be easier to list things it doesn’t support, but… I really can’t think of anything.  If someone really wants to use Linux® to run a piece of hardware, they’ll either write the kernel module or find someone to write it for them.

You may not use all of the modules in Linux® but when you download the source code for it from https://kernel.org (that’s where the most recent source code is) you do get almost all of the modules along with it.  You can pick and choose which parts you want when you build it, which is something we’ll talk about in the future.  That’s because it’s about how to compile a program from source code, a more advanced topic than this.

I said ‘almost all’ because sometimes hardware manufacturers offer the modules separately.  It depends on the manufacturer and the people that maintain the kernel source code.

Kernel of the Matter

We’ve talked about how your computer gets places on the Internet.  Now let’s talk about how your computer, well, works!  How does Linux® do its thing, aside from  typing commands at the command line?  It’s called the kernel and it’s the core (or kernel) of the operation of your system.

So it’s not like the kernel of your popcorn, it’s more like the thing in the middle.  Like Nick Fury.  He’s always in the middle of the Avengers keeping things going.  Or making things go.  He’s always up to something.

Nick Fury

Nick Fury

He showed up with that helicarrier at the end of The Age of Ultron, didn’t he? He made that happen and got the Avengers (and the towns people) from the flying in the sky town (something I never want to see) and on to safety.

That’s what the kernel does.  It’s in between the hardware and the software.  Like this picture:

What the Kernel Does

What the Kernel Does

Linus Torvalds made the first Linux® kernel in 1991 for his own system. These days it runs on all sorts of things, but back then, he just wanted something for his own computer.

So how does it control your hardware?  It uses things called device drivers.  It lets you type on your keyboard and have it show up on a screen, or print to a printer, or read a CD, or read a USB, or… you get the idea.  It’s really flexible.

The kernel is also  modular.  That means that it isn’t one huge thing that keeps things going, but it’s made up of lots of little systems that put it all together and make it go.

It’s kind of like a Death Star built from Legos.  It needs all the parts together to make it a Death Star, but you can leave pieces off and still mostly have a Death Star.  You can add pieces to it and it’ll be a Death Star with more abilities.  Like if someone added an ice cream maker to the Death Star.  Or a spa for the emperor.  It’s still the Death Star and still acts like it, it’s just more!

 

SuperUser aka Root

Before we go back into the world of Linux (having spent time in the world of networking), let’s talk about users again.  In particular, the SuperUser also known as Root.  Root is his every day name, SuperUser is his power!  And with great power comes great responsibility.

Groot not Root

Groot not Root

That’s Groot, not root, even though they rhyme.  Groot is a superhero, root is a superuser, and root doesn’t go around saying ‘I am Groot’ all the time.  They’re both super though.

SuperUsers’s great power is that he can do anything on a system and  I do mean, anything.  You change the permissions on your file so that you’re the only one that can see it?  Well, the superuser can see it too. He’s all powerful like Superman, but without that annoying green rock allergy.

His username is root and because he’s so powerful, he shouldn’t be logged in unless he’s absolutely needed.  The administrator of your system shouldn’t keep him logged in, but there’s a command to see who is logged in.  It’s called who.

Alpha:~ computerlamp$ who
computerlamp  console  Mar 17 08:01

There I am, logged into the system and I don’t have root logged into my system right now and that’s a good thing.

Since root is a user, he (or she!) has a password.  If you know the password, you can become root.  Like IronMan putting on his suit or BatMan suiting up, you can put on the root armor and be… SuperUser!  And like I always say, there’s a command for that.  This one is called su.

Alpha:~ computerlamp$ su
Password:
Alpha:~ :~ root#

You have to know the password in order for it to work.  If you don’t know the password, don’t try to do this.  It means you don’t have the permission to do it and if you try, you’re attempting to go around the system’s security and that’s a bad thing.  It’s like trying to lift Thor’s hammer and you’re not worthy.

If your root password gets out, then that’s a security problem.  When we made the shield group to hide the helicarrier plans, we thought we were safe from prying eyes.  But if Hydra got the root password, it wouldn’t matter.  That’s why it’s so important to keep that root password safe. The administrator of the system shouldn’t share it with anyone who doesn’t absolutely need it.