Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

Saturday, 2 November 2013

Setting up a Raspberry Pi as a home server

A lot of people have spoken about the potential uses for a Raspberry Pi, however a lot of these are often very specific to be of use to anybody other than the project creator (using it as part of a home made weather balloon system for example).  When I purchased my Raspberry Pi it was for a specific purpose; the old PC that I used as a home server had given up the ghost and I needed a replacement.  The Raspberry Pi seemed like the ideal answer as it was small and used a lot less electricity (a big plus for a piece of equipment that is going to be on 24/7).

Before we start there are a few things you will need:

  • A Raspberry Pi
  • A computer with internet access 
  • Raspian linux distro
  • An SD Card (4GB minimum)
  • An SD Card reader/slot on your computer
  • External USB hard drive (this will need to be large if you plan to have video and music files on it, I recommend about 2TB minimum)
  • Micro USB charger (my old one from a previous Android phone did the job)
  • A wired USB keyboard
  • An ethernet cable
  • An HDMI cable
  • A monitor/TV with an HDMI connection

1. Firstly we are going to need to install Raspian onto the SD card, for full instructions on how to do this I recommend reading this how to guide. However I kept it simple and used the command line on my Linux system.

Firstly we need to extract the file out of the Zip archive.  Navigate to the place where the downloaded file is and enter the command:
unzip {thefilename}

As these change every time a new version is released the command will alter depending on the image that has been downloaded.

2. Now to get the image onto the SD card.  I needed to use the bs=1M option in the command as the install failed twice with bs=4M, it stated that it would take 'considerably' longer, but the whole process was still fairly quick:
dd bs=1M if={location of raspian.img file} of={location of SD card}

If your not sure what the location of the SD card is then make sure it is removed from the computer and in the command line type:
df -h

Then insert (and mount) the SD card and retype the command:
df -h

There will be an additional item on the list:

In the example above the location of the card is /dev/sdc, we ignore the number as this refers to the partition.

3. Once the process has been complete, unmount the SD card and insert it into the Raspberry Pi.  Connect your keyboard and external hard drive via the USB ports and then connect the Pi to your router and TV before finally giving it power.

4. When you first power up the Raspberry Pi you are asked for some initial settings:


Firstly we'll want to expand_rootfs, this means that we'll be able to use the entire SD card if we ever need to.

We need to know the password, so the next thing we'll do is change the password, to do this simply select change_pass and enter in your new password.

configure_keyboard, change_local and change_timezone allow the user to set the keyboard layout, the location and the local time zone (these are all UK by default).

As this is a server we won't have it connected to a monitor for the majority of
it's life so make sure that we do not start the graphical desktop on boot, boot_behaviour changes this setting.   Although this may look nicer, the Raspberry Pi has limited power and we want this to focus on sharing our files over a server, not looking pretty.

5. To allow us to share our files over a network we will install Samba:  
sudo apt-get install samba

6. To find UUID and the file system of the drive, enter:
sudo blkid

This will give an output similar to the one below:


We can ignore the line that has the TYPE="fat32" as this is the SD Card, take a note of the other line, you need the UUID and the Type, the labels aren't important at this point (depending on the formatting some drives may not have a label)

7.  We need to mount this drive automatically whenever the Raspberry Pi is switched on. Firstly, we'll need to create a location to mount the external hard drive, we can do this by using the command:
sudo mkdir /media/external

Now we need to edit the fstab to tell the Raspberry Pi to automount the external drive every time it is switched on
sudo nano /etc/fstab

Insert the following line at the bottom of the page:
UUID="{the UUID you noted down in step 6}"     /media/external    
{type noted in step 6}     auto,user,rw      0     0

The above should all be on one line, pressing the key to create a gap between each piece of information.

8. Now we need to set up which folders are going to be shared.  I'll assume that we are going to make the whole of the external drive available over the network
nano /etc/samba/smb.conf

at the bottom of the page add the following, note that you can call this anything you wish, just exchange the word external but you must include []
[external]
path = /media/external
available= yes
browsable = yes
public = yes
writable = yes

It's worth noting before we continue that I've set the option writable - yes, this means that you can add to or remove the contents of the external drive over the network.  If you are not comfortable having this option then simply change it to writable = no. Now save and exit (ctrl + X), make sure that you answer 'yes' to save your changes. 

