Archive for the Linux Category

Mar 2 2022

Limiting clamav memory usage

During a database reload clamd will load the new DB first and then drop the old one. This concurrent database reload strategy allows it to keep scanning files while loading the new database. The drawback is that it requires twice as much memory as during normal operations. As a result the clamd process would keep getting killed.

Starting from ClamAV 0.103.0 you can set ConcurrentDatabaseReload no in your /etc/clamav/clamd.conf to disable this behaviour

Feb 25 2022

Change from Slackware-14.2 (32-bit) to Slackware64-15.0 (64-bit)

Boot from Slackware-14.2 USB install stick

mkdir /myraid
mount /dev/md1 /myraid
mount /dev/md5 /myraid/usr
mount /dev/md6 /myraid/var
mount /dev/md7 /myraid/home

mount --bind /dev /myraid/dev
mount -t devpts devpts /myraid/dev/pts
mount -t proc proc /myraid/proc
mount -t sysfs sysfs /myraid/sys

mount USB with Slackware64-15.0
mkdir /myraid/usb
mount /dev/sdc1 /myraid/usb

chroot /myraid

cd /usb/slackware64/a
installpkg kernel-huge.t?z installpkg kernel-modules.t?z

reboot

uname -m should prints ‘x86_64
mount usb stick to /mnt/usb

cd /mnt/usb/slackware64/
installpkg a/aaa_glibc-solibs-2.33-x86_64-5.t?z
installpkg a/aaa_libraries-15.0-x86_64-19.t?z
installpkg a/aaa_base-15.0-x86_64-3.t?z
installpkg a/aaa_terminfo-6.3-x86_64-1.t?z

install rest of packages
installpkg */*.t?z

reboot. Now you are running a 64-bit system.
get rid of the old 32-bit packages:
removepkg /var/adm/packages/*-i[456]86-*
check the *.new files

Feb 18 2022

Slackware upgrade from 32-bit to 64-bit

  1. If you use 4 as the default runlevel, change it back to the default 3 in /etc/inittab.
  2. installpkg the 64-bit huge kernel and modules, ADD it to lilo.conf, run lilo, reboot. Now you are running the 32-bit system on a 64-bit kernel. ‘uname -m’ prints ‘x86_64’ instead of ‘i686’.
  3. installpkg the 64-bit a/glibc-solibs and a/aaa_elflibs. After that the basic 64-bit binaries would run in addition to the 32-bit ones.
  4. installpkg everything from the 64-bit directories slackware64/*/*.t?z.
  5. reboot. Now you are running a 64-bit system.
  6. get rid of the old 32-bit packages:
    removepkg /var/adm/packages/*-i[456]86-*
  7. check the *.new files

fdisk -l /dev/sda
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000001

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 10487807 10485760 5G fd Linux raid autodetect
/dev/sda2 10487808 16779263 6291456 3G 82 Linux swap
/dev/sda3 16779264 976773167 959993904 457.8G 5 Extended
/dev/sda5 16781312 48238591 31457280 15G fd Linux raid autodetect
/dev/sda6 48240640 69212159 20971520 10G fd Linux raid autodetect
/dev/sda7 69214208 976773167 907558960 432.8G fd Linux raid autodetect

root@dwarf:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md1 4.8G 3.5G 1.2G 76% /
/dev/md5 15G 12G 2.1G 86% /usr
/dev/md6 9.8G 4.6G 4.6G 50% /var
/dev/md7 426G 225G 180G 56% /home

mdadm –assemble –run /dev/md1 /dev/sdb1

mdadm –assemble –run /dev/md5 /dev/sdb5

mdadm –assemble –run /dev/md6 /dev/sdb6

mdadm –assemble –run /dev/md7 /dev/sdb7

setup

liloconfig /mnt /dev/md1


Mounts made by setup:
mount /dev/md1 /mnt
mount /dev/md5 /mnt/usr
mount /dev/md6 /mnt/var
mount /dev/md7 /home
ln -s /var/lib/pkgtools/packages /mnt/var/lib/pkgtools/packages

 

 

 

 

 

Feb 17 2022

Clone whole disk with linux

Clone entire disk to file

dd if=/dev/sda conv=sync,noerror,notrunc bs=16M status=progress | gzip /path/to_image

Restore disk from file

gunzip -c /path/to_image | dd of=/dev/sdc bs=16M status=progress

Copy MBR (identical discs)

dd if=/dev/sda of=/dev/sdb bs=512 count=1

Copy MBR (different disc’s sizes)

dd if=/dev/sda of=/tmp/mbr.img bs=512 count=1

dd if=/tmp/mbr.img of=/dev/sdb bs=446 count=1

The above commands will preserve the partitioning schema.

Feb 13 2022

sudo without password

visudo

add line

rafrom ALL=NOPASSWD: ALL

Feb 12 2022

upgrade to Slackware-15.0

mkdir /packages
mount /dev/cdrom /packages
telinit 1 | 3

1.  Upgrade your glibc shared libraries. This is important, or things
    might go haywire during the next part of the upgrade:
upgradepkg --install-new /root/slackware/a/aaa_glibc-solibs-*.txz

2.  Upgrade your package utilities and related tools:

    upgradepkg /root/slackware/a/pkgtools-*.txz
    upgradepkg /root/slackware/a/tar-*.txz
    upgradepkg /root/slackware/a/xz-*.txz
    upgradepkg /root/slackware/a/findutils-*.txz

3.  Upgrade everything else (and install new packages):

    upgradepkg --install-new /root/slackware/*/*.t?z

