Wednesday, January 6, 2016

How to Install and Use zerofree on CentOS, RHEL, and Fedora to Compact VM Disks

When shrinking dynamic virtual machine disk images (such as VirtualBox VDI, VMware VMDK, or QEMU QCOW2), zeroing out unused filesystem blocks is essential for effective host compression. Because Enterprise Linux distributions (CentOS 6/7, RHEL) do not ship zerofree in their default package repositories, compiling from source is the quickest solution.

Environment: CentOS 6/7 • RHEL • Fedora • Ext3 / Ext4 Filesystems

1. Installing Build Headers and Compiling zerofree

Install the e2fsprogs development headers and compile:

yum install e2fsprogs-devel gcc make -y
cd /usr/src
wget http://frippery.org/uml/zerofree-1.0.3.tgz
tar -zxf zerofree-1.0.3.tgz
cd zerofree-1.0.3
make
cp zerofree /usr/bin/

2. Zeroing Out Unallocated Blocks

Important: Always remount the target filesystem in read-only mode prior to executing zerofree to prevent filesystem corruption:

# Remount filesystem as read-only:
mount -o remount,ro /

# Run zerofree on the target block partition:
zerofree -v /dev/sda1

Once complete, shut down the VM and run your hypervisor's disk compacting command (e.g. VBoxManage modifymedium --compact disk.vdi) on the host machine.

Saturday, September 19, 2015

Configuring PETSc and Eclipse Parallel Tools Platform (PTP) on macOS and Linux (C++ / Fortran)

The PETSc (Portable, Extensible Toolkit for Scientific Computation) framework provides high-performance data structures, sparse matrix operations, and scalable linear/nonlinear solvers for finite element and scientific modeling. Setting up PETSc within the Eclipse Parallel Tools Platform (PTP) IDE simplifies debugging and cross-compilation across macOS and Linux.

Platforms Verified: macOS Yosemite • Ubuntu 14.04 LTS • CentOS / RHEL (OpenMPI) • C++ and Fortran Compilers

1. Building PETSc with OpenMPI

Configure PETSc with shared libraries and debugging enabled:

./configure --with-shared-libraries=1 --with-debugging=1 PETSC_ARCH=debug
make PETSC_DIR=/path/to/petsc PETSC_ARCH=debug all
make PETSC_DIR=/path/to/petsc PETSC_ARCH=debug test

2. Eclipse Project Configuration

  1. Environment Variables: In Project Properties → C/C++ Build → Environment, add:
    • PETSC_DIR: Absolute path to your PETSc root directory.
    • PETSC_ARCH: Set to debug for Debug configurations and release for Release.
  2. Include Paths: Under C/C++ General → Paths and Symbols → Includes:
    ${PETSC_DIR}/include
    ${PETSC_DIR}/${PETSC_ARCH}/include
  3. Linker Libraries & Path: Under C/C++ Build → Settings → Linker:
    • Libraries (-l): Add petsc
    • Library search path (-L): Add ${PETSC_DIR}/${PETSC_ARCH}/lib
    • Miscellaneous Linker flags: Add runtime path binding:
      -Wl,-rpath,"${PETSC_DIR}/${PETSC_ARCH}/lib"
  4. Fortran Preprocessing Flags: If using gfortran, navigate to Fortran Build → Settings → Miscellaneous and add:
    -cpp -dM

3. Verification Test (C++)

#include <iostream>
#include "petsc.h"

