How to setup NFS Server

NFS (Network File System) allows you to ‘share’ a directory located on one networked computer with other computers/devices on that network.
NFS is perfect for creating NAS (Networked Attached Storage) in Linux/Unix environment. For more information visit, SettingUpNFSHowTo

Setup NFS Server :
The computer where directory located is called the server.
In following code we are installing ‘nfs-kernel-server’, creating share directory, setting up permissions, adding directory path to exports to share with client with necessary permission.

#sudo apt-get update
#sudo apt-get install nfs-kernel-server
#sudo mkdir /nfssharedir -p
#sudo chown nobody:nogroup /nfssharedir
#sudo vim /etc/exports
#sudo service nfs-kernel-server restart

‘all_squash’, ‘anonuid’ and ‘anongid’ permission will squash all incoming client read/write request to mentioned uid and gid. You need to make sure server has user with 1000 as uid and gid.

Setup NFS Client :
Computers or devices connecting to that server are called clients. Clients usually ‘mount’ the shared directory to make it a part of their own directory structure.
In following code we are installing ‘nfs-common’, creating share directory, mounting it to server’s shared directory path. We are also adding entry to fstab so it will be persisted after restart.

#sudo apt-get update
#sudo apt-get install nfs-common
#sudo mkdir /nfssharedir -p
#sudo mount /nfssharedir
#sudo vim /etc/fstab
#### NFS #### /nfssharedir nfs auto 0 0

More options for mount can be found here at, Fstab

Above is a basic setup. There are more security related permissions and setting which can be found at, SettingUpNFSHowTo

Hope you like this post.
Thanks you.

Posted in Hardware and Networking, IDE, Uncategorized | Tagged , | Leave a comment

Block ip address using iptables

How to block ip address using iptables

Some times we need to block ip address of spammer using iptables when Akismet plugin and recaptcha sometimes doesn’t work for manual spamming.

Following example shows how to filter IN and OUT traffic to server from spammer IPs.

1) Create list of IPs “list.txt”.

# IP list

2) Create bash script “” to add rules to iptables for blocking IPs in “list.txt”. Make it executable.

iptables -S
IPAdd=$(grep -Ev "^#" $BLOCKDB)
for i in $IPAdd
iptables -A INPUT -s $i -j DROP
iptables -A OUTPUT -d $i -j DROP
echo "DONE"
service iptables-persistent save
service iptables-persistent reload
iptables -S

3) Create bash script “” to add rules to iptables for unblocking IPs in “list.txt”. Make it executable.

iptables -S
IPAdd=$(grep -Ev "^#" $BLOCKDB)
for i in $IPAdd
iptables -D INPUT -s $i -j DROP
iptables -D OUTPUT -d $i -j DROP
echo "DONE"
service iptables-persistent save
service iptables-persistent reload
iptables -S

4) Above scripts works for Unbuntu 16.04. Make necessary changes for saving iptables as per your OS.

5) To block IPs in “list.txt” file run “”.

sudo ./

6) To block IPs in “list.txt” file run “”.

sudo ./

7) If you want more options use ready made tool like fail2ban

NOTE: Adding firewall rules to iptables is very sensitive. Any wrong rule can block all traffic to servers.


Posted in Hardware and Networking, Protocals, Proxy, Shell Script | Tagged , | Leave a comment

How to create ext4 partition from the command-line

How to create ext4 partition from the command-line

These commands are destructive. Have backups and be careful using them.

To quickly set up a drive up as a single ext4 partition…

1) View detected devices of class “DISK”

#sudo lshw -C disk

2) View existing partition table(s)

#sudo fdisk -l
#ls -hal /dev/disk/by-uuid/

3) Collect Linux Block Device Information

#lsblk -l;
#lsblk --fs --ascii

4) Edit the partition table for my chosen device (in this case, “sdx”)

#fdisk /dev/sdx

Within FDISK, press:

d …to delete the current partition

n …to create a new partition

p …to specify it as a PRIMARY partition

1 …to set it as the 1ST primary partition

ENTER(default) …First sector

ENTER(default) …Last sector

w …to write the changes.


#sudo fdisk /dev/sdx

Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-488327039, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-488327039, default 488327039):

Created a new partition 1 of type 'Linux' and of size 232.9 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Synching disks.