4.  Remove obsolete packages. The CHANGES_AND_HINTS.TXT file should have a
    list of these. You may also wish to go into /var/lib/pkgtools/packages
    and take a look at the package list:


    ls -lt | less
    removepkg --terse ConsoleKit2 PyQt Thunar aaa_elflibs amarok amor ash \
      automoc4 bigreqsproto calligra-l10n-bs calligra-l10n-ca \
      calligra-l10n-ca@valencia calligra-l10n-cs calligra-l10n-da \
      calligra-l10n-de calligra-l10n-el calligra-l10n-en_GB calligra-l10n-es \
      calligra-l10n-et calligra-l10n-fi calligra-l10n-fr calligra-l10n-gl \
      calligra-l10n-hu calligra-l10n-it calligra-l10n-ja calligra-l10n-kk \
      calligra-l10n-nb calligra-l10n-nl calligra-l10n-pl calligra-l10n-pt \
      calligra-l10n-pt_BR calligra-l10n-ru calligra-l10n-sk calligra-l10n-sv \
      calligra-l10n-tr calligra-l10n-uk calligra-l10n-zh_CN \
      calligra-l10n-zh_TW cargo cgmanager compositeproto damageproto db42 \
      db44 dirmngr dmxproto dri2proto dri3proto eigen2 eject evieext \
      fixesproto fontcacheproto fontsproto gcc-java getty-ps glade3 \
      glibc-solibs glproto gnome-themes-standard gnu-cobol gst-plugins-base0 \
      gst-plugins-good0 gstreamer0 gtk-xfce-engine herqq idnkit ilmbase \
      imapd inputproto intel-gpu-tools js185 kaccessible kajongg \
      kaudiocreator kbproto kde-base-artwork kde-baseapps kde-l10n-ar \
      kde-l10n-bg kde-l10n-bs kde-l10n-ca kde-l10n-ca@valencia kde-l10n-cs \
      kde-l10n-da kde-l10n-de kde-l10n-el kde-l10n-en_GB kde-l10n-es \
      kde-l10n-et kde-l10n-eu kde-l10n-fa kde-l10n-fi kde-l10n-fr \
      kde-l10n-ga kde-l10n-gl kde-l10n-he kde-l10n-hi kde-l10n-hr \
      kde-l10n-hu kde-l10n-ia kde-l10n-id kde-l10n-is kde-l10n-it \
      kde-l10n-ja kde-l10n-kk kde-l10n-km kde-l10n-ko kde-l10n-lt \
      kde-l10n-lv kde-l10n-mr kde-l10n-nb kde-l10n-nds kde-l10n-nl \
      kde-l10n-nn kde-l10n-pa kde-l10n-pl kde-l10n-pt kde-l10n-pt_BR \
      kde-l10n-ro kde-l10n-ru kde-l10n-sk kde-l10n-sl kde-l10n-sr \
      kde-l10n-sv kde-l10n-tr kde-l10n-ug kde-l10n-uk kde-l10n-wa \
      kde-l10n-zh_CN kde-l10n-zh_TW kde-runtime kde-wallpapers kde-workspace \
      kdeartwork kdegraphics-strigi-analyzer kdelibs \
      kdenetwork-strigi-analyzers kdepim kdepim-apps-libs kdepimlibs \
      kdesdk-strigi-analyzers kdevelop-php kdevelop-php-docs kdevplatform \
      kdewebdev keybinder kgamma kio-mtp klettres korundum kplayer kppp \
      kremotecontrol ksaneplugin ksnapshot ksysguard ktuberling ktux \
      kuser kwebkitpart lha libXfont libart_lgpl libbluedevil libcroco \
      libkdeedu libkgeomap liblastfm libmcs libmm-qt libmowgli libmsn \
      libnm-qt libtermcap libva-intel-driver libwmf-docs mailx man \
      mkfontdir mozjs52 mozjs60 mozjs68 mplayerthumbs nepomuk-core \
      nepomuk-widgets notify-python openldap-client openssl10 \
      openssl10-solibs orage oxygen-icons pairs perlkde perlqt \
      phonon-gstreamer pm-utils presentproto printproto pth pykde4 pyrex \
      python python-enum34 qca-qt5 qimageblitz qjson qt qt-gstreamer qtruby \
      qtscriptgenerator randrproto raptor2 rasqal recordproto redland \
      renderproto resourceproto rfkill rxvt scim scim-anthy scim-hangul \
      scim-input-pad scim-m17n scim-pinyin scim-tables scrnsaverproto \
      seamonkey-solibs sendmail sendmail-cf slocate smokegen smokekde \
      smokeqt soprano strigi superkaramba tetex tetex-doc transfig trn \
      urwid videoproto virtuoso-ose wicd-kde wireless-tools workbone \
      xcmiscproto xextproto xf86-video-xgi xf86-video-xgixp xf86bigfontproto \
      xf86dgaproto xf86driproto xf86miscproto xf86vidmodeproto xfractint \
      xineramaproto xproto xv


