Linux – Hardware


Device Name

In Linux, all the devices are treated as files that are stored in /dev directory.
For example,

IDE disks are saved as /dev/hd[a-d]

SCSI/SATA/USB disks are saved as /dev/sd[a-p]

USB devices are saved as /dev/sd[a-p] (same as SATA disks)

Partition Table

Partition Table lies on the first sector of a disk. The size of the Partition Table is 64 bytes and it can only contain 4 partition records that are either primary partition or extended partition.

For example, if a disk is named /dev/sdb and is divided into 4 partitions, P1-P4. They are named as,

P1: /dev/sdb1

P2: /dev/sdb2

P3: /dev/sdb3

P4: /dev/sdb4

In fact, extended partition can be divided into more partitions called logical partition. Thanks to this technology, we can create more than 4 partitions on a disk.

Selection_012

Master Boot Record

Master Boot Record (MBR) is located on the first sector of a disk. It records the boot information of the disk. The boot loader is stored in MBR. MBR is 446 bytes.

Boot Procedure

BIOS->MBR->Boot Loader (stored in MBR)->Kernel

Basic Commands

command format — command [-options] parameter1 parameter2

Notation:

1. In Linux, all commands and filenames are capital sensitive. ‘cd’ and ‘CD’ represent completely different things.

2. Slash ‘\’ at the end of a line represents current command is not finished and would be continued in the next line.

Selection_014

Mount/umount – mount/unmount a partition to a specified directory

Mount a partition means to utilize a directory as the entry to the partition, and put all the data in the partition under the directory. Linux uses directory tree structure to organize files.

For example,

If I insert a CD in my computer,

in Windows, it would appear as a new driver in “my computer”, say E:\

in Linux, it would appear as a new directory under the root directory “/media/cdrom/”. It can also be mounted to any other directories, say /mnt/cdrom

Selection_006

Notation:

1. umount the first partition of first disk (/dev/sda1) which is usually named C:\ in Windows.

2. create a directory /mnt/c

3. mount /dev/sda1 to /mnt/c direcotry

4. list directories and files under the c

date – show date and time

Selection_009

cal – show calendar

Selection_008

bc – a simple calculator

Selection_010

man [command/filename] — show the manual page of some commands or files

Selection_016

‘/[word]’ search the [word] in man page.

‘n’ and ‘N’ next match / previous match.

man -f [name] find a command whose name contains the key word. It is the same as ‘whatis’

man -k [description] find a command whose description contains the key word. It is the same as ‘apropos’

The meaning of the code at the top-left of each man page: (LS(1)) in this example

1 — commands or executable files that can be run in shell by users.

2 — functions or tools that is callable by kernel.

3 — some common functions and libraries, mostly belongs to C lib.

4 — descriptions of device files under /dev

5 — configuration file or the format of some files

6 — games

7 — protocols, such as Linux file system, network protocol, ASCII code, etc.

8 — administrative commands accessible to system administrator.

9 — kernel related file

info — similar to man

In face, both info and man opens a file describing the specified command or file. The file is located at /usr/share/man or /usr/share/info.

Other manual documents for installed packages are stored in /usr/share/doc

Function of some system directories

~ home directory of current user. For root user, ~ means /boot. For other user, ~ means /home/[username]

Selection_015

/boot/ – stores boot related files.

Tip: Some out-of-date BIOSs may not recognize large disks. So it’s important to divide a small partition (100MB) at the beginning of your disk to store the files under /boot for the sake of a successful booting.

/mnt/

/usr/

/etc/passwd – Users’ information

/etc/shadow – User’s password

/etc/group – Group names

Shortcuts

[Tab] Make up unfinished part of command.

[Ctrl] + D Means End of File (EOF) or typing ‘exit’ in the terminal. Exit the current process.

[Ctrl] + C Send a sigint signal to current running process. End and exit the current process.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of