int main(int argc, char *argv[]) {
    PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
    PetscPrintf(PETSC_COMM_WORLD, "PETSc successfully initialized in Eclipse!
");
    PetscFinalize();
    return 0;
}

Wednesday, October 22, 2014

Automating Low-Cost Server Backups to Amazon Glacier with glacier-cmd (cPanel & Virtualmin)

Amazon Glacier provides an extremely cost-effective cold-storage solution for archiving periodic server backups (such as weekly full-system and MySQL snapshots) without paying standard S3 active storage pricing. Here is how to configure automated Glacier uploads using the command-line utility glacier-cmd on cPanel and Virtualmin servers.

Components: Amazon Glacier Vault • glacier-cmd Python CLI • Automated root cron backup workflow

1. Installing glacier-cmd

Install Python setup tools and the Glacier command-line interface:

yum install git python python-setuptools -y
cd /usr/src

# For cPanel servers, link git to system path if needed:
[ ! -f /usr/bin/git ] && ln -s /usr/local/cpanel/3rdparty/bin/git /usr/bin/git

git clone https://github.com/uskudnik/amazon-glacier-cmd-interface
cd amazon-glacier-cmd-interface
python setup.py install

2. Configuring AWS Credentials

Create ~/.glacier-cmd in the root home directory:

[aws]
access_key=YOUR_AWS_ACCESS_KEY_ID
secret_key=YOUR_AWS_SECRET_ACCESS_KEY

[glacier]
region=us-east-1
bookkeeping=True
bookkeeping-sqlite-db=/root/.glacier-cmd-db

3. Uploading Backups to a Vault

Create your backup vault and upload archives with automatic multipart chunking:

# Create a new vault
glacier-cmd mkvault server-backups

# Upload a backup archive with description
glacier-cmd upload --description "cPanel Weekly Full Backup $(date +%Y-%m-%d)" server-backups /backup/weekly-backup.tar.gz

Monday, May 26, 2014

Essential Fortran Tips: Implicit Typing, Common Blocks, and Array Bounds

When developing or maintaining scientific simulation and finite-element codes in Fortran, understanding memory sharing semantics and legacy typing rules prevents subtle computational bugs. Here are key fundamental tips to keep in mind:

Topics: Implicit precision typing • Common block limits • Explicit bounds declarations

1. Implicit Typing and Precision Control

By default in classic Fortran, variables starting with letters I through N default to integer, while all others default to single-precision real. You can enforce double precision across designated variable prefixes using:

IMPLICIT DOUBLE PRECISION (A-H, O-Z)

Modern recommendation: In Fortran 90 and newer, always specify IMPLICIT NONE at the top of every module and subroutine, explicitly declaring types and kinds (e.g. REAL(dp)) to avoid unintended variable scoping.

2. Blank vs. Named COMMON Blocks

  • A Fortran program may contain only one blank (unnamed) COMMON block across all translation units.
  • A program can declare any number of named COMMON blocks:
    COMMON /grid_params/ nx, ny, deltax, deltay
  • Ensure that variable sizes and ordering within named COMMON blocks match identically across all subroutines that include them.

Thursday, April 17, 2014

CFD: Generating Non-Uniform 2D Rectangular Grid Meshes in Fortran

In Computational Fluid Dynamics (CFD), resolving boundary layers and high-gradient shear regions requires non-uniform grid clustering near solid walls while keeping cell counts manageable in free-stream regions. Here is a Fortran routine to generate a geometrically stretched, symmetric 2D rectangular grid.

Domain: Rectangular 2D domain \([a, b] imes [c, d]\) • Method: Geometric progression expansion clustering toward boundaries

Mathematical Formulation

Given domain limits \(x \in [a, b]\) with \(n_x\) divisions and expansion ratio \(r_x\), the initial wall-adjacent step size \(\eta_x\) is computed from the geometric sum across the symmetric half-domain:

eta_x = (b - a) * (1 - exp_x) / (2 * (1 - exp_x**(n_x / 2)))
eta_y = (d - c) * (1 - exp_y) / (2 * (1 - exp_y**(n_y / 2)))

Fortran Source Code

! ====================================================================
! 2D Non-Uniform Symmetric Rectangular Grid Generator
! ====================================================================
      exp_x = 1.05   ! x-axis expansion factor
      exp_y = 1.10   ! y-axis expansion factor

      a = 0.0
      b = 1.0
      c = 0.0
      d = 1.0

! Uniform step sizes for reference
      del_x = (b - a) / n_x
      del_y = (d - c) / n_y

! Compute first wall-adjacent step sizes (eta_x, eta_y)
      eta_x = (b - a) * (1.0 - exp_x) / (2.0 * (1.0 - exp_x**(n_x / 2)))
      eta_y = (d - c) * (1.0 - exp_y) / (2.0 * (1.0 - exp_y**(n_y / 2)))

      x(1) = a
      y(1) = c

! --- X-Direction Mesh Generation ---
! Half 1: Wall to Center (Expanding)
      DO i = 2, n_x / 2 + 1
          x(i) = x(i - 1) + eta_x * exp_x**(i - 2)
      END DO

! Half 2: Center to Opposite Wall (Contracting)
      DO i = n_x / 2 + 2, n_x + 1
          x(i) = x(i - 1) + eta_x * exp_x**(n_x + 1 - i)
      END DO

! --- Y-Direction Mesh Generation ---
! Half 1: Wall to Center (Expanding)
      DO j = 2, n_y / 2 + 1
          y(j) = y(j - 1) + eta_y * exp_y**(j - 2)
      END DO

! Half 2: Center to Opposite Wall (Contracting)
      DO j = n_y / 2 + 2, n_y + 1
          y(j) = y(j - 1) + eta_y * exp_y**(n_y + 1 - j)
      END DO
! ====================================================================

Sunday, January 5, 2014

How to Disable 'Sort by Subject' in Roundcube Webmail

In Roundcube Webmail, accidentally clicking on the Subject column header triggers an expensive mailbox-wide sort operation. On large mail folders with thousands of messages, sorting by subject can freeze the UI and create heavy server load. Here is how to disable sorting on the Subject column while keeping date and status sorting intact.

File: program/steps/mail/func.inc • Target: Subject header click handler

Step-by-Step Fix

  1. Open program/steps/mail/func.inc in your text editor.
  2. Search for ./#sort (typically around line 440–445).
  3. Locate the onclick attribute generation:
    'onclick' => 'return ' . JS_OBJECT_NAME . ".command('sort','" . $col . "',this)"
  4. Replace it with a no-op handler for the subject column (or globally):
    'onclick' => 'return true'

Save the file. Clicking the Subject column header will no longer initiate slow sorting queries.

Tuesday, October 8, 2013

How to Log PHP mail() Sender Scripts and Headers to Detect Outgoing Spam

When a web server hosting multiple PHP applications or CMS sites is compromised by spammers, identifying the exact malicious PHP script sending unauthorized emails can be notoriously difficult. In PHP 5.3 and newer, built-in configuration directives allow you to track the exact script filename and originating source of every outgoing message.

Key Directives: mail.log for auditing script paths • mail.add_x_header for tracking script UID in email headers.

1. Enable mail.log

Open your server's php.ini (or pool configuration in PHP-FPM) and configure a dedicated mail log:

; Log all mail() function invocations, including script path and line number
mail.log = /var/log/php_mail.log

Ensure the web server user (e.g. apache or www-data) has write permissions to the destination file:

touch /var/log/php_mail.log
chown www-data:www-data /var/log/php_mail.log
chmod 660 /var/log/php_mail.log

2. Enable X-PHP-Originating-Script Header

To embed the sender script path directly into outgoing mail headers, enable mail.add_x_header:

; Adds X-PHP-Originating-Script header containing the UID and filename
mail.add_x_header = On

When an email is sent, the recipient headers will contain:

X-PHP-Originating-Script: 1000:contact_form.php

This allows you to immediately trace spam reports back to the offending script or compromised user account.

How Google Antigravity Solved the Mysterious NVIDIA Sleep Reboot on My Dell Inspiron 7567 (Ubuntu Linux)

If you run modern Ubuntu or Linux on a Dell Inspiron 15 Gaming (7567) or a similar 7th-gen Intel laptop paired with an NVIDIA GeForce GTX ...