"Linux" on https://aligot-death.space, available at https://aligot-death.space/wiki/linux-en
Linux
Linux tips and notes.
Simple log analyzer for web traffic
sudo apt install goaccess
Then use like:
sudo goaccess /var/log/nginx/access.log.1 -c
Post-install
Add current user to sudo:
1 usermod nemecle -aG sudo
To install missing firmware (as printed during boot sequence), this command might be enough:
1 sudo apt install firmware
Basic packages to install:
1 sudo apt install vim sysstat mlocate tmux python3-pip htop rofi xbindkeys
2 keepassxc rsync fd-find hwinfo gparted curl
Easy network management from terminal
the nmcli utility is very easy and useful to manage network settings, including Wi-fi connections.
For instance, listing available Wi-Fi networks:
1 nmcli d wifi list
Connecting to a wifi network:
1 nmcli d wifi connect "Super Wifi" password "John19970612"
Mounting secondary drive on boot
- sudo blkid
- sudo umount /mnt/xxx
- vim /etc/fstab: if in doubt, just pu UUID, mount point, FS type and "defaults 0 0"
Recovering from deleted /boot/efi (dual boot)
the "/boot/efi" partition used to boot is not exclusive to Linux: it is shared with Windows, and thus you can (and should) provide it to utility tools that fix boot. It is usually on /dev/sda2. You can ls -l /boot/efi from a functioning linux to check its content.
The command to "install" grub requires to provide the disk, not a specific partition (e.g. /dev/sda, not /dev/sda2)
The following lines are a crude hint, the full operation might require some other mounting.
First, create a live USB/CD system, and boot on it.
Then we mount the dead system to be able to work with it:
1 for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do sudo mount -B /mnt$i; done
And we chroot to act as if we were on the dead system:
1 chroot /mnt
Then we mount the EFI partition:
1 mount /dev/sda2 /boot/efi
And finally we execute the "grub-install" command: The bootloader-id argument will be the name appearing in the EFI boot list if you go to the boot menu. Type the following command very carefully, a lot of people online seem to have errors simply due to typos:
1 sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --debug /dev/sda
You may eventually do (once you left chroot with exit like any shell instance):
1 update-grub
vim battle hardened config
" BASIC CONFIG
set encoding=utf-8
syntax on
set nu
set rnu
set hls
set sm
set smarttab
set nocompatible
set clipboard=unnamed
set scrolloff=30
set backspace=indent,eol,start " backspace over everything in insert mode
set ignorecase " do case insensitive search
set incsearch " show incremental search results as you type
" STYLE
" colorscheme peachpuff
highlight LineNr ctermfg=black ctermbg=grey
let g:indentLine_color_term = 239
" MAPPING
noremap <space> :
nnoremap <F2> za " Enable folding with F2
" Always show statusline
set laststatus=2
set t_Co=256"
set foldmethod=indent
set foldlevel=99
set tabstop=4
set softtabstop=4
set shiftwidth=4
set textwidth=79
set wrapmargin=0
set expandtab
set autoindent
set fileformat=unix
" web
au BufNewFile,BufRead *.html,*.css,*js
\ set tabstop=2 |
\ set softtabstop=2 |
\ set shiftwidth=2
autocmd BufRead,BufNewFile /etc/nginx/sites-*/* setfiletype conf
" to test
" Bind key to run python3
" map :w\|!python3 %
" " Bind key to run doctests in a python3 module
" map :w\|!python3 -m doctest %
" " Bind key to run doctests with verbose output
" map :w\|!python3 -m doctest -v %
" " Bind key to run pep8 Python style checker
" map :w\|!pep8 %
Changing the theme for GTK from CLI
(for instance, If you use typical GTK utilities in i3)
1 vim $HOME/.config/gtk-3.0/settings.ini
Example config:
1 [Settings]
2 gtk-icon-theme-name = Paper
3 gtk-theme-name = Arc-Darker
4 gtk-font-name = DejaVu Sans 11
ffmpeg
Creating a timelapse
1080p/30i with jpg files:
1 ffmpeg -framerate 30 -pattern_type glob -i '*.jpg' -c:v libx264 -r 30 -pix_fmt yuv420p -s hd1080 out.mp4
Concatenate ".ts" files from local record
For instance, if you made a local record using OBS
Create file list:
File order might be wrong, to fix
1 (for %i in (*.ts) do @echo file '%i') > mylist.txt
Then concatenate to a single mp4 file:
1 ffmpeg -f concat -i mylist.txt -c copy output.mp4
debugging CLI software
Set LD_DEBUG environment variable
Emergency mode
Happened to me as I changed my DATA HDD. because I added it to /etc/fstab
and the disk wasn't the same anymore, the system would drop into emergency
mode.
Once connected, try mounting all mount points and see errors:
mount -a
Direct kernel communication through key combo
Can be useful in case of partially stalled or locked system
Alt, press SysRq (The SysRq being the Print Screen key), release SysRq, press <command key>, Hit ALT-SysRq-<command key>, release everything.
Or if possible,
1 echo t > /proc/sysrq-trigger
with t being the command key.
See the wikipedia page for full command key list.
Can't beat a tool that has a "Perform a system crash" feature.
Managing multiple screens from CLI/i3wm
install xrandr. On debian, do:
sudo apt install x11-xserver-utils
More often than not, this is enough:
xrandr --auto
to see possible settings, type:
xrandr
to add a second screen next to a 2560x1440, plugged on HDMI2:
xrandr --output HDMI-2 --pos 2560x0 --mode 1920x1080 --rate 60
Remove a screen:
xrandr --output HDMI-2 --off