Sujith's Blog

How to increase the storage of a Virtual Machine by resizing Logical Volume

Increasing the partition/storage of a linux Virtual-Machine instance is done in three steps.

Resize the Virtual Disk

Power off the virtual machine and then, increase the virtual disk/storage size from the virtual machine settings. By increasing storage space here, the OS is not going to use/detect this. For that we have resize the partition using Disk partition manager (Gparted here).

Get Gparted and resize the partition.

For gparted, we can either use Gparted.iso or any of ubuntu live CD. I’m using a bootable USB stick with Ubuntu live CD iso.

For choosing/changing the boot order/device for virtual instance, We have to increase the boot delay in Options -> Boot options -> Power on Boot Delay. This will allow us to see the boot screen for the specified no. of milliseconds.

In Gparetd first resize the extended partition, then resize the LVM.

Resize the LVM Volume.

For resizing the LVM, first resize the Physical Volume.

$ sudo pvs

PV         VG              Fmt  Attr PSize   PFree
  /dev/sda5  ubuntuServer-vg lvm2 a--  99.76g 9.16g

$ sudo pvresize /dev/sda5

Physical volume "/dev/sda5" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

Next extend the Logical volume to the full size of PV(Physical Volume).

$ sudo lvdisplay

  --- Logical volume ---
  LV Path                /dev/PA-server-vg/root
  LV Name                root
  VG Name                PA-server-vg
  LV UUID                fwuhJl-mvBY-xDgv-ihmF-CCDH-U2kX-EZ7tMV
  LV Write Access        read/write
  LV Creation host, time PA-server, 2014-10-17 19:31:06 +0530
  LV Status              available
  # open                 1
  LV Size                31.76 GiB
  Current LE             8130
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Path                /dev/PA-server-vg/swap_1
  LV Name                swap_1
  VG Name                PA-server-vg
  LV UUID                Xqk8xg-mVYW-zgpc-FYPz-MSpd-0bIr-Kqgnxq
  LV Write Access        read/write
  LV Creation host, time PA-server, 2014-10-17 19:31:06 +0530
  LV Status              available
  # open                 0
  LV Size                8.00 GiB
  Current LE             2048
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

Take the LV Path of the volume to be extended(root, here /dev/PA-server-vg/root ), now we can resize it to the available 100% using lvextend.

$ lvextend -l+100%FREE /dev/PA-server-vg/root

Now the last step is to extend the file-system on the volume.

$ resize2fs /dev/PA-server-vg/root

Now check the with df -h, we have resized the disk/storage of the VM.

How to mount windows network shared folder to ubuntu.

For mounting windows shares in ubuntu using cifs-utils. Install cifs utils sudo apt-get install cifs-utils.

for mounting use this command:


$ sudo mount -t cifs //<windows-ip>/<path-to-shared-folder>/ /path/to/ubunut-mount-point/ -o username=<username>,password=<password>,uid=1000,gid=1000

eg:
$ sudo mount -t cifs //192.168.1.202/sample/ /mnt/shared/ -o username=bob,password=123456,uid=1000,gid=1000

How to enable password authentication in MongoDB 3.x

Create one admin user in the special db admin like this:


  $ mongo
  > use admin
  > db.createUser({user:"root-username",pwd:"root-password", roles:[{role:"root",db:"admin"}]})
  > exit

Now open /ect/mongod.conf in your favorite text editor and enable authentication by adding this to it:


security:
   authorization: enabled

Now restart your mongodb sudo service mongod restart.

Why we moved from Bitbucket to Github.

Anyone who has used or is using git, must have heard about Bitbucket and Github, two git repository hosting services. We were using Bitbucket for the last 2 years. But last week we switched to Github. Here is the reasons why we switched to Github:

  1. Issue Tagging

    When we start developing an application, issues can pile up. This is where the tagging feature helps. Unfortunately Bitbucket lacks this feature. But we can adjust with the Module/Milestone feature. Still Bitbucket won’t allow us to keep one issue in more than one module/milestone. This is where Github works well, We can attach any number of tags(coloured) to an Issue. Github also provides a very good option to cross-reference issues, pull-requests, and commits.

  2. Milestones

    Github’s milestone makes sense. It has an option to set due date, move Issues to milestone. And shows the progress of the milestone graphically. Wherein Bitbucket just provides an extra column in the issue tracker.

  3. Visualizations

    Github provides very nice visualisations about what is happening in our team/project. This part is completely missing in Bitbucket. It has got an activity feed which is not that useful. Github’s contributions graph, streak, contributors, punchcard are all kind of motivating/gamifying. See some of the screenshots:

contributors

streak

How to set syntax highlighting and color scheme in vim

Whenever a git merge occurs in any of my repo, Vim opens up for editing commit message. Initially even getting out of Vim was very difficult for me. I was about to change my default editor in git configs. Then I thought of learning how to use Vim, because it will be very useful, when editing files in remote-server using ssh. Yesterday I learned How to set the syntax highlighting and color scheme in Vim.

For enabling syntax highlighting and line numbers, add the following lines to the ~/.vimrc file, create it if not present.

syntax on
set nu

Now for adding color scheme, you have to download any of the color schemes like distinguished for Vim. Now extract it and move *.vim files in colors directory to ~/.vim/colors/.

  $ mv ~/Downloads/vim-distinguished/colors/*.vim ~/.vim/colors/

Now add the following line to the ~/.vimrc file

colorscheme distinguished

I assume that syntax on is already there in it.