Swap space notes

Whats using swap space

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less

Where are my swap files

 cat /proc/swaps

How to add more swap space

1. Create empty file:
This file will contain virtual memory contents so make file big enough for your needs. This one will create 1Gb file which means +1Gb swap space for your system:

dd if=/dev/zero of=/media/fasthdd/swapfile.img bs=1024 count=1M

If you want to make 3Gb file then change count value to count=3M. See man dd for more information.

2. Bake swap file:
Following command is going to make “swap filesystem” inside your fresh swap file.

mkswap /media/fasthdd/swapfile.img

3. Bring up on boot:
To make sure that your new swap space is activated while booting up computer you should add it to filesystem configuration file /etc/fstab. Add it to end of file, this is recommended because other filesystems (at least one that contains swap file) must be mounted in read-write mode before we can access any files.

# Add this line to /etc/fstab
/media/fasthdd/swapfile.img swap swap sw 0 0

4. Activate:
You can either reboot your computer or activate new swap file by hand with following command:

swapon /media/fasthdd/swapfile.img

Original articles


EasyRSA – Make a certificate and copy to ansible staging dir

I use this script on my CA server to create a certificate for each new server we provision. This allows our internal PKI to function.

This script creates a certificate then copies it to the Ansible server where is can be deployed to the destination host

Obviously you’ll need to take the necessary precautions around key security


cd /home/admin/EasyRSA-3.0.5/
/home/admin/EasyRSA-3.0.5/easyrsa build-server-full $ISSUE_NAME nopass
ssh edpk-ansible..local 'mkdir -p /home/admin/ansible/files/'$1'/'
scp /home/admin/EasyRSA-3.0.5/pki/issued/$ISSUE_NAME.crt edpk-ansible..local:/home/admin/ansible/files/$1/$1.crt
scp /home/admin/EasyRSA-3.0.5/pki/private/$ISSUE_NAME.key edpk-ansible..local:/home/admin/ansible/files/$1/$1.key
cd ~

Ubuntu interfaces file examples

Example 1 – Includes some static routes and manually specified IP’s

auto lo
iface lo inet static

auto ens3
iface ens3 inet static
up route add -net netmask gw
up route add -net netmask gw

iface ens3 inet6 static
address 2405:cc:ee:110::7
netmask 64
autoconf 0
accept_ra 0
gateway 2405:cc:ee:110:ff:ff

auto ens4
iface ens4 inet static

