docs

a slatepencil documentail site

View on GitHub

Disk management

Examining disk space and disk partitions

df -h
# Filesystem      Size  Used Avail Use% Mounted on
# udev            969M  4.0K  969M   1% /dev
# tmpfs           196M  1.1M  195M   1% /run
# /dev/sda1        37G  4.5G   31G  13% /
# none            4.0K     0  4.0K   0% /sys/fs/cgroup
# none            5.0M     0  5.0M   0% /run/lock
# none            980M  152K  979M   1% /run/shm
# none            100M   36K  100M   1% /run/user
# /dev/sda3        28G   44M   26G   1% /apps

du -sh ~/*
249M   /home/user/bin
4.0K    /home/user/Desktop
42M     /home/user/docker
5.8G    /home/user/Documents
4.7G    /home/user/Downloads
2.1G    /home/user/dpkg
128M    /home/user/kubernetes
1.9G    /home/user/miniconda3
4.0K    /home/user/Music
4.0K    /home/user/Pictures
4.0K    /home/user/Public
462M    /home/user/snap
4.0K    /home/user/Templates
4.0K    /home/user/Videos

pydf
# Filesystem Size  Used Avail Use%                 Mounted on
# /dev/sda1   37G 4534M   30G 12.1 [##...........] /
# /dev/sda3   27G   44M   26G  0.2 [.............] /apps

sudo parted -l # partition information
# Model: ATA WDC WD800AAJS-60 (scsi)
# Disk /dev/sda: 80.0GB
# Sector size (logical/physical): 512B/512B
# Partition Table: msdos

# Number  Start   End     Size    Type     File system     Flags
# 1      1049kB  40.0GB  40.0GB  primary  ext4            boo#t
# 2      40.0GB  50.0GB  10.0GB  primary  linux-swap(v1)
# 3      50.0GB  80.0GB  30.0GB  primary  ext4

lsblk # list block devices
# NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
# sda      8:0    0  74.5G  0 disk
# ├─sda1   8:1    0  37.3G  0 part /
# ├─sda2   8:2    0   9.3G  0 part [SWAP]
# └─sda3   8:3    0    28G  0 part /apps

sudo fdisk -l
# Disk /dev/sda: 80.0 GB, 80026361856 bytes
# 255 heads, 63 sectors/track, 9729 cylinders, total 156301488 sectors
# Units = sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes
# Disk identifier: 0x000f114b

#    Device Boot      Start         End      Blocks   Id  System
# /dev/sda1   *        2048    78125055    39061504   83  Linux
# /dev/sda2        78125056    97656831     9765888   82  Linux swap / Solaris
# /dev/sda3        97656832   156301311    29322240   83  Linux

sudo sfdisk -l -uM
# Disk /dev/sda: 9729 cylinders, 255 heads, 63 sectors/track
# Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0

#    Device Boot Start   End    MiB    #blocks   Id  System
# /dev/sda1   *     1  38146  38146   39061504   83  Linux
# /dev/sda2     38147  47683   9537    9765888   82  Linux swap / Solaris
# /dev/sda3     47684  76318  28635   29322240   83  Linux
# /dev/sda4         0      -      0          0    0  Empty

sudo blkid
# /dev/nvme0n1p2: UUID="1c5c141d-5a27-4bb6-a12c-be1694aa70df" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a997e867-6f36-4e5c-a043-954dfc679e69"
# /dev/nvme0n1p1: UUID="00E3-E78D" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="bb16caac-20af-43e7-8652-349a7c69afc7"
# /dev/nvme1n1p1: UUID="44338d24-ab2c-4c40-9719-5b6db0f59643" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux data partition" PARTUUID="a5e92eac-e197-4ea8-8e6b-f3815595675a"

Mount/unmount disk

# create mounting point
cd /mnt && mkdir ssd
# synatx `mount /divice /mounting/point`
sudo mount /dev/nvme1n1 /mnt/ssd

# to unmount
sudo unmount /mnt/ssd

# to mount hard drive permantly
sudo vim /etc/fstab
# add a record as the following syntax
# UUID=<device UUID> <mount point> <file system type> <mount options> <dump> <pass>

# test mount
sudo mount -a

Monitoring disk performance

iostat -x 60 
# Linux 3.13.0-129-generic (stinkbug)     08/31/2017      _x86_64_        (2 CPU)

# avg-cpu:  %user   %nice %system %iowait  %steal   %idle
#            0.93    1.15    0.35    1.86    0.00   95.73

# Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
# sda               8.37     3.26   13.41    2.79   341.14   191.82    65.79     0.61   37.60   30.40   72.14   2.52   4.08

sudo smartctl -a /dev/sda1
# smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-129-generic] (local build)
# Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

# === START OF INFORMATION SECTION ===
# Model Family:     Western Digital Caviar Blue Serial ATA
# Device Model:     WDC WD800AAJS-60M0A0
# Serial Number:    WD-WMAV37134378
# LU WWN Device Id: 5 0014ee 0015c85ef
# Firmware Version: 02.03E02
# User Capacity:    80,026,361,856 bytes [80.0 GB]
# Sector Size:      512 bytes logical/physical
# Device is:        In smartctl database [for details use: -P show]
# ATA Version is:   ATA8-ACS (minor revision not indicated)
# SATA Version is:  SATA 2.5, 3.0 Gb/s
# Local Time is:    Thu Aug 31 15:30:19 2017 EDT
# SMART support is: Available - device has SMART capability.
# SMART support is: Enabled

# === START OF READ SMART DATA SECTION ===
# SMART overall-health self-assessment test result: PASSED

# General SMART Values:
# Offline data collection status:  (0x82) Offline data collection activity
#                                         was completed without error.
#                                         Auto Offline Data Collection: Enabled.
# Self-test execution status:      (   0) The previous self-test routine completed
#                                         without error or no self-test has ever
#                                         been run.
# Total time to complete Offline
# data collection:                ( 2700) seconds.
# Offline data collection
# capabilities:                    (0x5b) SMART execute Offline immediate.
#                                         Auto Offline data collection on/off support.
#                                         Suspend Offline collection upon new
#                                         command.
#                                         Offline surface scan supported.
#                                         Self-test supported.
#                                         No Conveyance Self-test supported.
#                                         Selective Self-test supported.
# SMART capabilities:            (0x0003) Saves SMART data before entering
#                                         power-saving mode.
#                                         Supports SMART auto save timer.
# Error logging capability:        (0x01) Error logging supported.
#                                         General Purpose Logging supported.
# Short self-test routine
# recommended polling time:        (   2) minutes.
# Extended self-test routine
# recommended polling time:        (  36) minutes.
# SCT capabilities:              (0x303f) SCT Status supported.
#                                         SCT Error Recovery Control supported.
#                                         SCT Feature Control supported.
#                                         SCT Data Table supported.

# SMART Attributes Data Structure revision number: 16
# Vendor Specific SMART Attributes with Thresholds:
# ID# ATTRIBUTE_NAME          FLAG  VALUE WORST THRESH TYPE     UPDATED WHEN_FAILED RAW_VALUE
#   1 Raw_Read_Error_Rate     0x002f 200  200   051    Pre-fail Always      -       0
#   3 Spin_Up_Time            0x0027 143  140   021    Pre-fail Always      -       3841
#   4 Start_Stop_Count        0x0032 100  100   000    Old_age  Always      -       178
#   5 Reallocated_Sector_Ct   0x0033 200  200   140    Pre-fail Always      -       0
#   7 Seek_Error_Rate         0x002f 100  253   051    Pre-fail Always      -       0
#   9 Power_On_Hours          0x0032 058  058   000    Old_age  Always      -       31203
#  10 Spin_Retry_Count        0x0033 100  100   051    Pre-fail Always      -       0
#  11 Calibration_Retry_Count 0x0032 100  100   000    Old_age  Always      -       0
#  12 Power_Cycle_Count       0x0032 100  100   000    Old_age  Always      -       175
# 184 End-to-End_Error        0x0033 100  100   097    Pre-fail Always      -       0
# 187 Reported_Uncorrect      0x0032 100  100   000    Old_age  Always      -       0
# 188 Command_Timeout         0x0032 100  100   000    Old_age  Always      -       0
# 190 Airflow_Temperature_Cel 0x0022 066  062   040    Old_age  Always      -       34
# 192 Power-Off_Retract_Count 0x0032 200  200   000    Old_age  Always      -       103
# 193 Load_Cycle_Count        0x0032 200  200   000    Old_age  Always      -       178
# 196 Reallocated_Event_Count 0x0032 200  200   000    Old_age  Always      -       0
# 197 Current_Pending_Sector  0x0032 200  200   000    Old_age  Always      -       0
# 198 Offline_Uncorrectable   0x0030 200  200   000    Old_age  Offline     -       0
# 199 UDMA_CRC_Error_Count    0x0032 200  200   000    Old_age  Always      -       0
# 200 Multi_Zone_Error_Rate   0x0008 200  200   000    Old_age  Offline     -       0

# SMART Error Log Version: 1
# No Errors Logged

# SMART Self-test log structure revision number 1
# Num  Test_Description  Status                 Remaining LifeTime(hours) LBA_of_first_error
# 1  Short offline     Completed without error      00%    30349        -
# 2  Extended offline  Aborted by host              80%        0        -

# SMART Selective self-test log data structure revision number 1
#  SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
#     1        0        0  Not_testing
#     2        0        0  Not_testing
#     3        0        0  Not_testing
#     4        0        0  Not_testing
#     5        0        0  Not_testing
# Selective self-test flags (0x0):
#   After scanning selected spans, do NOT read-scan remainder of disk.
# If Selective self-test is pending on power-up, resume after 0 minute delay.

find large files

# list the top 10 largest files in the specified directory.
du -ah /var/lib/docker/containers | sort -rh | head -n 10

# find files larger than 100 MB in the specified directory.
find /path/to/directory -type f -size +100M

aliyun online extend cloud disk

# https://help.aliyun.com/zh/ecs/user-guide/extend-the-partitions-and-file-systems-of-disks-on-a-linux-instance
sudo LC_ALL=en_US.UFT-8 growpart /dev/vda 3
CHANGED: partition=3 start=413696 old: size=83472351 end=83886047 new: size=167358431 end=167772127

df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
tmpfs          tmpfs  1.5G  154M  1.4G  10% /run
/dev/vda3      ext4    40G   37G  910M  98% /
tmpfs          tmpfs  7.5G     0  7.5G   0% /dev/shm
tmpfs          tmpfs  5.0M     0  5.0M   0% /run/lock
/dev/vda2      vfat   197M  6.1M  191M   4% /boot/efi
tmpfs          tmpfs  1.5G  4.0K  1.5G   1% /run/user/1000
tmpfs          tmpfs  1.5G  4.0K  1.5G   1% /run/user/0

sudo resize2fs /dev/vda3
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/vda3 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 5
The filesystem on /dev/vda3 is now 20919803 (4k) blocks long.

df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
tmpfs          tmpfs  1.5G  154M  1.4G  10% /run
/dev/vda3      ext4    79G   37G   39G  49% /
tmpfs          tmpfs  7.5G     0  7.5G   0% /dev/shm
tmpfs          tmpfs  5.0M     0  5.0M   0% /run/lock
/dev/vda2      vfat   197M  6.1M  191M   4% /boot/efi
tmpfs          tmpfs  1.5G  4.0K  1.5G   1% /run/user/1000
tmpfs          tmpfs  1.5G  4.0K  1.5G   1% /run/user/0

check RAM info

# displays the amount of memory used by the kernel
free -mh

               total        used        free      shared  buff/cache   available
Mem:            31Gi       2.4Gi       273Mi       7.8Gi        28Gi        20Gi
Swap:          2.0Gi       0.0Ki       2.0Gi

#  shows detailed information about the system's physical and virtual memory usage
cat /proc/meminfo

MemTotal:       32776684 kB
MemFree:         1307112 kB
MemAvailable:   21417480 kB
Buffers:          248464 kB
Cached:         28043720 kB
SwapCached:            0 kB
Active:         11535444 kB
Inactive:       18718400 kB
Active(anon):   10182460 kB
Inactive(anon):        0 kB
Active(file):    1352984 kB
Inactive(file): 18718400 kB
Unevictable:        4072 kB
Mlocked:              64 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Zswap:                 0 kB
Zswapped:              0 kB
Dirty:               276 kB
Writeback:             0 kB
AnonPages:       1965752 kB
Mapped:          9058936 kB
Shmem:           8220816 kB
KReclaimable:     508404 kB
Slab:             757296 kB
SReclaimable:     508404 kB
SUnreclaim:       248892 kB
KernelStack:       17376 kB
PageTables:        62872 kB
SecPageTables:     16064 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    18485488 kB
Committed_AS:   17066548 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       76048 kB
VmallocChunk:          0 kB
Percpu:             8928 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:     2048 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
Unaccepted:            0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      372764 kB
DirectMap2M:    12124160 kB
DirectMap1G:    20971520 kB

# displays the type, size, speed, and other details of the system's RAM
dmidecode -s memory

check GPU info

# displays detailed information about all video cards installed in the system
lspci -vnnk | grep VGA

01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Polaris 22 XT [Radeon RX Vega M GH] [1002:694c] (rev c0) (prog-if 00 [VGA controller])

# displays a summary of all hardware components, including graphics cards
lshw -C video
  *-display
       description: VGA compatible controller
       product: Polaris 22 XT [Radeon RX Vega M GH]
       vendor: Advanced Micro Devices, Inc. [AMD/ATI]
       physical id: 0
       bus info: pci@0000:01:00.0
       version: c0
       width: 64 bits
       clock: 33MHz
       capabilities: vga_controller bus_master cap_list rom
       configuration: driver=amdgpu latency=0
       resources: iomemory:200-1ff iomemory:210-20f irq:176 memory:2000000000-20ffffffff memory:2100000000-21001fffff ioport:e000(size=256) memory:db500000-db53ffff memory:c0000-dffff
  *-display
       description: Display controller
       product: HD Graphics 630
       vendor: Intel Corporation
       physical id: 2
       bus info: pci@0000:00:02.0
       version: 04
       width: 64 bits
       clock: 33MHz
       capabilities: bus_master cap_list
       configuration: driver=i915 latency=0
       resources: iomemory:2f0-2ef iomemory:2f0-2ef irq:174 memory:2ffe000000-2ffeffffff memory:2fa0000000-2fafffffff ioport:f000(size=64)

# displays kernel messages related to the graphics card
dmesg | grep "drm"

[    0.427477] ACPI: bus type drm_connector registered
[    0.443641] [drm] Initialized simpledrm 1.0.0 20200625 for simple-framebuffer.0 on minor 0
[    0.444024] simple-framebuffer simple-framebuffer.0: [drm] fb0: simpledrmdrmfb frame buffer device
[    1.932840] systemd[1]: Starting Load Kernel Module drm...
[    1.955414] systemd[1]: modprobe@drm.service: Deactivated successfully.
[    1.955778] systemd[1]: Finished Load Kernel Module drm.
[    2.779804] i915 0000:00:02.0: [drm] VT-d active for gfx access
[    2.779844] i915 0000:00:02.0: [drm] Using Transparent Hugepages
[    2.783935] i915 0000:00:02.0: [drm] Finished loading DMC firmware i915/kbl_dmc_ver1_04.bin (v1.4)
[    3.124918] i915 0000:00:02.0: [drm] [ENCODER:94:DDI A/PHY A] failed to retrieve link info, disabling eDP
[    5.136656] [drm] Initialized i915 1.6.0 20230929 for 0000:00:02.0 on minor 1
[    5.141750] [drm] amdgpu kernel modesetting enabled.
[    5.142047] [drm] initializing kernel modesetting (VEGAM 0x1002:0x694C 0x8086:0x2073 0xC0).
[    5.142060] [drm] register mmio base: 0xDB500000
[    5.142061] [drm] register mmio size: 262144
[    5.142138] [drm] add ip block number 0 <vi_common>
[    5.142140] [drm] add ip block number 1 <gmc_v8_0>
[    5.142141] [drm] add ip block number 2 <tonga_ih>
[    5.142142] [drm] add ip block number 3 <gfx_v8_0>
[    5.142143] [drm] add ip block number 4 <sdma_v3_0>
[    5.142144] [drm] add ip block number 5 <powerplay>
[    5.142145] [drm] add ip block number 6 <dm>
[    5.142146] [drm] add ip block number 7 <uvd_v6_0>
[    5.142147] [drm] add ip block number 8 <vce_v3_0>
[    5.145994] [drm] UVD is enabled in VM mode
[    5.145996] [drm] UVD ENC is enabled in VM mode
[    5.145999] [drm] VCE enabled in VM mode
[    5.161223] [drm] vm size is 128 GB, 2 levels, block size is 10-bit, fragment size is 9-bit
[    5.161313] [drm] Detected VRAM RAM=4096M, BAR=4096M
[    5.161314] [drm] RAM width 256bits HBM
[    5.161474] [drm] amdgpu: 4096M of VRAM memory ready
[    5.161477] [drm] amdgpu: 16004M of GTT memory ready.
[    5.161517] [drm] GART: num cpu pages 65536, num gpu pages 65536
[    5.161556] [drm] PCIE GART of 256M enabled (table at 0x000000F400580000).
[    5.162607] [drm] Chained IB support enabled!
[    5.167184] [drm] Found UVD firmware Version: 1.130 Family ID: 16
[    5.168920] [drm] Found VCE firmware Version: 53.21 Binary ID: 3
[    5.238581] amdgpu 0000:01:00.0: [drm] dce110_link_encoder_construct: Failed to get encoder_cap_info from VBIOS with error code 4!
[    5.238602] amdgpu 0000:01:00.0: [drm] dce110_link_encoder_construct: Failed to get encoder_cap_info from VBIOS with error code 4!
[    5.238640] [drm] Display Core v3.2.266 initialized on DCE 11.22
[    5.306383] i915 0000:00:02.0: [drm] Cannot find any crtc or sizes
[    5.349683] [drm] UVD and UVD ENC initialized successfully.
[    5.450642] [drm] VCE initialized successfully.
[    5.464062] [drm] Initialized amdgpu 3.57.0 20150101 for 0000:01:00.0 on minor 2
[    5.474407] amdgpu 0000:01:00.0: [drm] Cannot find any crtc or sizes
[    5.478422] i915 0000:00:02.0: [drm] Cannot find any crtc or sizes
[    5.657785] i915 0000:00:02.0: [drm] Cannot find any crtc or sizes
[   28.793067] [drm] PCIE GART of 256M enabled (table at 0x000000F400580000).
[   29.121920] [drm] UVD and UVD ENC initialized successfully.
[   29.222865] [drm] VCE initialized successfully.

# displays information about the OpenGL renderer
glxinfo | grep "OpenGL renderer"

# NVIDIA GPU, this command will display details such as memory usage, temperature, and performance metrics
nvidia-smi

Stop processes

# use process IDs
kill -9 $(ps aux | grep qemu | awk '{print $2}')
sudo kill -9 $(ps aux | grep qemu-.*.sh | awk '{print $1}' | xargs)
# use process names
sudo systemctl stop qemu@qemu-system-x86_64 qemu@qemu-system-i386 qemu@qemu-aio