Saturday, April 15, 2023

Automatically set Linux as first boot option

Having two operating systems (Linux and Windows 10) I get annoying problem - WIndows 10 keep settings itself first boot option instead of what I wanted. After selecting Linux manually at UEFI boot menu I want it to set itself first again. Following script and systemd service file allows to check boot order in UEFI and set Linux as first boot

 

Script named "BootFirst" and located in "/etc/systemd/system/scripts":

 #!/bin/bash

#Name=${1:-shell}
Name="${1}"
Result=0

if [[ -z "$Name" ]] # if empty
then
    Name="Linux"
fi

readarray -t BootInfo < <(efibootmgr)
BootOrder=$(printf -- '%s\n' "${BootInfo[@]}" | grep -P "^BootOrder: " | perl -pe 's/^BootOrder:\s+(.*)$/\1/')
IFS=',' read -ra BootOrder <<< "$BootOrder"

FirstBootNumber=${BootOrder[0]}
SelectedBootNumber="$(printf -- '%s\n' "${BootInfo[@]}" | grep -im1 $Name | perl -p -e 's/^Boot(\d{4}).*$/\1/g')"
if [[ -n "$SelectedBootNumber" ]] && [[ -n "$FirstBootNumber" ]] # if found
then
    if [[ ! $SelectedBootNumber = $FirstBootNumber ]]; then
        First=$(printf -- '%s\n' "${BootOrder[@]}" | grep -nm1 "$FirstBootNumber" | cut -f1 -d":")
        ((First--))
        Selected=$(printf -- '%s\n' "${BootOrder[@]}" | grep -nm1 "$SelectedBootNumber" | cut -f1 -d":")
        ((Selected--))
        Tmp="${BootOrder[First]}"
        BootOrder[First]="${BootOrder[Selected]}"
        BootOrder[Selected]="$Tmp"
        efibootmgr -o "$(printf -- '%s,' "${BootOrder[@]}"| perl -pe 's/^(.*),$/\1/')"
        Result=$?
        if (( Result == 0 ))
        then
            echo "Have set new boot order"
        fi
    else
        echo "Boot order is correct"
    fi
else
    echo "Error: found no entries that match '$Name'"
    exit 1
fi
if (( Result != 0 ))
then
    echo "Failed: exiting with nothing"
fi


Systemd service file named "boot-order.service":

[Unit]
Description=Set Linux as the first boot option
#After=

[Service]
Type=oneshot
ExecStart=/etc/systemd/system/scripts/BootFirst

[Install]
WantedBy=multi-user.target

After making this files run:

systemctl daemon-reload

systemctl enable boot-order.service

 

 

Saturday, February 18, 2023

Fixing lags and stuttering with Oculus Quest 2 and Mikrotik WiFi

 Trying to make Air Link work properly between my PC and Oculus Quest 2 I have found that my Mikrotik cAP ac access point working very bad. Further investigation get me to the possible reason - access point constantly switching connection rate (single/double chain, short/long gate interval, etc). So I did the following:

1) disable 2.4GHz WiFi

2) set 5GHz WiFi settings to the following:

    band=5ghz-onlyac

    channel-width=20/40/80mhz-XXXX

    country=***my country***

    distance=indoors

    guard-interval=long (disable short gate interval)

    rx-chains=0 (using one antenna for receive only)

    tx-chains=1 (using second antenna for transmission only)

    frequency=5180 (it appears that lower channels provide better speed even when it is used by neighbors)

This helped me to achieve stable Air Link between my PC and Oculus Quest 2 with 105Mbit/s fixed rate.

Later I have upgraded my WiFi to hAP-ax³. And get another problem - while network speed was fine (400Mb/s speedtest in Oculus browser) there was about 2..5 FPS when using AirLink. This happened only when my PC was connected to ethernet port. If I connect my PC to router using same WiFi to which Oculus is connected - AirLink was working (not playable, but usable for browsing). The cause was in hardware offloading enabled for ethernet ports in Bridge tab of Mikrotik configuration. Disabling it suddenly fixed all the problems. Seems like hardware offloading causing extra delay, because routing and WiFi is handled by CPU and not by switch-chip. Or maybe it's some limitations of switch-chips related to QoS or etc.

Friday, September 13, 2019

Problems of Linux as the OS for the work computers

I have been using Ubuntu and Arch Linux distributions in the past, and for me it feels like Arch is more stable and bug-free than Ubuntu. Ubuntu aim to be more stable, but when some bug present it may be not fixed until next release, which is quite annoying.

Bellow there is a list of problems of using Linux and related desktop software (obviously) for work computers that I have experience myself. Most of this problems happened at certain moments and is probably fixed already, but purpose of this list is rather to give example of real problems that may hit you out of nowhere

Linux:
1) Running on HDD is extremely slow. Never in my experience I could handle slowness of Linux desktop on HDD (even at times when HDD was the only available option)
2) 12309 - this stated as fixed long ago, but I've experienced GUI lags on excessive disk access for a long time after
3) Linux may "allocate" more memory than it physically have. Some application may request memory allocation, if this request fits to free memory Linux will allow it, yet will not actually do allocation. Since memory still free application may repeat request which may lead to virtual memory allocation much greater than physical memory. And everything is fine until application will try to use all of this "allocated" memory - at this moment comes OOM-killer and just kill application it wants. So instead of error when requesting too much memory (which a good program may be able to handle) this or any other program is just getting killed silently

