A chronological documentation test project, nothing serious, really!

03 Jan 2018 Print last Sunday of month

This is a bash oneliner to get the date of the last Sunday in the month, nice to have if you cannot figure out an easy solution in crontab.

# cal -m | awk ‘{print $7}’ | grep -E ‘[0-9]’ | tail -n 1

or only using awk
# cal -m | awk ‘$7!=””{l=$7} END {print l}’

The cal command is run using the -m switch to have the first day of week to be Monday.


Posted by

03 Feb 2016 Generate IP-address ranges using simple bash script

This is just a simple script to generate IP-addresses in a IP-range and write the result output to a file.
The script does also remove addresses you would like to exclude from the final output.


# Remove old OUTFILE
rm -f $OUTFILE

# Loop addresses, write to OUTFILE
for IP in $IPRANGE
        seq -f "$IP.%g" 1 255 >> ./$OUTFILE

# Exclude IP-addresses from file (inplace replacement)
for EX in $EXCLUDE
        sed --in-place "/$EX/d" ./$OUTFILE

Tags: , ,

Posted by

02 Nov 2015 How to mount LVM partitions from rescue mode

This is a short post about mounting LVM partitions when you are using a rescue CDROM or a desktop install CDROM. The whole process is only four easy steps.

  1. Boot your rescue media. This can be a CentOS, Ubuntu, Red Hat or other CDROM that gives you a console access to the server. Most newer linux distributions have LVM support available.Scan for volume groups
    # lvm vgscan -v
  2. Activate all Volume Groups
    # lvm vgchange -y
  3. List Logical Volumes
    # lvm lvs –all
  4. You have now activated the volumes and have all the information you need to mount them
    # mkdir /media/your-mount-point
    # mount /dev/volumegroup/logical-volume /media/your-mount-point

You can now look into /media/your-mount-point and see the content of your mounted LVM volume.


Tags: , , , ,

Posted by

15 Jul 2015 Virtualize physical Ubuntu linux server

This post describes how to create a bit for bit copy of a Ubuntu 14.04 LTS server using tools like gddrescue and qemu from a Ubuntu Live-CD. This procedure can actually be used to create a copy of any operating system, not just Ubuntu.

This could probably have been done more easily and faster using VMware vCenter Converter Standalone Client but I have experienced that not all linux flavours can be converted easily.

To perform such an operation you need several things.

  • Extra harddrive – same size or bigger than used disk space
  • Access to the linux packages gddrescue, qemu-imgThe first thing you should do to reduce the time ddrescue uses to copy the data is to remove unneeded files and folders as well as removing harddrives that you do not want to copy.

Creating the disk image

# ddrescue --nosplit /dev/sda imagefile.img imagefile.log

The –nosplit option copies the disk without retrying or splitting the file and is also “fast”.
Remember to place the imagefile.img on another harddisk than you are imageing to avoid filling your disk.

Convert the img file to a VWware VMDK disk file

# qemu-img -p convert -f raw sda.img -O vmdk sda.vmdk

Options used
-p gives you a nice progress indication of the conversion
-f raw tells us that we a trying to convert a raw disk image
-O vmdk describes the output format of the new disk image, in this example a VMware VMDK-file

qemu-img (1.5.0) supports a wide range of formats like vvfat vpc vmdk vhdx vdi sheepdog sheepdog sheepdog rbd raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd nbd nbd dmg tftp ftps ftp https http cow cloop bochs blkverify blkdebug.

Tags: , , , , , ,

Posted by