5) Display the new partition table:

#fdisk -l

6) Format the new partition’s filesystem as type ext4

#sudo mkfs.ext4 /dev/sdx1
#sudo mkfs -t ext4 /dev/sdx1

7) Create a new directory where the new drive will mount into,

mkdir -p /storage
mount /dev/sdx1 /storage

9) Mount at boot up using /etc/fstab.

#sudo vim /etc/fstab

Find (or add) the relevant line in fstab for your drive. Parameters in fstab are separated by white space, for example the drive described above might appear as:
- The first parameter identifies the partition (either by /dev/ or a long UUID);
- The second parameter is the path the partition will be mounted to;
- Third is the filesystem type;
- The fourth parameter contains the options;
- Fifth is the dump schedule for backups; and,
- The sixth parameter is pass-number (used to control fsck order).

Add UUID entry of new partition to fstab. Update Options according to your need,

UUID=c2a8f7f4-7dba-4a51-85bb-0c4d9da56274 /mnt/ssd/ ext4 rw,noatime 0 0

Reboot to check that everything went well.

Posted in Hardware and Networking | Tagged | Leave a comment

Linux command to check server configuration and hardware information

Linux command to check server configuration and hardware information,

1. How to View Linux System Information
#uname -a
#lsb_release -a

2. How to View Linux System Hardware Information
#cat /proc/cpuinfo
#cat /proc/meminfo
#cat /proc/version
#lshw -short
#lshw -short -C memory
#lshw -html > lshw.html

3. How to View Linux CPU Information

4. How to Collect Linux Block Device Information
#lsblk -a

5. How to Print USB Controllers Information
#lsusb -v

6. How to Print PCI Devices Information
#lspci -t
#lspci -v

7. How to Print SCSI Devices Information
#lsscsi -s

8. How to Print Information about SATA Devices
#hdparm /dev/sda1
#hdparm -g /dev/sda1

9. How to Print Linux File System Information
#fdisk -l

10. How to Extract Information about Hardware Components
#dmidecode | less
#dmidecode -t memory
#dmidecode -t system
#dmidecode -t bios
#dmidecode -t processor

11. Display information about hardware RAID

See info about Adaptec hardware RAID:
#arcconf getconfig DEV
#/usr/StorMan/arcconf getconfig 1

See info about 3ware hardware RAID:
#tw_cli /dev show
#tw_cli /c0 show

Hope you find it useful. Thank you.

Posted in Hardware and Networking | Tagged | Leave a comment

Setting up Galera notification command on on Ubuntu

Galera Cluster:

Galera Cluster is a synchronous multi-master database cluster, based on synchronous replication and Oracle’s MySQL/InnoDB. When Galera Cluster is in use, you can direct reads and writes to any node, and you can lose any individual node without interruption in operations and without the need to handle complex failover procedures.

At a high level, Galera Cluster consists of a database server—that is, MySQL or MariaDB—that then uses the Galera Replication Plugin to manage replication.

Setting up Galera notification command:

While you can use the database client to check the status of your cluster, the individual nodes and the health of replication, you may find it counterproductive to log into the client on each node to run these checks. Galera Cluster provides a notification script and interface for customization, allowing you to automate the monitoring process for your cluster.

More details can be found here,

Default script is implemented in Mysql which is not feasible. Because, when whole cluster is down you won’t be able to connect any node in cluster to get details about current status.
Hence, it is good idea to lot cluster status to some other data source.

Here we will be logging all status updates to MongoDb. Let’s create script,


#!/bin/sh -eu


mongo --host $MONGO_HOST $MONGO_DB --eval 'db.'$MONGO_COL'.insert({"_id" : "members", "members" : "'$MEMBERS'" });';

local idx=0

for NODE in $(echo $MEMBERS | sed s/,/\ /g)
idx=$(( $idx + 1 ))

mongo --host $MONGO_HOST $MONGO_DB --eval 'db.'$MONGO_COL'.insert({"_id" : "'$NODE_NAME'", "size" : "'$idx'", "status" : "'$STATUS'", "primary" : "'$PRIMARY'" });'

mongo --host $MONGO_HOST $MONGO_DB --eval 'db.'$MONGO_COL'.update({"_id":"'$NODE_NAME'"},{$set:{"status":"'$STATUS'"}});';

COM=status_update # not a configuration change by default

while [ $# -gt 0 ]
case $1 in
[ "$2" = "yes" ] && PRIMARY="1" || PRIMARY="0"

# Undefined means node is shutting down
if [ "$STATUS" != "Undefined" ]

exit 0

You can update mysql node host name and Mongodb parameters.
NOTE: You will need to setup above script on each node in cluster.

Now, let’s set script as notification command in cluster setting,

sudo mv /etc/mysql/conf.d
sudo chown mysql:mysql /etc/mysql/conf.d/
sudo chmod 700 /etc/mysql/conf.d/

sudo vim /etc/mysql/conf.d/cluster.cnf

Add wsrep option,

Now restart nodes one by one and you will start getting data into mongo collections.

Now you will need monitoring script to check this data for cluster status and alert dev-ops in case if anything is wrong. (e.g. split brain and no node is part of primary component)



import pymongo
import pprint

from pymongo import MongoClient
client = MongoClient('', 27017)
db = client.galera_log_db
col = db.galera_log_coll
for doc in col.find():
except Exception as e:


Above script is just printing rows. You can implement your customized logic.


Posted in MariaDb, Uncategorized | Tagged | Leave a comment

Setting up Galera Arbitrator on Ubuntu

Galera Arbitrator:

The recommended deployment of Galera Cluster is that you use a minimum of three instances. Three nodes, three datacenters and so on.

In the event that the expense of adding resources, such as a third datacenter, is too costly, you can use Galera Arbitrator. Galera Arbitrator is a member of the cluster that participates in voting, but not in the actual replication.

More details can here,

Setting up Galera Arbitrator :

Suppose you already have 2 nodes,

and you want to add arbitrator for cluster failover on new node Then,

Create config file,
vim /etc/default/garb.arbtirator.config

group = cluster_name
address = gcomm://,,
log = /var/logs/garbd.log

create log file,
sudo touch /var/logs/garbd.log
sudo chmod 777 /var/logs/garbd.log

Start garbd,
garbd -d -c /etc/default/garb.arbtirator.config

Now you can see ne wcluster count using mariadb status variable “%wsrep_%”.


Posted in Architecture | Tagged , | Leave a comment

How to setup Apache Thrift on Ubuntu

How to setup Apache Thrift on Ubuntu:

The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.
Mode details can be found here, Apache Thrift

Basic requirements:
$sudo apt-get install automake bison flex g++ git libboost1.58-all-dev libevent-dev libssl-dev libtool make pkg-config
Any java,
$sudo apt-get install ant
$sudo apt-get install python-all python-all-dev python-all-dbg
$sudo apt-get install php7.0-dev php7.0-cli phpunit

Download Apache Thrift :

$tar -xvf thrift-0.10.0.tar.gz

Build and Install the Apache Thrift compiler:

$cd thrift-0.10.0/
$sudo make
$sudo make check
$sudo make install
$thrift -version

if got following error,
thrift: error while loading shared libraries: cannot open shared object file: No such file or directory

$vim ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/lib/:${LD_LIBRARY_PATH}
$source ~/.bashrc
$thrift -version

Above setup also generates source code for given language using thrift files as follows. You don’t need to generate them yourself for examples,

$cd thrift-0.10.0/tutorial/java/
$../../compiler/java/thrift -r --gen java ../../tutorial/tutorial.thrift

Test examples:
Now, client-server source code is ready to run. You can run them using following java commands.

$cd thrift-0.10.0/tutorial/java/
$make tutorial
$make tutorialserver
$make tutorialclient
java -cp ../../lib/java/build/*:../../lib/java/build/lib/*:tutorial.jar JavaServer
java -cp ../../lib/java/build/*:../../lib/java/build/lib/*:tutorial.jar JavaClient simple
java -cp ../../lib/java/build/*:../../lib/java/build/lib/*:tutorial.jar JavaClient secure

Posted in Apache Thrift | Tagged | Leave a comment

Best Java tools for profiling

Best Java tools :

Recently, I was building real-time, high performance back-end Java application which computes 16K ratios per company for around 70K companies (~1.1bn total) by pulling data from different data sources like, Mongodb, Cassandra, Mysql and Redis. It was multi-threaded application which was using Dynamic programming approach for storing intermediate results to pass as an input to calculate derived ratios on next layer. Having small setup of average servers which were serving both front-end application and back-end batch processing, It was very important to build solution which has less CPU/IO and memory utilization.
When I tested application the first time, response time for computing one company was 2mnts with 20mb memory usage and it was really not acceptable.
So, I decided to profile code to find duplicate computations to reduce CPU/IO which will improve response time and remove any memory leaks due to strong references. I searched for best tool for profiling java application and came across some amazing tools which help me reduce response time to 4sec and <2Mb memory usage for one company (before GC).


All these tools are as following,

1) VisualVM :

It is free and very handy all-in-One Java troubleshooting visual tool integrating command-line JDK tools and lightweight profiling capabilities. Designed for both development and production time to monitor application locally and remotely. VisualVM comes with default Oracle Hotspot JVM installation which gives you insights of CPU Utilization, Memory Usage, Threads, CPU/Memory sampling/profilling.
You can extend basic functionality adding more plugin for Mbean, Jconsole and Garbage collection. It is possible to take Thead/Heap dump and perform manual GC on running application. It is super set of Jconsole and requires Jstatd for monitoring application remotely.
More details can be found here, VisualVM.


2) Java Mission Control :

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed run-time information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collection framework built into the Oracle JDK. It allows Java administrators and developers to gather detailed low level information about how the Java Virtual Machine (JVM) and the Java application are behaving. Java Mission Control is an advanced set of tools that enables efficient and detailed analysis of the extensive of data collected by Java Flight Recorder.
The tool chain enables developers and administrators to collect and analyze data from Java applications running locally or deployed in production environments.
More details can be found here, Java Mission Control.


Following tools are paid but they gives you very deep insights to pin point issues and save lots of time.

3) JProfiler:

JProfiler is paid all-in-One paid with intuitive UI which helps you resolve performance bottlenecks, pin down memory leaks and understand threading issues.
More details can be found here, JProfiler.


3) Yourkit:

YourKit is paid all-in-one profiler utilizes all of the advanced Java profiling features and capabilities. It profile any SE or EE application, server, technology and framework; on multiple platforms; locally and remotely; in development, testing and production. For teams and companies of any size.
More details can be found here, Yourkit.


I hope, this post will save your precious time on finding best java profiling tools.
Thank you.

Posted in Java | Tagged | Leave a comment

How to setup cassandra on Ubuntu 14.04

What is Cassandra?

The Apache Cassandra database is the right choice when you need scalability and high availability without compromising performance. Linear scalability and proven fault-tolerance on commodity hardware or cloud infrastructure make it the perfect platform for mission-critical data.Cassandra’s support for replicating across multiple datacenters is best-in-class, providing lower latency for your users and the peace of mind of knowing that you can survive regional outages.

Cassandra cluster data flow :


Cassandra architecture:


More information can be found here. Apache Cassandra, Datastax Cassandra Documantation and Users.

Cassandra cluster read/updates:


Install dependencies:-

Java8 :

#sudo apt-get install software-properties-common python-software-properties
#sudo apt-add-repository ppa:webupd8team/java
#sudo apt-get update
#sudo apt-get install oracle-java8-installer

#java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

#python3 --version
Python 3.4.3

Install Cassandra:-

Following steps will install Cassandra and other tools like cqlsh client, noodtool administrative tool.

#echo "deb 36x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
#curl | sudo apt-key add -
#sudo apt-get update
#sudo apt-key adv --keyserver --recv-key A278B781FE4B2BDA
#sudo apt-get install cassandra

#nodetool status
cqlsh> show VERSION
[cqlsh 5.0.1 | Cassandra 3.6 | CQL spec 3.4.2 | Native protocol v4]
cqlsh> SHOW HOST
Connected to Test_Cluster at
cqlsh> SELECT cluster_name, listen_address FROM system.local;
cqlsh> tracing off
cqlsh> paging off
cqlsh> expand off

Setup Cassandra Multi-node Cluster:

Cassandra uses,
storage_port: 7000 for cluster communication (7001 if SSL is enabled),
native_transport_port: 9042 for native protocol clients,
JMX : 7199 for Java tools
rpc_port: 9160 for remote client communication.

Now let’s setup environment for cluster for 3 servers (,,,
Do following steps for all cassandra nodes.

#sudo service cassandra stop

If you nhave SSD, point data dirs for SSDs.

#sudo mkdir -m=777 /mnt/ssd/cassandra
#sudo vim /etc/cassandra/cassandra.yaml

Setup clustor,

cluster_name: 'Stockopedia_Production_Cluster'

Point data dir to SSD,

- /mnt/ssd/cassandra/data
commitlog_directory: /mnt/ssd/cassandra/commitlog
saved_caches_directory: /mnt/ssd/cassandra/saved_caches
hints_directory: /mnt/ssd/cassandra/hints

Add node seeds,

- seeds: ",,"

Update Ip/ports, eth0 :

listen_interface: eth0
start_rpc: true
rpc_interface: eth0

Update snitch for grouping machines into “datacenters” and “racks.”:

endpoint_snitch: GossipingPropertyFileSnitch

#vim /etc/cassandra/

#sudo service cassandra start

Test cassandra environment:

# nodetool status
Datacenter: dc1
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 7.84 GiB 256 100.0% bde625de-8af6-477f-9a69-asdedec0fc62 rack1
Datacenter: dc2
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 7.84 GiB 256 100.0% 162ae9dc-e572-4927-98a4-qwe371c9f071 rack2
Datacenter: dc3
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 7.84 GiB 256 100.0% 162ae9dc-e572-4927-98a4-qwe371sdf071 rack3

Monitoring cassandra servers using VisualVm and Jconsole:

Remote process connection string : service:jmx:rmi://server-ip:7299/jndi/rmi://server-ip:7199/jmxrmi

vim /etc/cassandra/

JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=server-ip"

Cassandra Model:


Import CSV using cqlsh client and upload it to cassandra table:

First export data from mysql database,

mysql>SELECT instrument,IFNULL(open,''),IFNULL(high,''),IFNULL(low,''),IFNULL(close,''),IFNULL(volume,''),IFNULL(date,''),created_at INTO OUTFILE '/tmp/price.csv'
FROM price;
Query OK, 129865916 rows affected (7 min 5.59 sec)

cqlsh> CREATE KEYSPACE price_db WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'dc1' : 1, 'dc2' : 1, 'dc3' : 1 };
cqlsh> USE price;
cqlsh> COPY price_db.price_table (instrument,open,high,low,close,volume,date,created_at) FROM '/tmp/price.csv';

cqlsh> CREATE TABLE price_db.price_table (
instrument varchar,
open decimal,
high decimal,
low decimal,
close decimal,
volume decimal,
date date,
created_at timestamp,
PRIMARY KEY (instrument, date)
) WITH CLUSTERING ORDER BY (date DESC) AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'} ;

cqlsh> CREATE INDEX close ON price_db.price_table (close);
cqlsh> DESCRIBE price_db.price_tabl;
cqlsh> SELECT * FROM price_db.price_tabl;
cqlsh> SELECT close FROM price_db.price_tabl where instrument = 'XYZ';
cqlsh> DROP TABLE price_db.price_tabl;
cqlsh> TRUNCATE TABLE price_db.price_tabl;

Install Cassandra php-driver :

# php --version
PHP 5.5.9-1ubuntu4.20 (cli) (built: Oct 3 2016 13:00:37)

PHP data driver can be found here,

sudo apt-get install g++ clang make cmake libssl-dev libgmp-dev libpcre3-dev git

#sudo wget
#sudo wget
#sudo wget
#sudo wget

#sudo dpkg -i libuv_1.8.0-1_amd64.deb
#sudo dpkg -i libuv-dev_1.8.0-1_amd64.deb
#sudo dpkg -i cassandra-cpp-driver_2.5.0-1_amd64.deb
#sudo dpkg -i cassandra-cpp-driver-dev_2.5.0-1_amd64.deb

#sudo pecl install cassandra

#sudo vim /etc/php5/mods-available/cassandra.ini;
#php5enmod cassandra

We found cassandra is 3x faster that relational mysql for timeseries data. You will need to design data model according to query patterns using de-normalization so that you can pull all needed data using just one query.

Thank you.

Posted in Cassandra, Php, Uncategorized | Tagged | Leave a comment

How to setup a virtual machine

How to setup a virtual machine ?

This post covers how to setup VirtualBox , VMware Workstation, VMware Player and Vagrant applications and how to setup guest operating system.

Here, I’ve selected Windows 10 Home as Host OS and Ubunbu 16.04 LTS Xenial as guest OS.

Let’s first understand some basic terminologies regarding Virtualization.

Virtualization :
Virtualization is the creation of a virtual (rather than actual) version of something, such as an operating system, a server, a storage device or network resources.


Hypervisor :
A hypervisor or virtual machine monitor (VMM) is a piece of computer software, firmware or hardware that creates and runs virtual machines.


A computer on which a hypervisor is running one or more virtual machines is defined as a host machine. Each virtual machine is called a guest machine. The hypervisor presents the guest operating systems with a virtual operating platform and manages the execution of the guest operating systems. Multiple instances of a variety of operating systems may share the virtualized hardware resources.

Type-1, native or bare-metal hypervisors
These hypervisors run directly on the host’s hardware to control the hardware and to manage guest operating systems. For this reason, they are sometimes called bare metal hypervisors.

Type-2 or hosted hypervisors
These hypervisors run on a conventional operating system just as other computer programs do.
A guest operating system runs as a process on the host. Type-2 hypervisors abstract guest operating systems
from the host operating system. VMware Workstation, VMware Player, VirtualBox and QEMU are examples of type-2 hypervisors.


VirtualBox :

VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. It is freely available as Open Source Software under the terms of the GNU General Public License (GPL) version 2.

Presently, VirtualBox runs on Windows, Linux, Macintosh, and Solaris hosts and supports a large number of guest operating systems including but not limited to Windows (NT 4.0, 2000, XP, Server 2003, Vista, Windows 7, Windows 8, Windows 10), DOS/Windows 3.x, Linux (2.4, 2.6, 3.x and 4.x), Solaris and OpenSolaris, OS/2, and OpenBSD.

You can download it from here VirtualBox

There are two options to setup guest OS,
1) You need Ubuntu ISO image to set it up new guest OS machine. It can be downloaded from here ubuntu-16.04-desktop-amd64.iso.
2) You can directly download ready box from osboxs.

I’ve chosen to setup new machine using ISO image.

Installation setups are given on their website which are pretty simple. Installation steps has chosen default setting while allocation size/space to guest OS.
You need to make sure that your guest machine has sufficient space both for application and data which you will keeping on it.

Follow these steps to setup virtual machine,

Virtualbox Setting Up a New Virtual Machine

You can also share folder between Host and guest machine using VirtualBox/SharedFolders and
HOWTO: Use Shared Folders.

If you want to have it mount automatically upon each boot, put the mount command in /etc/rc.local (Debian based distro’s), or whatever script is run at the end of the boot process. The Shared Folders service should mount them automatically, but that doesn’t always happen.
Using /etc/fstab has little effect, because that file is processed before the SF module is loaded and will fail to mount the share. Sometimes, the share does get mounted because the GA check for it when they are loaded upon boot, but it’s very flaky, meaning it doesn’t work most of the time. You’re better of with the first option.
When you put the mount command in /etc/rc.local, so it’s mounted at startup, you can’t use the short notation for your home folder. During startup, everything is done through the root user, so using ~ for home, means it’s the home folder of Root (/root).

Guest Additions setup can be found here, Guest Additions.

Following are important steps for setting up shared folder,

sudo apt-get install build-essential
sudo apt-get install linux-headers-`uname -r`

sudo mkdir /mnt/$sharename
sudo chmod 777 /mnt/$sharename
sudo mount -t vboxsf -o uid=1000,gid=1000 $sharename /mnt/$sharename
ln -s /mnt/$sharename $HOME/Desktop/$sharename

For me, it got mounted on /media/sf_share path for some reason.

If google chrome in guest OS (Ubuntu) is not working properly then Disable 3D-acceleration in guest OS setting on virtual box.

Resize Virtualbox Image :

1) Backup VDI image:

Take a backup of you image by coping ‘.vdi’ file to somewhere else. You may need it to restore your system in case of any data lose.

path_to_folder\VirtualBox VMs\Xenial64\Xenial64.vdi

2) Extent VDI image size:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd "path_to_folder\VirtualBox VMs\Xenial64\Xenial64.vdi" --resize 30000

Above command will extent VDI size of you image but you will still need to allocate that space to guest OS partition manually.

3) Allocate space to partition:

You can resize your existing guest OS parting using gparted.

Download gparted from this link, (Choose correct 32bit/64bit)

Boot your virtual machine using above gparted ISO.

NOTE: If gparted gui not working or you it is getting hanged in between.
Go to VM Setting->Systems and checked the “Enable EFI (special OSes only)” extended feature.

Now you should see gparted GUI.

You can see /dev/sda1, /dev/sda2 (linux-swap) partitions on screen. You can easily resize /dev/sda2 (linux-swap) partition by selecting it, choosing “Resize/Move” and applying using “Apply” button.

But, If you wish to extent /dev/sda1 partition then you will need to delete linux-swap and /dev/sda2 partition. Now It will allow you to resize /dev/sda1 partiontion. Set it whatever size you want. Also keep

some 3-4GB free for linux-swap.

Now, re-add your Linux Swap Space. Press on the unallocated space and right-click to “Created new Partition” -> choosing “Create as: Extended partition” .

Press “+Add” and right-click the new “unallocated” to Create a new partition. Choose as “Create as: Logical Partition” and underneath “File System: linux-swap”.

Now press “+Add” and then “Apply” in the main window. Hopefully all changes are successfully applied.

You can now safely shut down this Live CD Virtual Machine.

You can now check disk space again.

#df -h

VMware Workstation / VMware Player :

VMware virtualizes computing, from the data center to the cloud to mobile devices, to help our customers be more agile, responsive, and profitable.

VMware Workstation and VMware Player transforms the way technical professionals develop, test, demonstrate and deploy software by running multiple x86-based operating systems simultaneously on the same PC.

You can download it from here Vmware

Most of installation steps are identical to for both of them. There are few differences which can be found here on compare page.

Follow these steps to setup virtual machine,

VMware Workstation Setting Up a New Virtual Machine

Here also you will need some shared folder to sync data between Host and Guest machine.

Install vmware-tools as follows,

sudo apt-get install build-essential
sudo apt-get install linux-headers-`uname -r`
cp /cdrom/VM*.gz /tmp/
cd /tmp
tar xvzf VM*.gz
cd vmware-tools*
sudo ./

NOTE : if you got,
The package that need to be removed,

sudo apt-get remove open-vm-tools;

and try running above command again.

Hit enter for all defaults.

Details are given here, Installing VMware tools on an Ubuntu guest

Once it is done, follow steps given as below to setup shared folder,

Create a New Shared Virtual Machine

Now, your shared folder should be ready on following path,

ls /mnt/hgfs/

Vagrant :

Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.

To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can be used to automatically install and configure software on the machine.

You can get it here, Vagrant

To set it up on ubuntu follow this Setup vagrant on ubuntu

You can find ready boxes here, hashicorp.

Now we can just start your virtual machine as follows,

C:\HashiCorp\Vagrant\bin>vagrant init boxcutter/ubuntu1604
C:\HashiCorp\Vagrant\bin>vagrant up --provider virtualbox

If you are using Window as Host OS and Ubuntu Server as guest OS then While setup you will get following details,

Username : ubuntu
PrivateKey : Drive:\HashiCorp\Vagrant\bin\.vagrant\machines\default\virtualbox\private_key

As Window doesn’t has ssh client by default. You will need ssh client like ‘putty’ to ssh to guest OS Ubuntu server.

Putty can be downloaded from here, putty.

Also download PuTTYgen.

- PuTTY – Client to for managing SSH sessions
- PuTTYgen – Tool for managing and creating SSH key pairs

Load Vagrant private key in PuTTYgen, set key passphrase (remember it. Will need later) and click on ‘Save private key’ button to Generate Putty(.ppk) ‘Private’.
Use Putty private key (.ppk) to set it under SSH-Auth section in Putty. You can also set default auth username under Putty Connection-Data section.

Now you should be able to ssh to guest Ubuntu server OS.

You can also setup shared folder on Vagrant. Steps are given here , Shared folder.

Now you can setup as many as guest OS using above applications.


Posted in Virtualization | Tagged , , | Leave a comment