LibreOffice:
1) Tooltips (for toolbar buttons) disappeared, which caused extreme frustration for elder user. Fixed by changing option in Advanced settings
2) Due to bugged KDE integration copy-paste was unreliable - sometimes text was copied as text only, other times as text with style, sometimes copied text was not available for other applications. Fixed by switching VCL mode to GTK3
3) Opening XLSx file with protected cells and attempt to change this cells resulted in infinite loop of password request which blocked application interface
4) LibreOffice Impress didn't supported videos in PPTx files

KDE/PlasmaShell/Desktop/Sound:
1) Multi monitor desktop is frustrating - you open application launcher and click on some application and it's window opens on secondary display, even if your mouse activity is on your primary display (and even if this display is selected as primary in display settings). One of the PC had bug which cause one of displays to go blank (no signal) at startup, even if desktop was extended to it. Another PC had projector screen marked as primary after every reboot. "Fixed" by playing with xrandr commands in auto-start script.
2) One of the applications crashed when closing which caused DrKonqi window to popup. This delayed system shutdown. "Fixed" by removing DrKonqi package
3) At certain moment KDE desktop widgets like CPU and memory usage graphs where consuming 50-100% of CPU.
4) Desktop widgets didn't remember its position after screen resolution change
5) KTorrent - was not able to work well with gigabit network and often freezed/crashed. "Fixed" by raise of vm.max_map_count
6) KDE NetworkManager settings had "100Mbit half-duplex" as default option for new network connections instead of "Auto negotiation"
7) Getting out of disk space in /home caused Dolphin file manager to forget all bookmarks
8) Sound volume changed after output - volume level was temporary preserved after switching to another audio output, which caused 1 second of 100% loud sound on device where 30% volume is comfortable maximum

Other apps:
1)  Firefox window was bugged at start - window is big but content is small. Need restore/maximize window to fix it. "Fixed" by making Firefox window not maximized at startup in individual windows rules (KDE option)

Saturday, July 27, 2019

Advantages of UEFI over BIOS

Below there is a list of things that I myself think of as advantages of UEFI over legacy BIOS:
1) Full support of GPT (advantages of which over MBR is another story)
2) UEFI partition is "visible" - by that I mean that unlike legacy MBR partition scheme, where booting information hidden inside special MBR record - UEFI partition is FAT (FAT32 mostly) partition with special mark. But still, its a regular partition that you're able to access directly from most of modern operating systems.
3) UEFI shell - when something does not boot right you can check things from primitive yet sufficient shell that is built-in most of the modern motherboard's firmware (most useful commands are: map, ls, cd and of-course changing file system (e.g. FS0:) and name of EFI executable to load).
4) Access to UEFI from running operating system - for instance you can:
- reboot PC and request start of another OS (use efibootmgr command to see list of available options):
    > efibootmgr -n 0001; sync; systemctl reboot
- reboot PC and go to UEFI settings without pressing DEL or F2 or etc:
    > systemctl reboot --firmware-setup
- see boot time without manual timer:
    > systemd-analyze plot > "/tmp/plot.svg"; xdg-open "/tmp/plot.svg"
when starting from UEFI there will be a motherboard boot time given
 5) Motherboard logo can be preserved while booting operating system (works for Linux) - this is rather personal preference.

Not whole list of advantages probably, but it's all that was important to me.

Monday, September 24, 2012

Удобное чтение мануалов в Linux

Часто случается, что необходимо прочитать мануал к программе, но чтение из консоли не удобно. Однако консольную версию man можно заменить на стандартную программу отображения справки в Gnome/Unity [link]:
man () { yelp "man:$@"; }
Эта команда создает функцию, которая заменяет имя man.
А так, мануал откроется в браузере Firefox
man () { /usr/bin/man --html=firefox $@; }
Можно заменить команду для запуска другого браузера, например, Chromium
man () { /usr/bin/man --html=chromium-browser $@; }
Эта функция сбрасывается после завершения сеанса пользователя (точнее, она просто не запоминается). Что бы эта команда работала всегда - необходимо добавить её в конец файла .bashrc. Откройте его для редактирования
xdg-open $HOME/.bashrc
и введите в конце одну из указанных выше строчек, и сохраните файл (настоятельно рекомендую предварительно сделать копию этого файла). После перезапуска - выполнение команды man откроет выбранный интерфейс.
Пользователям KDE повезло, браузер rekonq (для установки выполните apt:rekonq) может обрабатывать запросы в строке адреса вида man:* (например, man:apache2). Хотя, Firefox тоже умеет обрабатывать такие запросы, просто откроется стандартная утилита просмотра мануалов (в Gnome/Unity это yelp)

Tuesday, July 10, 2012

Статейка

Поучаствовал в написании статейки help.ubuntu.ru - Seahorse и help.ubuntu.ru - davfs2

Wednesday, February 8, 2012