5.  IMPORTANT! *Before* attempting to reboot your system, you will need
    to make sure that the bootloader has been updated for the new kernel!
    First, be sure your initrd is up to date (if you use one). You can
    build a new initrd automatically by running the geninitrd script:

6. Genereate initrd
edit /usr/share/mkinitrd/mkinitrd_command_generator.sh
USING_RAID="Y"

mkinitrd -c -k 5.15.19 -f ext4 -r /dev/md0 -m jbd2:mbcache:crc32c_intel:crc32c_generic:ext4 -R -u -o /boot/initrd.gz
genitrd

7. ln -s /lib64/libcrypto.so.1.1 /lib64/libcrypto.so.1
8. reboot
Jan 28 2022

To recursively give directories read&execute privileges:

find /path/to/base/dir -type d -exec chmod 755 {} +

To recursively give files read privileges:

find /path/to/base/dir -type f -exec chmod 644 {} +

Or, if there are many objects to process:

chmod 644 $(find /path/to/base/dir -type f)
chmod 755 $(find /path/to/base/dir -type d)

Find files with permissions

find /path -perm 755

Change directories permissions from 750 to 755

chmod 755 $(find /path -type d -perm 750)

Change files permissions from 740 to 644

chmod 644 $(find /path -type f -perm 740)

 
Jan 14 2022

