• Category Archives Linux
  • Booting to a RAID drive from a USB key

    I ran into a situation recently where I was building a new server install on a RAID controller in an old extra PC (Dell Optiplex). The BIOS in this machine wouldn’t allow a boot directly from the RAID card, but it did support booting from a USB flash drive.

    My solution was to put a bootloader on the USB drive and have it load the operating system directly from the RAID logical volume.

    1. Boot into rescue mode from your distro’s installation DVD. I used CentOS 7 but any distro would probably be fine.
    2. Mount the RAID volume with your previously installed operating system using chroot /mnt/sysimage
    3. Once booted, insert your USB Flash Drive
    4. Type fdisk -l (and note which device is your USB)
    5. Type mkdir /mnt/USB && mount /dev/sdx1 /mnt/USB (replacing x with your actual usb device)
    6. Type grub-install –force –no-floppy –boot-directory=/mnt/USB/boot /dev/sdx (replacing x with your actual USB device)
    7. Type cd /mnt/USB/boot/grub2
    8. Type cp /boot/grub2/grub.cfg .
    9. You may need to update the grub.cfg on the USB so that the paths points to the correct location of the kernel image and initramdisk in /boot
    10. You should now be able to boot your operating system installed on the RAID volume off of the USB drive

  • Flush Postfix Mail Queue

    Traditionally you use the “sendmail -q” command to flush mail queue under Sendmail MTA. Under Postfix MTA, just enter the following command to flush the mail queue:

    # postfix flush

    OR

    # postfix -f

    To see mail queue, enter:

    # mailq

    To remove all mail from the queue, enter:

    # postsuper -d ALL

    To remove all mails in the deferred queue, enter:

    # postsuper -d ALL deferred

    postfix-delete.pl script

    Following script deletes all mail from the mailq which matches the regular expression specified as the first argument

    #!/usr/bin/perl
     
    $REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!";
     
    @data = qx</usr/sbin/postqueue -p>;
    for (@data) {
      if (/^(\w+)(\*|\!)?\s/) {
         $queue_id = $1;
      }
      if($queue_id) {
        if (/$REGEXP/i) {
          $Q{$queue_id} = 1;
          $queue_id = "";
        }
      }
    }
     
    #open(POSTSUPER,"|cat") || die "couldn't open postsuper" ;
    open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;
     
    foreach (keys %Q) {
      print POSTSUPER "$_\n";
    };
    close(POSTSUPER);
    

    For example, delete all queued messages from or to the domain called fackspamdomain.com, enter:

     ./postfix-delete.pl fackspamdomain.com

    Delete all queued messages that contain the word “xyz” in the e-mail address:

    ./postfix-delete.pl xyz