source /etc/network/interfaces.d/*.cfg


MYSQL Backup to S3 script



# Set the enviroment variable so read function knows to seperate on ",".
export IFS=","

NOW=$(date +"%Y_%m_%d_%H_%M")




echo "[$DB_SRV - $DB_NAME]"

mysqldump --single-transaction --quick --lock-tables=false \
-h $HOST \

echo "Uploading backup to S3 storage - $DB_SRV-$DB_NAME-$NOW.sql.gz"

aws --endpoint-url=$S3_ENDPOINT s3 cp $TEMP_BACKUP_DIR/$DB_SRV-$DB_NAME-$NOW.sql.gz $S3_BUCKET


echo -e "\n\n"


~/ .aws/credentials




Script to enable fast-diff on an entire pool of images and rebuild the object-map

This script enables the requisite features on all RBD images in a pool to allow you to run rbd du and have it return a result quickly as opposed to having to calculate the size very time

rbd ls -p backup1 | while read line; do
  echo "$line"
  rbd feature enable backup1/$line object-map exclusive-lock
  rbd object-map rebuild backup1/$line
  rbd snap ls backup1/$line | while read snap; do
        export snapname=$(echo $snap| awk '{print $2;}')
        if [ ! $snapname == "NAME" ]
                echo "$line@$snapname"
                rbd object-map rebuild backup1/$line@$snapname

KVM\Qemu\Openstack – Manage a live migration

virsh qemu-monitor-command {VMNAME} --pretty '{"execute":"migrate_cancel"}'

Allow Virsh more downtime(If it cant keepup with RAM utilization)

virsh migrate-setmaxdowntime VMNAME 2500


Check migration status

virsh domjobinfo instance-000002ac
Job type: Unbounded
Operation: Outgoing migration
Time elapsed: 1307956 ms
Data processed: 118.662 GiB
Data remaining: 9.203 MiB
Data total: 8.005 GiB
Memory processed: 118.662 GiB
Memory remaining: 9.203 MiB
Memory total: 8.005 GiB
Memory bandwidth: 41.294 MiB/s
Dirty rate: 35040 pages/s
Page size: 4096 bytes
Iteration: 197
Constant pages: 1751031
Normal pages: 31041965
Normal data: 118.416 GiB
Expected downtime: 3314 ms
Setup time: 70 ms






Bonding in active-backup using linux bridges on Ubuntu 18

Because this was WAAYY more difficult to find any decent doco on that I had ever expected, here is what worked for me

I deleted the netplan config file at /etc/netplan/01-netcfg.yaml

rm /etc/netplan/01-netcfg.yaml

Ensure that ‘bonding’ appears in /etc/modules (I’s not here by default)

echo bonding >> /etc/modules


Here is /etc/network/interfaces

source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback

allow-hotplug ens3f0
iface ens3f0 inet manual
bond-master bond0

allow-hotplug ens3f1
iface ens3f1 inet manual
bond-master bond0

allow-hotplug bond0
iface bond0 inet static
mtu 9000

bond-mode active-backup
bond-miimon 100
bond-slaves none


error on subcontainer ‘ia_addr’ insert (-1)

If you use SNMP on Ubuntu you might see this annoying log entry repeat itself in syslog
Sep 15 17:29:34 myServer snmpd[3609]: error on subcontainer 'ia_addr' insert (-1)
Easy fix is
sed -i 's/Lsd/LS6d/g' /etc/default/snmpd
service snmpd restart

Linux static routes & fixing “Error: either “to” is duplicate, or gw is a garbage.”

I was having troubles adding a route using ip route, I was getting “Error: either “to” is duplicate, or “” is a garbage.”

[root@adlwest-nms1 ~]# ip route add dev eth1
Error: either "to" is duplicate, or "" is a garbage.

But running ip route add subnet/netmask via gw worked

[root@adlwest-nms1 ~]# ip route add via
[root@adlwest-nms1 ~]# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=62 time=1.04 ms
64 bytes from icmp_seq=2 ttl=62 time=0.992 ms

HPACUCLI – Mapping a disk to a linux mount point /dev/sdx

Found this little nugget by accident but here is the command to use hpacucli on linux to determine which logical disk is mapped to which mount point

[root@ceph1 ~]# /usr/sbin/uname26 hpacucli controller slot=2 ld 3 show

Smart Array P410 in Slot 2

array C

Logical Drive: 3
 Size: 3.6 TB
 Fault Tolerance: 0
 Heads: 255
 Sectors Per Track: 32
 Cylinders: 65535
 Strip Size: 256 KB
 Full Stripe Size: 256 KB
 Status: OK
 Caching: Enabled
 Unique Identifier: 600508B1001C953FDF746410876C6824
 Disk Name: /dev/sdb
 Mount Points: /var/lib/ceph/osd/ceph-58 3.6 TB
 OS Status: LOCKED
 Logical Drive Label: A9874C30PACCRID105108LP4D16
 Drive Type: Data

[root@adlwest-ceph70 ~]# /usr/sbin/uname26 hpacucli controller slot=2 ld 4 show

Smart Array P410 in Slot 2

array D

Logical Drive: 4
 Size: 3.6 TB
 Fault Tolerance: 0
 Heads: 255
 Sectors Per Track: 32
 Cylinders: 65535
 Strip Size: 256 KB
 Full Stripe Size: 256 KB
 Status: Failed
 Caching: Enabled
 Unique Identifier: 600508B1001C9435EB0B8689EAB537B1
 Mount Points: None
 Logical Drive Label: A9875C36PACCRID105108LP839F
 Drive Type: Data