.htaccess if statement

<If “%{REMOTE_ADDR} == ‘123.123.123.123’ || %{REMOTE_ADDR} == ‘456.456.456.456’”>

Options +Indexes

</If>

<Else>

Options -Indexes

</Else>

Dec 14 2021

Resize mounted partition in Linux

You can resize only last partition at runtime

 

fdisk / gdisk

  • Run sudo fdisk /dev/sda
  • press p to list the partitions. Make note of the start cylinder of /dev/sda1 ex. 2048
  • press d to delete existing partition
  • press n to create new partition it is critical that the new partition starts at the same block as the old
  • do not remove the signature
  • press a and set boot flag

Reboot or use partprobe / kpartx to see new partition’s size

Resize filesystem

sudo resize2fs /dev/sda1

 

Dec 12 2021

resize RAID partitions

Ensure that the RAID array is consistent and synchronized by entering

cat /proc/mdstat

If your RAID array is still synchronizing according to the output of this command, you must wait until synchronization is complete before continuing.

sudo mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sda1

To succeed, both the fail and remove actions must be specified.

Increase the size of the partition, using a disk partitioner

Re-add the partition to the RAID array. For example, to add /dev/sda1

sudo mdadm -a /dev/md0 /dev/sda1

….

Wait until the RAID is synchronized and consistent before continuing with the next partition.

Repeat these steps for each of the remaining component devices in the array. Ensure that you modify the commands for the correct component partition.

If you get a message that tells you that the kernel could not re-read the partition table for the RAID, you must reboot the computer after all partitions have been resized to force an update of the partition table.

Remove second disk’s paritions from the RAID array:

sudo mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sdb1
sudo mdadm /dev/md1 --fail /dev/sda5 --remove /dev/sdb5
sudo mdadm /dev/md2 --fail /dev/sda6 --remove /dev/sdb6
sudo mdadm /dev/md3 --fail /dev/sda7 --remove /dev/sdb7

Check the size of the array and the device size known to the array by entering

sudo mdadm -D /dev/md0 | grep -e "Array Size" -e "Dev Size"

Increase the size of the array to the maximum available size by entering

sudo mdadm --grow /dev/md0 -z max --assume-clean

The array uses any space that has been added to the devices, but this space will not be synchronized. This is recommended for RAID 1 because the synchronization is not needed. It can be useful for other RAID levels if the space that was added to the member devices was pre-zeroed.

Recheck the size of your array and the device size known to the array by entering

sudo mdadm -D /dev/md0 | grep -e "Array Size" -e "Dev Size"

If your array was not resized as you expected, you must reboot, then try this procedure again.

You can increase the size of the file system to the maximum space available or specify an exact size. When specifying an exact size for the file system, ensure that the new size satisfies the following conditions:

  • The new size must be greater than the size of the existing data; otherwise, data loss occurs.
  • The new size must be equal to or less than the current RAID size because the file system size cannot extend beyond the space available.

Increase the size of the partition on second disk, using a disk partitioner

Re-add the partition to the RAID array. For example, to add /dev/sdb1..x enter:

sudo mdadm -a /dev/md0 /dev/sdb1
sudo mdadm -a /dev/md1 /dev/sdb5
sudo mdadm -a /dev/md2 /dev/sdb6
sudo mdadm -a /dev/md3 /dev/sdb7

Resize RAID partition to max size

sudo resize2fs -p /dev/md0
sudo resize2fs -p /dev/md1
sudo resize2fs -p /dev/md2
sudo resize2fs -p /dev/md3

WHEN ALL PARTITIONS ARE REBUILDED run:

mdadm --detail --scan >> /etc/mdadm.conf