Expanding an AWS Linux Partition

A couple of days ago, I went through the steps of enlarging my AWS instance volume as well as switching over from magnetic drives to SSD. I thought everything would just work magically when I restarted the instance but instead found that the file system did not recognize the change in disk size. I should not have assumed that the VM would know how I want to use the extra disk space.

The following shell output details the steps required to expand the Linux file system after increasing the instance volume size.

[ec2-user@service ~]$ df -h # check the filesystem
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       14G  5.6G  8.4G  40% /
tmpfs                 3.6G     0  3.6G   0% /dev/shm
/dev/xvda1            485M   54M  407M  12% /boot

[ec2-user@service ~]$ lsblk # observe how the disk, partition, and lvm is laid out
NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda                        202:0    0   30G  0 disk 
├─xvda1                     202:1    0  500M  0 part /boot
└─xvda2                     202:2    0 15.5G  0 part 
  ├─VolGroup-lv_root (dm-0) 253:0    0 13.9G  0 lvm  /
  └─VolGroup-lv_swap (dm-1) 253:1    0  1.6G  0 lvm  [SWAP]

[ec2-user@service ~]$ sudo parted /dev/xvda # use parted to expand the second partition
GNU Parted 2.1
Using /dev/xvda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s                                                           
(parted) print                                                            
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 62914560s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start     End        Size       Type     File system  Flags
 1      2048s     1026047s   1024000s   primary  ext4         boot
 2      1026048s  33554431s  32528384s  primary               lvm

(parted) rm 2                                                             
Warning: WARNING: the kernel failed to re-read the partition table on /dev/xvda (Device or resource busy).  As a result, it may not
reflect all of your changes until after reboot.
(parted) mkpart primary 1026048s 100%                                     
Warning: WARNING: the kernel failed to re-read the partition table on /dev/xvda (Device or resource busy).  As a result, it may not
reflect all of your changes until after reboot.
(parted) print                                                            
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 62914560s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start     End        Size       Type     File system  Flags
 1      2048s     1026047s   1024000s   primary  ext4         boot
 2      1026048s  62914559s  61888512s  primary

(parted) quit                                                             
Information: You may need to update /etc/fstab.                           

[ec2-user@service ~]$ lsblk # observe that no changes until reboot
NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda                        202:0    0   30G  0 disk 
├─xvda1                     202:1    0  500M  0 part /boot
└─xvda2                     202:2    0 15.5G  0 part 
  ├─VolGroup-lv_root (dm-0) 253:0    0 13.9G  0 lvm  /
  └─VolGroup-lv_swap (dm-1) 253:1    0  1.6G  0 lvm  [SWAP]

[ec2-user@service ~]$ sudo reboot now

[ec2-user@service ~]$ sudo pvresize /dev/xvda2 # resize the physical volume to occupy the full partition

[ec2-user@service ~]$ sudo lvextend /dev/mapper/VolGroup-lv_root /dev/xvda2 # resize the logical volume to occupy the full physical volume

[ec2-user@service ~]$ sudo resize2fs /dev/mapper/VolGroup-lv_root # resize the file system to occupy the full logical volume

[ec2-user@service ~]$ lsblk # observe that the lvm resize has taken place
NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda                        202:0    0   30G  0 disk 
├─xvda1                     202:1    0  500M  0 part /boot
└─xvda2                     202:2    0 29.5G  0 part 
  ├─VolGroup-lv_root (dm-0) 253:0    0 27.9G  0 lvm  /
  └─VolGroup-lv_swap (dm-1) 253:1    0  1.6G  0 lvm  [SWAP]

[ec2-user@service ~]$ df -h # confirm that the file system has the new disk availability
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       28G  5.6G   21G  22% /
tmpfs                 7.3G     0  7.3G   0% /dev/shm
/dev/xvda1            485M   54M  407M  12% /boot

Homebrew Calculator

I created a table for reference and calculating typical homebrew mashing. Find it on the side bar. (pun intended)

Getting Tomcat manager working for a multi-instance Tomcat on localhost

All day I had the pleasure of trying to get the Tomcat manager gui working on local instanced Tomcat. Manager had always loaded up fine when I ran Tomcat as a single server on my local machine. Today, I had a need to run multiple instances of Tomcat on my local computer and there are several resources that discuss the process1. However, I kept running into an issue where the manager for the instanced server wouldn’t work. The username/password prompt would show up but it would not accept the username/password that I had configured in the tomcat-users.xml file; it would just re-prompt me resulting in 401/403 html errors. Finally, I found a post2 that discussed a solution to the problem, though doesn’t go into the explanation of why this is the solution.

The solution is as follows:

In the server.xml under the Engine context add:

<Realm className="org.apache.catalina.realm.MemoryRealm" />

According to the Tomcat resource3:

The purpose of the MemoryRealm implementation is to provide a mechanism by which Tomcat can acquire information needed to authenticate web application users, and define their security roles, from a simple text-based configuration file in XML format. This is intended to simplify the initial installation and operation of Tomcat, without the complexity of configuring a database or directory server based Realm. It is not intended for production use.

With that in mind, I still don’t know why it was unnecessary for the single instance Tomcat setup I had earlier…

Git rebase sucks

Git was being a real pain in the ass today. I’m not the biggest fan of git rebasing, but I understand that some teams prefer to use it to keep the code history clean. Today’s problem arose from canceling a pull request, then requiring new changes to be made on my feature branch while the master branch had ongoing development. By the time I had made my new changes and tried to rebase with master, I was experiencing a butt load of merge conflicts that I just didn’t want to deal with.

So the steps that lead to my problem was as follows:

  1. create feature branch
  2. write code in feature branch
  3. rebase with master
  4. commit and push feature branch
  5. create pull request
  6. decline pull request
  7. write code in feature branch
  8. team member simultaneously updated master
  9. rebase with master

I was trying to rebase with master because my team practices rebasing with master before performing pull requests. However, that last rebase really screwed things up for me as far as merge conflicts go. My solution to preventing all of that headache is as follows. Rather than performing a vanilla rebase with master that second time, perform git rebase --onto master. This changes the starting point at which to create new commits. Basically it changes your feature branch to look just like master. At this point if you perform git status you will see that your local branch and the remote branch have diverged commits. Now you can simply perform git pull to play the remote branch commits on top of your local branch. Now perform any necessary code changes as required before then commit and push. Last step is to drink a beer because PHEW that was hard work!

To summarize, if you think you need to rebase your feature branch with master, but you feel like you may run into a merge headache try: git rebase --onto master && git pull

:)

Problem installing Protobuf 2.3.0 on Mac

Installing the 2.3.0 version of google protobuf using homebrew was being problematic. I ended up trying instead to make it manually using the source from google but ran into the same troubles. The solution1 never made its way to the homebrew repo, I guess, or google’s archive.

// replace the following in protobuf-2.3.0/src/google/protobuf/message.h

#ifdef __DECCXX
// HP C++'s iosfwd doesn't work.
#include 
#else
#include 
//#include 
#endif