Creating a Disk Image of a Hard Drive

This one is really useful if you want to take a quick backup of an entire hard drive. 💻

root@server.server.com:~# dd if=/dev/sda of=/backup/hdadisk.img

Of course make sure you input the correct if and of values where if is the source drive and of is the output file. 👍 Enjoy!

Reading and Writing to an HFS+ Disk in Linux

This past week I had to take a backup of one of my servers, but the only drive I had laying around with HFS+ formatted (Mac OSX). After fiddling around in Knoppix and going through a bunch of Google search results, I think I finally found the right combination of tools and commands to get the HFS+ formatted drive to show up under Knoppix as both read and write.

First, you'll want to make sure you get hfsprogs installed. As mentioned, I was in a Knoppix live environment, so using the following command worked for me:

root@Microknoppix:/# apt-get install hfsprogs

Now with this utility installed you should be able to mount your drive:

root@Microknoppix:/# mkdir /mnt/drive
root@Microknoppix:/# mount -t hfsplus -o force,rw /dev/sdXY /media/mntpoint
root@Microknoppix:/# cd /mnt/drive

Now it may also be possible to use this command if you previously tried mounting the drive without having hfsprogs installed. Without hfsprogs it can likely still mount the drive but it will be mounted as read-only.

root@Microknoppix:/# mkdir /mnt/drive
root@Microknoppix:/# mount -t hfsplus -o remount,force,rw /mount/point
root@Microknoppix:/# cd /mnt/drive

In any event, your HFS+ drive should now be mounted as read and write! 👍

Resources:

Installing Your Own Reddit Server

Reddit is apparently a pretty popular website. So how about having your own Reddit website?! Not only can you create your own subreddits but you can be the administrator of the whole entire thing. Cool!!

Head on over to the reddit GitHub page and visit this wiki page in particular. You mostly just need to follow the directions provided here, however there's a couple extra things I would like to add in.

Firstly, it's really important you follow their direction on the Linux distribution to use, Ubuntu 12.04. I'll go ahead and give another shoutout to my favorite DigitalOcean since they're so easy to get setup and running.

Once you've gotten your Ubuntu instance going login as the root user. Next install screen and less. These aren't necessary but I find that they're useful tools. It's possible they may already been installed.

root@reddit:~# apt-get install screen less

Next add a new user account. This account is where Reddit will be installed too.

root@reddit:~# adduser reddit

You'll likely get prompted to input a password and possible some extra information about the user. I usually just input the new password and hit Enter for the remaining questions (such as first name, last name, etc...).

Now let's add that user to the sudoers file.

root@reddit:~# nano /etc/sudoers

Now, this may not be 100% sure or the 100% proper way to do this as this basically provides your user complete root access but it will ensure that Reddit installs itself correctly. That said, add this line to the above file.

reddit ALL=(ALL) ALL

Save your changes. Now grab a copy of the Ubuntu Reddit installer script and set execute permissions on it. You'll want to do this as the reddit user (assuming your non-root account is named reddit - mine is).

reddit@reddit:~$ wget https://raw.github.com/reddit/reddit/master/install-reddit.sh
reddit@reddit:~$ chmod +x install-reddit.sh

Now, as recommended by the official wiki article, you may want to review and check through the script. If you feel so inclined:

reddit@reddit:~$ less install-reddit.sh

Alright, hopefully that was a fun read. Let's install it! 😄 Fortunately this is probably the most easy part, assuming nothing errors out.

reddit@reddit:~$ REDDIT_DOMAIN=yourdomain.com ./install-reddit.sh

The install shouldn't take very long, I believe it took 10 minutes at most on my little VPS instance. If all ended well, you'll see some nice output about what URL to use to visit your instance as well as some information on how you can populate your Reddit install with some demo data.

All done! 👍

Resources:

Install GitBucket w/ Nginx

I previously wrote an article to get GitBucket working with Heroku which was awesome for testing purposes, however if you actually plan on using GitBucket, you probably want an environment that saves your data and users! Fear not, it's easier then I thought. Follow this guide to get GitBucket working in a production-like environment.

Install Your Server

I used CentOS 6 x86_64 for my server. I just got it running in a VPS environment. You can use DigitalOcean, it's nice and cheap and super easy to use.

Install Java

Next you'll want to make sure Java is installed. This is quite simple as well.

cd /opt/
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/7u60-b19/jdk-7u60-linux-i586.tar.gz"

This will download Java for you. Next let's unpack the archive.

tar zxvf jdk-7u60-linux-i586.tar.gz

Next, we'll use Alternatives to get Java installed to your system.

cd /opt/jdk1.7.0_60/
alternatives --install /usr/bin/java java /opt/jdk1.7.0_60/bin/java 2
alternatives --config java

You should get the output of something like:

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /opt/jdk1.7.0_60/bin/java

Just hit the 'Enter' key at the prompt and it'll proceed with your installation. If all went well Java should be installed:

[root@git jdk1.7.0_60]# java -version
java version "1.7.0_60"

You'll also want to setup some environment variables:

export JAVA_HOME=/opt/jdk1.7.0_60
export JRE_HOME=/opt/jdk1.7.0_60/jre
export PATH=$PATH:/opt/jdk1.7.0_60/bin:/opt/jdk1.7.0_60/jre/bin

That completes the installation of Java onto your system.

Install GitBucket

Next grab a copy of the latest release of GitBucket. The version as of writing was 2.0.

cd /opt
mkdir gitbucket
cd gitbucket/
wget https://github.com/takezoe/gitbucket/releases/download/2.0/gitbucket.war

That's pretty much all we'll do with it for now. We'll come back to the war file in a bit.

Install Nginx

Since I prefer to not have :8080 in my URLs and I like Nginx, I'll install it as a front-end proxy to GitBucket. It's really easy!

cd /usr/src
wget http://nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
rpm -ivh nginx-release-rhel-6-0.el6.ngx.noarch.rpm
yum install nginx

If all went well you should see something like:

Installing : nginx-1.6.0-1.el6.ngx.x86_64                                                                                                                                                                   1/1 
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
  Verifying  : nginx-1.6.0-1.el6.ngx.x86_64                                                                                                                                                                   1/1 

Installed:
  nginx.x86_64 0:1.6.0-1.el6.ngx                                                                                                                                                                                  

Complete!

Now, we'll need to add a configuration file for your GitBucket install. Navigate to the /etc/nginx/conf.d folder and create a file named gitbucket.conf:

nano gitbucket.conf

Simple! Now add the following into the file:

server {
        listen   80; # The default is 80 but this here if you want to change it.
        server_name gitbucket.example.com;

  location / {
    proxy_pass              http://localhost:8080;
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_connect_timeout   150;
    proxy_send_timeout      100;
    proxy_read_timeout      100;
    proxy_buffers           4 32k;
    client_max_body_size    500m; # Big number is we can post big commits.
    client_body_buffer_size 128k;

  }
}

Remember to change the server_name setting to your URL. In my case I did:

server_name gitneko.com;

Also, you may want to set Nginx to start up on boot.

chkconfig nginx on

Running GitBucket

You're on the final stretch! Open a new screen (you may need to install screen if it's not installed already).

screen
cd /opt/gitbucket
java -jar gitbucket.war

This will start up GitBucket. Once it's started up hit Ctrl+A, Ctrl+D to get out of screen. Now we're going to start up Nginx.

/etc/init.d/nginx restart

Don't worry if you see something like:

[root@git conf.d]# /etc/init.d/nginx restart
Stopping nginx:                                            [FAILED]
Starting nginx:                                            [  OK  ]

It only failed to stop because it wasn't running. You could even just start instead of restart...

At this point you should be able to visit http://yourdomain.com and you'll see your GitBucket instance running! Done and done!

Updating GitBucket

Thankfully the developers of GitBucket have made it extremely easy to upgrade GitBucket. You simply need to download the new .war file and replace your current one with it. I then recommend restarting Nginx as well for good measure.

Resources