Thursday, August 19, 2021

Reinstalling Archlinux on a old Laptop


 

Yesterday I accidentally run rm -rf /  because everybody makes mistakes. 

each step is written here:

1 - first memtest86 

2 - swap memories, test one memory slot each time, and test a new one memory module from another laptop that it's working. So in this part I figure out that my laptop was broken, so Nico borrow me an old laptop :'-( .

3 - UEFI, installing Archlinux on UEFI require use the pen-drive on UEFI mode. after boot on UEFI mode, I did a back up to the files on the /home directory and install the Operative System again. 

4 - first I already have the partition so, this part is not new. the only thing with this new laptop is that I have to do a new UEFI partition to the grub, my old laptop does not have UEFI mode, so the grub was installed in the BIOS MBR sort of.
 

After I did the new UEFI Archlinux partition with "cfdisk /dev/sda" change Type to UEFI system, and verify if the notebook has a the boot mode UEFI listing this directory:

 

ls -l /sys/firmware/efi/efivars

 

If the output show you a list of files! Bingo you are currently booting in UEFI mode.

In UEFI we need the partition table in this Disklabel "GPT", so we check with

fdisk -l if the partition table is type BIOS or GPT. the output should be like:

"Disklabel type: gpt"


Also used parted -l to fix an error that was show up when we execute "fdisk -l": 

"something that GPT partition was different from MBR partition"

"GPT PMBR size mismatch" something like that.

 To do that: I installed parted 

$pacman -S parted && parted -l /dev/sda

 

 

5 -  After that I formatted the partitions to do a fresh installation.

mkswap /dev/sda6

swapon /dev/sda6 

mkfs.ext4 /dev/sda5 => /root

mkfs.vfat -F32 /dev/sda7 => /boot/grub/efi

6 - preparing for the chroot

from general to specify 

mount /dev/sda5 /mnt

mkdir -p /mnt/boot/efi

mount /dev/sda7 /mnt/boot/efi

7 - using pacstrap to install base system

pacstrap /mnt base base-devel grub os-prober ntfs-3g networkmanager efibootmgr gvfs gvfs-afc dhcpcd vim linux-headers linux-firmware linux  netctl wpa_supplicant xf86-input-synaptics pavucontrol htop lshw meld transmission-gtk docker docker-compose gvfs-mtp xdg-user-dirs lightdm  xorg xorg-xinit gnome-keyring xorg-server xorg-server-common xf86-video-vesa xorg-font-util  ttf-dejavu opencl-nvidia dkms git terminator rsync go-tools cinnamon-desktop cinnamon gnome-terminal lightdm-gtk-greeter  pulseaudio  pulseaudio-alsa firefox vlc  gimp xfburn gedit gnome-system-monitor faenza-icon-theme smartmontools

 

(xorg is an alias and in this case I installed ALL :O, just in case).

 

At first I did the install of nvidia and nvidia-utils  nvidia-304, driver BUT  doesn't have the correct version of the drivers that I need. so I have to uninstall later to install the correct one.

 

Something to remember if you install nvidia-lts you need to install kernel-lts and header-lts, and re run mkinitcpio -p.

 

nvidia-xconfig to set Xorg configuration.  See Also nvidia-settings and nvidia-smi.

 

nouveau-dri  I tried to install the open source driver but was a failed, after many modprobe and rmprobe  with nouveau and nvidia and debuging with modinfo -p video, lshw -c video, so I  install the legacy driver from an AUR package with the tool "yay" is a client writen on golang, and is easy to use and install from Cli.

    Cinnamon package to see sections:

    $ pacman -Ql cinnamon | awk -F '[_.]' '/cs_.+\.py/ {print $2}'

 

8 - generar fstab

genfstab -pU /mnt >> /mnt/etc/fstab

 

9 - the chroot to make some configurations and installing the grub in the new uefi partition.

arch-chroot /mnt


10 - without  GUI, setting configuration files, service, and customizations:

    hostname

        echo "CoolName" >> /etc/hostname

   Timezone:
       ln -sf /usr/share/zoneinfo/America/Buenos_Aires  /etc/localtime
   Setting Locale:
       uncomment a line on this file "/etc/locale.gen" and run the command cli  $ locale-gen
   Setting keymap:
         localectl list-keymaps | grep -i us  (list all available keymaps)
         echo "KEYMAP=us" > /etc/vconsole.conf  (do the setting)
   Making grub config file:
         echo "GRUB_DISABLE_OS_PROBER=false" >> /etc/default/grub (edit /etc/default/grub)
         grub-install --efi-directory=/boot/efi --bootloader-id="Archlinux" --target=x86_64-efi --removable
         os-prober (testing if we have another OS like windows) 
         grub-mkconfig -o /boot/grub/grub.cfg
    Adding a new user to use with sudo:
        useradd -m -g users -G audio,lp,optical,video,wheel,games,power,scanner -s /bin/bash j3nnn1
        passwd j3nnn1 
    Installing nvidia driver via Yay: 
        - git clone https://aur.archlinux.org/yay.git
        - cd yay
        - makepkg -si (don't forget to add this user to sudoers file)
        - if you run without -i use pacman -U package.gz (optional)
        - yay -S nvidia-390xx-dkms 
        - yay -S google-chrome 
        - yay -S numix-gtk-theme 
    Setting  Time:
        - timedatectl set-ntp true. (only if you did previously the setting of timezone on the file: /etc/localtime)
        - timedatectl timesync-status
        - timedatectl status
    Related to Kernel:
        - mkinitcpio -P 
    Enable display manager and network manager and GUI:
        - systemctl enable lightdm
        - systemctl enable NetworkManager
        - systemctl isolate  graphical.target ( testing graphical UI, on next reboot will be dismiss this change) 
        - systemctl set-default multi-user.target (CLI)
        - systemctl set-default graphical.target (GUI) 
        - systemctl get-default 

11 - enable GUI.

     - systemctl set-default graphical.target (GUI) 

12 - disable GUI (troubleshooting).

     - systemctl set-default multi-user.target (CLI)

13 - testing with startx (xorg-xinit and xorg-apps should be installed)

       - edit file "~/.xinitrc".  

            vim ~/.xinitrc 

            OR

            echo "exec cinnamon-session" > ~/.xinitrc

       - from CLI execute: startx


And That's all. 

By now..

Sorry about  the Spanglish and grammatical errors.

14 - tools nvidia

is loaded nvidia driver?

dkms install --no-depmod nvidia/390.144 -k 5.15.3-arch1-1 && depmod 5.15.3-arch1-1

Logs

cat /var/log/Xorg.0.log

Blacklist noveau

caracas# cat /usr/lib/modprobe.d/nvidia-390xx-dkms.conf
blacklist nouveau 

When The Xorg Server API is not compatible with the driver:

caracas# cat /etc/X11/xorg.conf.d/20-server_flags.conf

Section "ServerFlags"
    Option "IgnoreABI" "1"
EndSection

cat /usr/lib/modprobe.d/nvidia-lts.conf

update nvidia driver with new API

 ..@TODO

References: 

https://wiki.archlinux.org/title/NVIDIA#Installation


gdm locked user.

vim /etc/security/faillock.conf

deny = 9999


Sunday, August 8, 2021

tools en linux

generar clave de 4 palabras. 
shuf -n4 /usr/share/dict/words | tr -d '\n'
todas las ips conectadas a mi host.
netstat -lantp | grep ESTABLISHED |awk '{print $5}' | awk -F: '{print $1}' | sort -u
chequear sintaxis
find . -name \*.php -exec php -l "{}" \; 
listar solo directorios.
find . -maxdepth 1 -type d | sort

recuperar archivos y se ejecuta como root o con sudo.
testdisk 
 
listar tamaño de uso de un archivo o directorio:

du -h . | egrep -i j3nnn1/santiagozarate$


eliminar procesos luego de una búsqueda. 


ps -fea | grep perl | awk '{print $2}' | xargs kill -9

matar un proceso zombie

dhcpcd zombi kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'`

Apuntes varios de GraphQL




 What is GraphQL? Is a query language and it’s focused on data manipulation of APIs, like an abstraction layer that lets us have many sources of data (Relational Database, APIs, documents databases, key-values databases) attached to one entrypoint, that let us filter fields from the client and take only the attributes/columns/data that we need and get in the response only what we defined as needed data.

 

Why use GraphQL in this process? because it is designed to make APIs fast, flexible, and developer-friendly. It can even be deployed within an integrated development environment (IDE) known as GraphiQL. As an alternative to REST, GraphQL lets developers construct requests that pull data from multiple data sources in a single API call. GraphQL gives API maintainers the flexibility to add or deprecate fields without impacting existing queries, that’s a plus to avoid errors from versioned API and have a lower impact on production changes.


Things to take into account when we iterate over a product API:


  • Schema first design: The first thing you must do is agree on a schema with the team who will be building the backend. This will save a lot of refactoring later on, and if all goes according to plan you will be able to swap out the MockedProvider for the real one and your application should work seamlessly.

  • Design and implement with the user in mind.

  • Remember API retirement and change Management.


Common GraphQL terms.

Graphql is a strongly typed language[1] this means that Graphql defines various data  types to define the schema in this way is a fixed contract between client and server, so we communicate in the same way with each request, and allows us to talk about GraphQL schemas in a language-agnostic way (we don’t care if we are using javaScript, java or golang).


The most basic components of a GraphQL schema are object types, which just represent a kind of object you can fetch from your service, and what fields it has.


Some of Type System’s schema are:

  • Object Type

  • Fields

  • Query

  • Mutations

  • Array

  • List

  • And a set of default scalar types out of the box: Int (a signed 32 bits), float (A signed double precision), String (UTF-8 character sequence), Boolean (true or false), ID (The ID scalar type represents a unique identifier).


After we did a resume about the type system of Graphql, we could use several tools to mock data into this services, one of them is:

- Apollo graphql (server/client)

- mock.io/graphql ( it’s no a free, you’ll have to pay to used it)

- hasura.io[2]  (server, works with apollo client or any client for graphql) is an open source service that gives you production-grade APIs on your data without having to build, operate & scale a GraphQL server. This has a developer tier free. You could try it.



Advantages and Drawbacks of GraphQL.

Advantages.

  1. Reducing the amount of data returned between your frontend and the backend. Solves the issue of over-fetching or under-fetching data. Over-fetching is fetching all the data from an endpoint, but using only a portion of that data for, say, a mobile application. Under-fetching is fetching all the data from an endpoint, but not having enough data. This usually requires a call to a second endpoint.

  2. Developers can build APIs with whatever methods they prefer, and the GraphQL specification will ensure they function in predictable ways to clients without impacting existing queries.

  3. Aggregate that data together into a single meaningful response. GraphQL can be set up to call multiple backend services as it assembles its query response.

  4. GraphQL is a way to simplify the interactions with your backend data, by using an interface whose schemas describe the system behavior so you can get efficient data from your APIs, bringing you flexibility in retrieving information. has general usefulness for simplifying the use of complex APIs.

  5. Can be scalable using Apollo Federation[3], in this way you have one entrypoint (GraphQL Schema Server) and many implementations of resolvers behind this schema. Apollo Federation encourages a design principle called separation of concerns. This enables different teams to work on different products and features within a single data graph, without interfering with each other. This promised the benefits of a unified schema with distributed ownership and implementation.

Drawbacks.

  1. The basic framework cannot be avoided. You have to do things according to the GraphQL way.

  2. GraphQL presents a learning curve for developers familiar with REST APIs.

  3. GraphQL shifts much of the work of a data query to the server side, which adds complexity for server developers.

  4. API maintainers have the additional task of writing maintainable GraphQL schema.

Tools on GraphQL.

  • strapi, allow you to auto generate documentation from GraphQL schemas. https://strapi.io/documentation

  • hotchocolate, .Net Platform to implement  a GraphQL server (C#).

https://github.com/ChilliCream/hotchocolate

  • Offix, an offline client that allows GraphQL mutations and queries to execute even when an application is unreachable.

https://offix.dev/

  • Graphback, a command line-client for generating GraphQL-enabled Node.js servers.

https://graphback.dev/

  • OpenAPI-to-GraphQL, a command-line interface and library for translating APIs described by OpenAPI Specifications or Swagger into GraphQL.

https://github.com/IBM/openapi-to-graphql


Links referenced.

[1] https://graphql.org/learn/schema/

[2] https://hasura.io/

[3] https://www.apollographql.com/docs/federation/

See Also:

  • https://www.redhat.com/architect/apis-soap-rest-graphql-grpc
  • https://www.apollographql.com/docs/federation/
  • https://opensourcelibs.com/libs/graphql-schema
  • https://www.howtographql.com/
  • https://graphql.org/
  • https://graphql.org/swapi-graphql/