Skip to content

Instantly share code, notes, and snippets.

@cmccormack
Last active August 31, 2018 20:10
Show Gist options
  • Save cmccormack/c8d2b2c551b000a8c2c5615dc4c89687 to your computer and use it in GitHub Desktop.
Save cmccormack/c8d2b2c551b000a8c2c5615dc4c89687 to your computer and use it in GitHub Desktop.
Notes on Linux Systems

Linux Boot Process

Bootloaders - Starts the OS:

  • LILO - Linux Loader -
  • GRUB - Grand Unified Bootloader
    • Replaced LILO

initrd - initial RAMDisk

  • Temporary filesystem loaded into memory with helpers that can perform hardware detection and loads modules to get the filesystem mounted

boot contains files needed to load the OS

Linux Kernal

  • vmlinux
  • vmlinuz - compressed version

Booting

dmesg or /var/log/dmesg

  • dumps the contents of the kernel ring buffer

runlevels:

  • 0. Power Off
  • 1. Single User Mode
  • 2. Multiuser, without NFS
  • 3. Full multiuser mode
  • 4. Unused
  • 5. X11
  • 6. Reboot System

systemctl (systemd):

Control the system:

  • shutdown, reboot, poweroff

System Logging

Facilities:

Severities:

  • emergency
  • alert
  • critical
  • error
  • warning
  • notice
  • info

Syslog servers:

  • syslogd
  • rsyslog
  • syslog-ng

logger to generate own log messages
logrotate to prune messages

Disk Management - Partitions

Partitions - dividing a disk into parts
Partition tables:

  • MBR - Master Boot Record - can only address up to 2TB of storage
  • GPT - GUID Partition Table (Global Unique Identifier)

Mount point

  • Directory used to access the mounted device

Create and modify partitions

  • fdisk, gdisk, parted

Disk Management - File Systems

mkfs - Used to create filesystem

  • mkfs -t TYPE DEVICE
    • mkfs -t ext4 /dev/sdb3

mount - Used to mount a filesystem

  • mount DEVICE MOUNT_POINT
    • mount /dev/sdb3 /opt

df - disk free - displays used and available space

umount - Used to unmount a filesystem - can umount the mount point or the device

  • umount /opt
  • umount /dev/sdb3

Disk Management - File System Table

/etc/fstab - contains the file system table

View lables and UUIDs (Universally Unique Identifiers:

  • lsblk -f
  • blkid - displays only UUID

creating lables

  • e2label

Managing Users and Groups

Account information is stored in

  • /etc/passwd and /etc/shadow

Accounts have the following attributes:

  • username
  • UID
  • GID (default group)
  • Comment
  • home directory
  • shell

These attributes are stored in /etc/passwd.
Password hashes are now stored in /etc/shadow which is only accessible by the super user account.

Managing accounts:

  • Create accounts - useradd
  • Delete accounts - userdel
  • Modify accounts - usermod

Group information is stored in /etc/group
Managing accounts:

  • Create groups - groupadd
  • Delete groups - groupdel
  • Modify groups - groupmod

To view group memberships use groups

Use su to switch users
whoami displays your account name
sudo allows you to run programs as others (often to run as super user) Use visudo to edit the sudoers file

Performance Analysis

uptime

This is a quick way to view the load averages, which indicate the number of tasks (processes) wanting to run.

uptime
 12:15:49 up 16 days, 20:49,  1 user,  load average: 0.11, 0.07, 0.01

dmesg | tail

Print or control the last 10 system messages in the kernel ring buffer

[   18.604392] Adding 102396k swap on /var/swap.  Priority:-1 extents:5 across:200700k SSFS
[   75.996440] random: crng init done
[84793.175753] TCP: request_sock_TCP: Possible SYN flooding on port 40444. Sending cookies.  Check SNMP counters.

vmstat 1

Prints a summary of key server statistics on each line.

procs ---------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
34  0    0 200889792  73708 591828    0    0     0     5    6   10 96  1  3  0  0
32  0    0 200889920  73708 591860    0    0     0   592 13284 4282 98  1  1  0  0
^C

mpstat -P ALL 1

Prints CPU time breakdowns per CPU, which can be used to check for an imbalance.

07:38:49 PM  CPU   %usr  %nice   %sys %iowait   %irq  %soft  %steal  %guest  %gnice  %idle
07:38:50 PM  all  98.47   0.00   0.75    0.00   0.00   0.00    0.00    0.00    0.00   0.78
07:38:50 PM    0  96.04   0.00   2.97    0.00   0.00   0.00    0.00    0.00    0.00   0.99

pidstat 1

Prints a rolling summary of processes

07:41:02 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command
07:41:03 PM     0         9    0.00    0.94    0.00    0.94     1  rcuos/0

iostat -xz 1

A tool for understanding block devices (disks), both the workload applied and the resulting performance.

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          73.96    0.00    3.73    0.03    0.06   22.21

Device:   rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
xvda        0.00     0.23    0.21    0.18     4.52     2.08    34.37     0.00    9.98   13.80    5.42   2.44   0.09
xvdb        0.01     0.00    1.02    8.94   127.97   598.53   145.79     0.00    0.43    1.78    0.28   0.25   0.25

free -m

Display amount of free and used memory in the system

             total       used       free     shared    buffers     cached
Mem:           923        363        560          6         53        168
-/+ buffers/cache:        141        781
Swap:           99          0         99

sar -n DEV 1

Collect, report, or save system activity information.

Linux 4.9.35-v7+ (Mack-Pi3)     08/31/2018      _armv7l_        (4 CPU)

12:22:39 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
12:22:40 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:22:40 PM     wlan0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:22:40 PM      eth0     14.00     11.00      2.61      2.98      0.00      0.00      0.00      0.02

sar -n TCP,ETCP 1

Summarized view of some key TCP metrics.

Linux 4.9.35-v7+ (Mack-Pi3)     08/31/2018      _armv7l_        (4 CPU)

12:23:05 PM  active/s passive/s    iseg/s    oseg/s
12:23:06 PM      0.00      0.00      1.00      1.00

12:23:05 PM  atmptf/s  estres/s retrans/s isegerr/s   orsts/s
12:23:06 PM      0.00      0.00      0.00      0.00      0.00

top

Display information about Linux processes

top - 12:24:35 up 16 days, 20:58,  1 user,  load average: 0.04, 0.05, 0.00
Tasks: 127 total,   1 running, 126 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.9 us,  0.2 sy,  0.0 ni, 98.7 id,  0.1 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem:    945512 total,   371620 used,   573892 free,    54692 buffers
KiB Swap:   102396 total,        0 used,   102396 free.   172344 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
23285 chris     20   0    5264   2520   2092 R   5.8  0.3   0:00.04 top
    1 root      20   0   22860   3936   2736 S   0.0  0.4   0:32.65 systemd
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.36 kthreadd
    3 root      20   0       0      0      0 S   0.0  0.0   6:36.28 ksoftirqd/0
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment