Sunday, 25 October 2015

How To: Automatically cd to a directory after you create it



The majority of the times that I create a directory I would then change to that directory. To make this happen automatically I add the following to my .bashrc :

mkcd () { mkdir -p "$@" && eval cd "\"\$$#\""; }

Example :

$ mkcd ~/tmp/FOO
$ pwd
/home/cw/tmp/FOO

How To: Display your Top 10 cli commands




Its useful to be able to see which command you use most often on a Linux box. I add the following to my .bashrc :

cli-top-10() {
  history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head
}

Example output :

57 ls
49 cd
26 mv
25 curl
18 wget
17 rm
15 sudo
13 packer
12 docker
12 vim

How To: Permanently Display line numbers for Vim or Vi




It can be very useful when troubleshooting to display line numbers in Vim or Vi. To enable this in your ~/.vimrc file add :

:set number

which can also be manually set within Vim or Vi. Within the editor to remove the line numbers :


:set nonumber

Tuesday, 8 September 2015

VirtualBox slow on installation of Guest OS

I use VirtualBox for testing in many environments. Normally the defaults are fine for installing Linux but on one environment it was really slow to just install. Installing Debian Jessie from an ISO would normally take 15 minutes but in this environment after an hour it was still only at 35%. The host OS was not over taxed and has lots of spare CPU + RAM resources free.

After some testing I found the issue was resolved by :

1. Open Settings
2. Navigate to System->Motherboard
3. Change the Chipset to ICH9 (see below)
4. Press OK

Now the installation will be fast.




Monday, 7 September 2015

Change docker default storage location




One of the first tasks I wanted to do after installing Docker on Arch Linux was to be change the default partition storage location. The default location is /var/lib/docker which is the path docker uses as the root of the docker runtime.

Looking at the man pages for docker its not amazingly obvious at first which option needs to be configured but after some research I found it is :

-g, --graph=""

And the service status shows this option is not set by default

$ sudo systemctl status docker
* docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2015-09-07 13:07:10 PDT; 2h 0min ago
     Docs: https://docs.docker.com
 Main PID: 420 (docker)
   CGroup: /system.slice/docker.service
           `-420 /usr/bin/docker daemon -H fd://

Its possible to define --graph within the /usr/lib/systemd/system/docker.service file but this will be overwritten with every new release of docker.

The solution is first create a directory:

$ sudo mkdir /etc/systemd/system/docker.service.d

Then create a file similar to the following

$ cat /etc/systemd/system/docker.service.d/dockerruntimeroot.conf
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --graph /mnt/docker-data


Then

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker


Now the new path will be shown in the service status

$ systemctl status docker
* docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/docker.service.d
           `-dockerruntimeroot.conf
   Active: active (running) since Mon 2015-09-07 15:52:28 PDT; 1min 49s ago
     Docs: https://docs.docker.com
 Main PID: 8981 (docker)
   CGroup: /system.slice/docker.service
           `-8981 /usr/bin/docker daemon -H fd:// --graph /mnt/docker-data