Category: hello world

  • iSCSI

    Since battle.net does not allow installing games on NFS, I’ve decided to setup iSCSI target on Fedora.

    1. Install scsi-target-utils and create a disk image:
    [root@fedora ~]# dnf install scsi-target-utils
    
    [root@fedora ~]# mkdir /share/iscsi-disks
    [root@fedora ~]# cd /share/iscsi-disks/
    [root@fedora iscsi-disks]# dd if=/dev/zero of=disk01.img count=0 bs=1 seek=350G
    
    [root@fedora iscsi-disks]# ls -alF
    total 32822716
    drwxr-xr-x. 1 root flatwhite           20 Jun 13 10:23 ./
    drwxrwxr-x. 1 root flatwhite          592 Jun 14 11:35 ../
    -rw-r--r--. 1 root flatwhite 375809638400 Jun 14 13:36 disk01.img
    [root@fedora iscsi-disks]# 
    1. Add tgt configuration file:
    [root@fedora iscsi-disks]# vim /etc/tgt/conf.d/target01.conf 
    <target iqn.2025-03.coffee.nicewarm:fedora.target01>
        # provided device as a iSCSI target
        backing-store /share/iscsi-disks/disk01.img
        # iSCSI Initiator's IQN you allow to connect
        initiator-name iqn.2025-03.coffee.nicewarm:gentoo16.initiator
        # authentication info ( set anyone you like for "username", "password" )
    </target> 
    1. Update SELinux and firewall rules:
    [root@fedora iscsi-disks]# chcon -R -t tgtd_var_lib_t /share/iscsi_disks
    [root@fedora iscsi-disks]# semanage fcontext -a -t tgtd_var_lib_t "/share/iscsi_disks(/.*)?"
    [root@fedora iscsi-disks]# ls -alFZ 
    total 39776832
    drwxr-xr-x. 1 root flatwhite system_u:object_r:tgtd_var_lib_t:s0               20 Jun 13 10:23 ./
    drwxrwxr-x. 1 root flatwhite system_u:object_r:default_t:s0                   592 Jun 14 11:35 ../
    -rw-r--r--. 1 root flatwhite unconfined_u:object_r:tgtd_var_lib_t:s0 375809638400 Jun 14 13:45 disk01.img
    
    [root@fedora iscsi-disks]# firewall-cmd --add-service=iscsi-target
    success
    [root@fedora iscsi-disks]# firewall-cmd --add-service=iscsi-target --permenent
    success
    1. Start tgtd service and verify
    [root@fedora iscsi-disks]# systemctl enable --now tgtd 
    [root@fedora iscsi-disks]# tgtadm --mode target --op show                                 Target 1: iqn.2025-03.coffee.nicewarm:fedora.target01
        System information:
            Driver: iscsi
            State: ready
        I_T nexus information:
            I_T nexus: 1
                Initiator: iqn.2025-03.coffee.nicewarm:gentoo16 alias: gentoo16
                Connection: 0
                    IP Address: 192.168.85.254
        LUN information:
            LUN: 0
                Type: controller
                SCSI ID: IET     00010000
                SCSI SN: beaf10
                Size: 0 MB, Block size: 1
                Online: Yes
                Removable media: No
                Prevent removal: No
                Readonly: No
                SWP: No
                Thin-provisioning: No
                Backing store type: null
                Backing store path: None
                Backing store flags: 
            LUN: 1
                Type: disk
                SCSI ID: IET     00010001
                SCSI SN: beaf11
                Size: 375810 MB, Block size: 512
                Online: Yes
                Removable media: No
                Prevent removal: No
                Readonly: No
                SWP: No
                Thin-provisioning: No
                Backing store type: rdwr
                Backing store path: /share/iscsi-disks/disk01.img
                Backing store flags: 
        Account information:
        ACL information:
            ALL
            iqn.2025-03.coffee.nicewarm:gentoo16.initiator      

    Gentoo is going to be iSCSI initator.

    1. Install and configure open-iscsi:
    gentoo16 ~ # emerge sys-block/open-iscsi
    
    gentoo16 ~ # cd /etc/iscsi
    gentoo16 /etc/iscsi # tail -n 1 initiatorname.iscsi
    InitiatorName=iqn.2025-03.coffee.nicewarm:gentoo16
    
    gentoo16 /etc/iscsi # systemctl start iscsid
    1. Discover iSCSI target and login:
    gentoo16 /etc/iscsi # iscsiadm -m discovery -t st -p 192.168.85.15 -P 1
    Target: iqn.2025-03.coffee.nicewarm:fedora.target01
            Portal: 192.168.85.15:3260,1
                    Iface Name: default
    
    gentoo16 /etc/iscsi # iscsiadm -m node -T iqn.2025-03.coffee.nicewarm:fedora.target01 -l
    Login to [iface: default, target: iqn.2025-03.coffee.nicewarm:fedora.target01, portal: 192.168.85.15,3260] successful.
    gentoo16 /etc/iscsi #
    1. Verify new disk is attached:
    gentoo16 /etc/iscsi # dmesg | tail -n 15
    [ 7672.992912] thunderbolt 0000:00:0d.2: 0:6 <-> 1:14 (DP): failed to change bandwidth allocation
    [ 7712.128451] Loading iSCSI transport class v2.0-870.
    [ 7712.130614] iscsi: registered transport (tcp)
    [ 7757.121749] scsi host1: iSCSI Initiator over TCP/IP
    [ 7757.125558] scsi 1:0:0:0: RAID              IET      Controller       0001 PQ: 0 ANSI: 5
    [ 7757.129678] scsi 1:0:0:0: Attached scsi generic sg2 type 12
    [ 7757.130419] scsi 1:0:0:1: Direct-Access     IET      VIRTUAL-DISK     0001 PQ: 0 ANSI: 5
    [ 7757.132855] sd 1:0:0:1: Attached scsi generic sg3 type 0
    [ 7757.133029] sd 1:0:0:1: Power-on or device reset occurred
    [ 7757.133306] sd 1:0:0:1: [sdc] 734003200 512-byte logical blocks: (376 GB/350 GiB)
    [ 7757.133310] sd 1:0:0:1: [sdc] 4096-byte physical blocks
    [ 7757.133445] sd 1:0:0:1: [sdc] Write Protect is off
    [ 7757.133447] sd 1:0:0:1: [sdc] Mode Sense: 69 00 10 08
    [ 7757.133737] sd 1:0:0:1: [sdc] Write cache: enabled, read cache: enabled, supports DPO and FUA
    [ 7757.161678] sd 1:0:0:1: [sdc] Attached SCSI disk
    
    gentoo16 /etc/iscsi # lsblk
    NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
    sda           8:0    1     0B  0 disk
    sdb           8:16   1 477.5G  0 disk
    └─sdb1        8:17   1 477.5G  0 part
    sdc           8:32   0   350G  0 disk
    zram0       252:0    0     0B  0 disk
    zram1       252:1    0     0B  0 disk
    zram2       252:2    0    14G  0 disk /var/tmp
    nvme0n1     259:0    0 476.9G  0 disk
    ├─nvme0n1p1 259:1    0     1G  0 part /efi
    ├─nvme0n1p2 259:2    0     4G  0 part [SWAP]
    └─nvme0n1p3 259:3    0 471.9G  0 part /
    gentoo16 /etc/iscsi # 
    1. Setup newly attached disk:
    gentoo16 /etc/iscsi # gdisk /dev/sdc
    GPT fdisk (gdisk) version 1.0.10
    
    Partition table scan:
      MBR: not present
      BSD: not present
      APM: not present
      GPT: not present
    
    Creating new GPT entries in memory.
    
    Command (? for help): n
    Partition number (1-128, default 1):
    First sector (34-734003166, default = 2048) or {+-}size{KMGTP}:
    Last sector (2048-734003166, default = 734001151) or {+-}size{KMGTP}:
    Current type is 8300 (Linux filesystem)
    Hex code or GUID (L to show codes, Enter = 8300):
    Changed type of partition to 'Linux filesystem'
    
    Command (? for help): i
    Using 1
    Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
    Partition unique GUID: 984FE47C-5DC5-41FA-B5A0-45AE5EED7271
    First sector: 2048 (at 1024.0 KiB)
    Last sector: 734001151 (at 350.0 GiB)
    Partition size: 733999104 sectors (350.0 GiB)
    Attribute flags: 0000000000000000
    Partition name: 'Linux filesystem'
    
    Command (? for help): c
    Using 1
    Enter name: fedora-iscsi
    
    Command (? for help): w
    
    Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
    PARTITIONS!!
    
    Do you want to proceed? (Y/N): y
    OK; writing new GUID partition table (GPT) to /dev/sdc.
    The operation has completed successfully.
    
    
    gentoo16 /etc/iscsi # mkfs.ext4 /dev/sdc1
    mke2fs 1.47.2 (1-Jan-2025)
    Creating filesystem with 91749888 4k blocks and 22937600 inodes
    Filesystem UUID: e91c4bfc-17be-4fba-bea7-e19cc33fda1c
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
            4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (262144 blocks): done
    Writing superblocks and filesystem accounting information: done
    

    5. Update /etc/fstab and mount:

    gentoo16 /etc/iscsi # cd
    gentoo16 ~ # lsblk -o NAME,PARTUUID
    NAME        PARTUUID
    sda
    sdb
    └─sdb1      b143c70c-01
    sdc
    └─sdc1      984fe47c-5dc5-41fa-b5a0-45ae5eed7271
    zram0
    zram1
    zram2
    nvme0n1
    ├─nvme0n1p1 55e2bb94-d149-45f1-a1fa-40eb55a1d4a4
    ├─nvme0n1p2 582238e0-7b6c-4315-8ce7-f54dd895afe2
    └─nvme0n1p3 115a26d3-e19a-47ba-929d-04f65ebddb4e
    
    gentoo16 ~ # cat /etc/fstab | tail -n 1
    PARTUUID="984fe47c-5dc5-41fa-b5a0-45ae5eed7271" /mnt/iscsi/     ext4    noauto,_netdev       0 1
    gentoo16 ~ # systemctl daemon-reload
    gentoo16 ~ # mount /mnt/iscsi/
    gentoo16 ~ # mount | grep iscsi
    /dev/sdc1 on /mnt/iscsi type ext4 (rw,relatime,_netdev)
    
    1. Update Flatpak permissions:
  • Removing top tabs in Firefox

    edit: no longer needed as vertical tabs are added to Firefox!

    1. Open about:config and set toolkit.legacyUserProfileCustomizations.stylesheets to true

    2. Put this under the Firefox profile:

    $ cat chrome/userChrome.css
    
    /* hides the native tabs */
    #TabsToolbar {
      visibility: collapse;
    }
    
    /* adjust navigation bar size */
    #nav-bar {
        margin-top: 1px;
        margin-right: 74px;
        margin-bottom: 1px;
    }
  • ollama + open-webui docker compose

    ❯ cat docker-compose.yaml
    services:
      ollama:
        image: ollama/ollama:latest
        container_name: ollama
        restart: always
        ports:
          - "11434:11434"
        environment:
          - "OLLAMA_HOST=0.0.0.0"
          - "OLLAMA_KEEP_ALIVE=120"
        volumes:
          - ollama-local:/root/.ollama
        deploy:
          resources:
            reservations:
              devices:
                - driver: nvidia
                  count: 1
                  capabilities: [gpu]
    
      openWebUI:
        image: ghcr.io/open-webui/open-webui:main
        container_name: open-webui
        restart: always
        depends_on:
          - ollama
        ports:
          - "8080:8080"
        environment:
          - "OLLAMA_BASE_URL=http://ollama:11434"
          - "WEBUI_AUTH=false"
        extra_hosts:
          - "host.docker.internal:host-gateway"
        volumes:
          - open-webui-local:/app/backend/data
    
    
    volumes:
      ollama-local:
        external: true
      open-webui-local:
        external: true
    
    ❯ docker volume create open-webui-local
    ❯ docker volume create ollama-local
    ❯ docker compose up -d

  • sharing zram via NFS

    Apparently, 16GB memory is not enough to compile Firefox using clang with LTO. Since my mini PC has plenty of memory, I decided to create a zram device and share it via NFS.

    ## Fedora - NFS server, 192.168.1.2
    ### create a zram device and format it with ext4 without journaling
    $ cat /etc/mke2fs.conf 
    ... output omitted ...
    [fs_types]
    	ext4 = {
    		features = has_journal,extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file
    	}
    	ext4withoutjournal = {
            	features = extent,huge_file,flex_bg,metadata_csum,metadata_csum_seed,64bit,dir_nlink,extra_isize,orphan_file
    	}
    ... output omitted ...
    
    ### setting zram size as 16Gig
    $ cat /etc/systemd/zram-generator.conf  
    [zram0]
    zram-size = min(ram, 16384)
    compression-algorithm = zstd
    mount-point = /mnt/zram
    
    fs-type = ext4withoutjournal
    options = rw,nosuid,nodev,discard,X-mount.mode=1777
    
    $ sudo ln -s /usr/sbin/mke2fs /usr/sbin/mkfs.ext4withoutjournal
    
    $ ls -alF /usr/sbin/mkfs.ext4withoutjournal 
    lrwxrwxrwx. 1 root root 6 Aug 31 21:33 /usr/sbin/mkfs.ext4withoutjournal -> mke2fs*
    
    ### reboot will disable the default zram swap and /dev/zram0 will now be mounted under /mnt/zram
    
    ### check zram is mounted
    $ mount | grep zram
    /dev/zram0 on /mnt/zram type ext4 (rw,nosuid,nodev,relatime,seclabel,discard)
    
    ### no_root_squash is required for root to write on nfs
    $ cat /etc/exports
    /mnt/zram 192.168.1.0/24(rw,sync,no_root_squash)
    
    ## Gentoo - NFS client, 192.168.1.100
    ### emerge nfs-utils
    $ sudo emerge net-fs/nfs-utils
    
    ### create a mount point and mount the zram
    $ sudo mkdir /mnt/nfs/zram
    $ sudo mount -t nfs 192.168.1.2:/mnt/zram /mnt/nfs/zram
    
    ### check zram is mounted
    $ sudo mount | grep zram
    /dev/zram2 on /var/tmp type ext4 (rw,relatime,discard)
    192.168.1.2:/mnt/zram on /mnt/nfs/zram type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.100,local_lock=none,addr=192.168.1.2)
    
    ### create a 8Gig swapfile
    $ sudo fallocate -l 8Gib /mnt/nfs/zram/swapfile
    $ sudo chmod 600 /mnt/nfs/zram/swapfile
    
    ### check swapfile is created
    $ ls -alFh /mnt/nfs/zram/swapfile 
    -rw------- 1 root root 8.0G Aug 31 23:48 /mnt/nfs/zram/swapfile
    
    $ sudo mkswap /mnt/nfs/zram/swapfile
    Setting up swapspace version 1, size = 8 GiB (8589930496 bytes)
    no label, UUID=f910bbdf-1ff2-4c20-9bdb-f5f92bd37156
    $ sudo swapon -p 100 /mnt/nfs/zram/swapfile
    
    ### verify swap
    $ sudo swapon --show
    NAME                   TYPE      SIZE   USED PRIO
    /dev/nvme0n1p6         partition   4G 404.9M   -2
    /mnt/nfs/zram/swapfile file        8G     0B  100
    
    ### you can also use /mnt/nfs/zram as portage tmpfs by setting PORTAGE_TMPDIR to utilize the remaining space
    PORTAGE_TMPDIR="/mnt/nfs/zram"

    References:
    https://wiki.gentoo.org/wiki/Zram
    https://www.redhat.com/sysadmin/configure-nfs-linux

  • bash shortcuts

    My favorite bash tips found from stack overflow:

    !^      first argument
    !$      last argument
    !*      all arguments
    !:2     second argument
    
    !:2-3   second to third arguments
    !:2-$   second to last arguments
    !:2*    second to last arguments
    !:2-    second to next to last arguments
    
    !:0     the command
    !!      repeat the previous line

    Examples:

    $ echo a b c d e 
    a b c d e
    $ echo !^
    echo a
    a
    
    $ echo a b c d e 
    a b c d e
    $ echo !:1
    echo a
    a