Linux guide

Ubuntu CPU, Memory and Disk

Monitor resources and find what is eating them.

Explore how to check CPU, memory, and disk information on an Ubuntu system

Up-time and processors ———————————————–

htop Shows CPU, Memory and Diks Utilization
cat /proc/cpuinfo Shows CPU Model
cat /proc/version Shows Ubuntu version is running

Reboot System
shutdown -h now
halt
reboot

Process
pidof apache2 Check PID of Apache process

sudo lsof -i:22  Check if port 22 is listening
sudo kill -9 process_id Kill Process using ID

Disk

lsblk List Disks with sizes

findmnt -D List partitions
df -h Display information about total space and available space on a file system.

sudo fdisk -l List partitions
sudo fdisk /dev/sdd

Add New Data Drive

cd /      # Navigate to root of drive
sudo mkdir /datadisk    # Create the mount point under root

(The directory /datadisk will be used as the mount point for the new disk).

lsblk        # (Identify Data disk. Verify the available disks and their partitions. Ensure you identify the correct disk (e.g., /dev/sdc in our case))
sudo mkfs.ext4 /dev/sdc       # (Format the disk with the ext4 filesystem. Replace /dev/sdc with the correct disk identifier from the lsblk output.)
lsblk -f       # (Confirm the new disk is formatted and note its UUID). Write Down UUID (566b58df-bd9b-4b6f-9e4c-f22ced590682)
sudo nano /etc/fstab    # run to open fstab

Add following line
UUID=”566b58df-bd9b-4b6f-9e4c-f22ced590682″ /datadisk ext4 defaults,nofail 1 2

sudo mount -a mount all  # (This mounts all file systems listed in /etc/fstab)


findmnt list mounting points

Add Swap File to Ubuntu VM in Azure

sudo nano /etc/waagent.conf Config file by setting the following three parameters

ResourceDisk.Format=y
ResourceDisk.EnableSwap=y
ResourceDisk.SwapSizeMB= 4096

service walinuxagent restart
free

dmesg | grep swap
swapon -s

cat /proc/swaps

file /mnt/resource/swapfile
free| grep -i swap