Linux commands

Põhilised käsud

clear – clear the screen
apt-get update – update repositories (updates paths for installing files)
sudo su – enable superuser (root – administrator)
su user(nickname) – switch from root to regular user
apt-get upgrade – update packages inside the system
lsblk – display information about storage devices

fdisk

sudo fdisk /dev/sdb – run fdisk to manage disk partitions (in this case /dev/sdb)
p – display current disk partitions
d – delete partition
n – create new partition
w – write changes to disk and exit
q – exit without saving changes
t – change partition type (e.g. for Linux Swap installation)
l – list available partition types

lsblk – display disk and partition structure
sudo fdisk -l – list all disks and their partitions

sudo mkfs.ext4 /dev/sdb1 – create ext4 file system on partition /dev/sdb1
sudo mkfs.xfs /dev/sdb1 – create XFS file system

sudo mount /dev/sdb1 /mnt – mount partition /dev/sdb1 on /mnt
sudo umount /mnt – unmount partition
sudo mount -o rw /dev/sdb1 /mnt – mount in read-write mode

sudo apt install mc – install Midnight Commander
mc – run Midnight Commander

raid

sudo apt-get install mdadm(mdadm – utility for working with software RAID arrays of various levels)
sudo wipefs –all –force /dev/sd{b,c} – cleans disk metadata

create raid 1

sudo mdadm –create –verbose /dev/md0 -l 1 -n 2 /dev/sd{b,c} – creates RAID 1
/dev/md0 – name of the raid array
-l 1 – raid level
-n – number of disks

echo “DEVICE partitions” > /etc/mdadm/mdadm.conf – tells mdadm to look for a raid
mdadm –detail –scan –verbose | awk ‘/ARRAY/ {print}’ >> /etc/mdadm/mdadm.conf – adds raid to config
nano /etc/mdadm/mdadm.conf – edits mdadm config
mkfs.ext4 /dev/md0 – formats raid to ext4

to create a new directory in mc – F7

sudo blkid /dev/md0 – shows information about the file system and UUID of the RAID array
sudo mkfs.ext4 /dev/md0 – creates an ext4 file system on the RAID array /dev/md0
sudo mkdir -p /mnt – creates the /mnt folder if it does not exist
sudo mount /dev/md0 /mnt – mounts the RAID array /dev/md0 to /mnt so that it can be accessed as a normal one directory

sudo blkid /dev/md0 – shows information about the file system and UUID of the device /dev/md0
sample output: /dev/md1: UUID=”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx” TYPE=”ext4″

nano etc/fstab – opens the file in a text editor
add the line at the end: UUID=”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx” /mnt ext4 defaults 0 0
ctrl + o – save the file
ctrl + x – exit the file

if you need to delete the raid array
sudo mdadm –stop /dev/md0 – stops
sudo mdadm –remote /dev/md0 – deletes