9. We will now set the Raspberry Pi to log in automatically on startup, if the user Pi isn't logged in then all of things we've just set up will not work. Type:
sudo nano /etc/inittab

navigate down to the line:
1:2345:respawn:/sbin/getty --noclear 38400 tty1 

and add --autologin pi after getty to make the line:
1:2345:respawn:/sbin/getty --autologin pi --noclear 38400 tty1

save and exit (ctrl + X) make sure that you answer 'yes' to save it.

10. We're going to need one more piece of information before we finish.  I've had trouble in the past browsing Samba share folders using assigned names rather than IP addresses.  So to find the IP address of the Raspberry Pi type
ifconfig eth0

You'll be given a an output similar to what is shown below:

The part that is circled in orange (inet addr) in the above image is what you need to note down.  We'll need this to test the share drive later on.

11. We can try it out our system and auto-login by using the command
sudo reboot

Assuming that everything goes well, your system should be up and running.

Lets try this out on a different computer or device.

Load up your chosen file manager, most have location bar at the top (similar to the address bar on a browser).  Enter the following in the location bar: smb://{your Raspberry Pi's IP address from step 10}

You should now be able to access the files on the external hard drive connected to your Raspberry Pi.

Congratulations you've now set up your home server.

Saturday, 24 September 2011

Using WeeChat with Freenode (the basics)



I recently tested out WeeChat which is a very fast and lightweight IRC client that is used in the command line.

I must say that I was extremely impressed with the program, but not with the documentation. The quick start wasn't of much help and the user guide was way too heavy and detailed, going into things that were far beyond what I was needing for internet chat.

I'm assuming that the user has already installed the program, if not check the repos or visit http://www.weechat.org for installation details.

