General - Commands

General - Commands

Raspberry Pi is a small general-purpose, single board computer, which is able to do physical computing too (using sensors, motors, lights and microcontrollers). The name comes from  a "tradition" of using fruit names for computing systems (like Apple, Blackberry, Tangerine, Apricot) and the second half is for the Python programming language. (Originally Python was recommended for learning and development.)

It was designed to run an operating system called GNU/Linux (in short Linux).

Linux was originally founded to produce a kernel that would be free for anyone to use. The kernel is the heart of an operating system, and handles the communication between the user and the hardware. Officially only the kernel itself is called Linux, but in general the kernel and all the additional tools/softwares together is referred to as Linux. The original version of Linux was combined with a collection of tools created by a group called GNU, and the resulting system was known as GNU/Linux. Later, other projects created  different flavours of Linux, known as distributions. Some major Linux distributions are Debian, Suse, Ubuntu...

Linux is open source (which means the entire operating system can be modified by anyone). One distribution of Linux, called Raspbian which is based on the original Debian distribution and  it has been changed specifically that it can be run on the Raspberry Pi. (Thus the name Raspbian) This process of changing is called as porting and during the years several other Linux distributions have been ported to the Raspberry Pi. (Regarding Debian: In 1993 Ian Murdock founded the Debian project. At that time his girlfriend name was Deb, so he called this new Operating System after themself: Deb+Ian.)


==========================================

Kernel

Kernel is the heart of the operating system that interfaces with all the hardware devices in the computer. These are CPU, Memory, Storage devices and any other hardware devices attahed to the Pi.  All applications and processes are going through the kernel and the kernel makes possible that these processes get information from each other (using inter-process communication (IPC)).

The Linux kernel is a single file located in the /boot directory called kernel.img. When the Pi is switched on and begins to load the operating system, it looks for this file, and if the file is missing, the Pi won’t work.  There’s also a second kernel file, which sits unused and this is called the emergency kernel. (It is also in /boot directory, and the file called kernel_emergency.img) 

The emergency kernel is identical to the standard kernel, and it can be used when the normal kernel does not work. (When changes are made to the standard kernel, the emergency kernel is left untouched, so in case Pi can load the emergency kernel instead the default kernel.)


2 ways to boot into the emergency kernel:
1. rename the existing kernel.img file to kernel.img.bak, and then rename the kernel_emergency.img file to kernel.img. 
(After renaming files to the original names, Pi will load the default kernel.)

2. edit the cmdline.xt file (in the /boot directory) by adding at the end of the existing command line: kernel=kernel_emergency.img
(After removing removing the entry Pi will load the default kernel.)


Kernel ring buffer
The kernel ring buffer is a special part of memory used by the kernel to store important data. (A ring buffer is a special kind of thing in memory to store information, whicht is always a constant size, removing the oldest messages when new messages come in.) During boot all information logged into this buffer, and when booting has been completed, syslog damon takes over logging.

At this point "dmesg" can be used to view the content of the kernel ring buffer, which contains info from boot, and also all messages by the kernel since the Pi was switched on.
To list all usb related messages, you can use: dmesg | grep usb

==========================================

Commands

Default login:
user: pi
password: raspberry

sudo -i                                  <--change to root

sudo raspi-config                        <--configuration options

sudo shutdown -h now                     <--powers off the system after the shutdown is complete
sudo shutdown -r now                     <--reboot the system ("sudo reboot" does the same)

cat /etc/*-release                       <---info about linux (linux distribution, version...)
cat /proc/cpuinfo                        <--shows details about the cpu (and model, version) (lscpu will also shows these)
cat /proc/meminfo                        <--shows details about the memory
cat /proc/partitions                     <--shows details about partitions
cat /proc/version                        <--version??

top                                      <--real time monitoring tool of processes (P: list by CPU, M: list by Memory)
free -o -h                               <--memomy usage (lists free memory)
df -h                                    <--disk usage
netstat -tupan                           <--shows network connections and listening ports


dmesg                                    <--system messages (from os)
/var/log/messages                        <--system logs


tar -xzf myfile.tar.gz                   <--extracts tar files (which are zipped with gzip) in one command
find /home -name "*adapter"              <--searches in /home for files names which are ending as "adapter"
grep -r "adapter" /home                  <--searches in /home in the content of each file for the word "adapter"

==================================

Flashing (Imaging)

Flashing or imaging is to write a Linux image file to an SD card. It is not a usual copy+paste operation as the image has to be written exactly it is designed in order the OS can boot and function correctly from an SD card. After downloading the Raspbian zip file and it has been extracted, you will have an img file, which need to be written in a special way to the SD card.

Flashing from Linux:
0. plug in SD card
1. sudo fdisk -l                      <--find SD card (by its size, e.g. /dev/sdX  or /dev/mmcblkX)
2. sudo dd if=<imagefilename.img> of=/dev/sdX bs=1M           <--write the image file to the SD card

Flashing from Windows
0. Plug in SD card
1. Download and start Win32DiskImager
2.  choose img file, select correct drive letter + ?????? + write


==================================

No comments:

Post a Comment