Start the program:
weechat-curses
Set your username (dont forget to include the quotation marks"):
/set irc.server.freenode.username "{enter your username here}"


Set your real name (optional):
/set irc.server.freenode.realname "{enter your name here}"


Connect to Freenode:
/connect freenode


However if you would like to connect to Freenode by default every time you start up WeeChat:
/set irc.server.freenode.autoconect on


If you've registered your username (highly recommended so that nobody can pretend to be you) then you will need to prove you own the username by supplying the password:
/msg nickserv identify {your password}


Identify your username automatically every time you log on:
/set irc.server.freenode.command "/msg nickserv identify {your password}"


Join a channel (don't forget the hash # tag):
/join #{channel name}


Automatically join a channel (or channels) every time you log onto freenode:
/set irc.server.freenode.autojoin "#{channel 1},#{channel 2}"


These channels will open up side by side, one does not replace the other. However as this is a command line tool there are no tabs to click on for different chats. The next few commands give some examples of navigation, they all produce the same outcome using slightly different techniques, try these and decide on the ones you are happiest with.

Move to the next channel:
/buffer +1


Move to the previous channel:
/buffer -1


If you remember the channel name:
/buffer #{channel name}


All of the channels you join are assigned a number (the channels start at 3, 1 is the Freenode front page) To jump straight to the channel:
/buffer {channel number}


All of the above /buffer commands all essentially allow the user to navigate through the active chatroom channels, decide which one works best for you.

Should a user send you a private message, you are able to navigate using the above commands, it behaves just like another channel. When a user sends a message, their username will appear at the bottom of the screen, above the text entry box.

Any messages that mention your username during the chat, their username will change to a yellow text with a purple background. This makes it easier to keep track of a conversation in a busy chatroom.

Send a user a private message:
/msg {username} {your message goes here}
A condensed version of this post is available for download in odt format here, this is ideal if you wish to print these off and can also be easily edited.

This isn't even close to all of the commands and tools available to the end user, however it should be enough to allow the user to perform most of the basic required functions for an internet chat on the Freenode network.

If there are any tasks or command that you feel this guide is missing then please leave a comment below.

Tuesday, 31 May 2011

Adding a new user and default user groups in Crunchbang

Recently I had a bit of an accident when I stupidly entered the wrong letter letter into a command and ended up removing myself from all the default groups on my profile in Crunchbang Linux. No problem, I thought, I'll just use the same groups that I added my username to when I created my Gentoo system. Problem: Gentoo and Crunchbang (Debian based) use different groups. This was a more annoying problem than I expected.

This resulted in a lot of wasted time so I thought I would share the experience so that it could be easily fixed without wasting the amount of time I did in looking for a solution.

To add a user we simply open up a terminal and type (as root) the command adduser

This will ask for some details of the new user including name, username and password. This will give a new user a working login and a home folder, however it will not give the new user any group privileges. The default groups that Crunchbang assigns to a user upon installation are:
  • cdrom floppy sudo audio dip video plugdev netdev bluetooth powerdev
To add the user to these groups we enter the command (as root):
usermod -a -G cdrom,floppy,sudo,audio,dip,video,plugdev,netdev,bluetooth,powerdev {the new username}
Please note that the above command may appear to be on different lines, but it should be written all on one line with a space after "-G" and after "powerdev", all the groups are separated with commas. Once you have done this then your new user is ready. Don't forget to add the new user to the sudoers file, if your not sure about this then take a look at this post for some extra help. If your like me and you end up removing the user from the groups then simply add your current username to the above command.

Saturday, 26 February 2011

Formatting a USB pen drive with the Command Line

The vast majority of users today are probably wandering why I would even consider writing a 'how to' for formatting anything from the command line. The vast majority of distros come with gparted installed and that is an easier option to format any drive with the added convenience of a nice graphical front end.

However for those users who like to test out new distros on a regular basis, a USB pen drive is now the preferred option to boot into a live environment. Why? Well for starters programs like Unetbootin make it very easy to put a live distro onto a pen drive. This can be run, booted straight from the stick, without ever having the need to burn a CD. After testing and/or installing the distro the drive can be reused, unlike the CD which may be used as a coaster before ending up in the bin.

Some programs, when they put the distro onto the pen drive, trick the computer into thinking that the pen drive is a CD. It works fine for testing the distro, but when it comes to wiping it you are unable to do it from the file manager (CDs are read only) and gparted will not format it (it does drives not CDs). So your left with a pen drive that behaves like it can't be altered, but this is where the command line is a useful tool.

This will wipe all the data off the pen stick, for safety reasons I would strongly advise disconnecting any other external USB hard drives or pen sticks at this point.

First of all you need to find out the stick is listed as
1. open up the terminal

2. type: fdisk -l

This will tell you the location of your USB drive, in the case below it is located at /dev/sdd so I'll use that for the rest of the tutorial. Please remember to substitute in the actual location of the drive when you are doing this.
kevie@kev-pc:~$ fdisk -l

Disk /dev/sdd: 4009 MB, 4009754624 bytes
124 heads, 62 sectors/track, 1018 cylinders
Units = cylinders of 7688 * 512 = 3936256 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
3. unmount the drive with the command: umount /dev/sdd

4. I'm going to assume that your wanting the pen drive formatted to FAT32 to allow you to use it on any system. Type: mkdosfs -F 32 -I /dev/sdd

That's it, your done.

Wednesday, 29 December 2010

Adding user to Sudoers file

I remember my first time exploring Linux distros outside the safety of Ubuntu. One of the very first things that confused me was when I tried to use the sudo command I was greeted with the message:
kevie is not in the sudoers file. This incident will be reported.
In the community we are often guilty of assuming things we do regularly are known to all users, but we all lacked knowledgable at one time. Well the first thing that is important is how to add the user to the sudoers file.

1. open the terminal

2. type su (then enter your password)

3. type visudo

this will then bring up a screen full of characters, you can scroll around, but you'll notice that we can't start typing right away, we are in the editor called vi

4. scroll down to the line root ALL=(ALL) ALL

5. press i to start editing the file

6. below the line in step 4 enter {your user name} ALL=(ALL) ALL

7. stop editing by pressing the escape(esc) key

8. assuming everything went alright* enter :wq to save and exit the file

*if you accidentally changed something you shouldn't have :q! will exit without saving the file. If you need to do this type the command and go back to step 3.

You are now in the sudoers file and can use sudo to gain superuser privileges. But remember:
With great power comes great responsibility
The second question you'll be asking yourself is "Who does the first 'illegal' use of sudo get reported to?" Well the following illustration should help: