Saturday, February 26, 2011

Setting up a server, the nanoTux way!

Good evening. I think I've built up enough oomph to attepmt AGAIN to setup a server. Using the nanoTux guide, http://nanotux.com/blog/the-ultimate-server/, I'm really hoping that it works and that I haven't gone insane by the time I reach the end of the HowTo. This guide was found on the Ubuntu Forums website in the Server Platforms area and seeing as it's had almost 27000 views, I'm sure it's the real McCoy.

For a complete HowTo, go to the address given above as this post will simply be making references to the code I use, and any workarounds that I implement. Begin! Shit...no coffee, plunger is missing...

To be continued...

Sunday, February 6, 2011

Just some useful stuff: bash networking commands


After all that clicking and scrolling for my last post, I ended up finding several other useful commands. Most of them are to do with networking and I'd just like to have them handy. Here goes.

Display total space and availability:
df -h

Display size of a folder, a couple of options here, may need to be sudo:
sudo du -hs /path/to/folder
sudo du -chks /path/to/folder

IP Scanning with range 192.168.1.1-192.168.1.254:
sudo nmap -sP 192.168.1.1-254

Scan operating system on target IP (cool!):
sudo nmap -O 192.168.1.3


...and that was all!

Ubuntu and Windows: admiring how they share


Up late again but I've struck some success. I've just found a neat little way to access a share folder located on a windows box on your current network. This will no doubt be a short How-To since it's 12:44AM and I didn't fall asleep till 3:30 this morning because it was so hot, great.

So, basically, you have a network, and because you are leet, you run a Ubuntu machine, but of course someone else will be running Windows (and others maybe even a Mac, God help me if I have to figure that out). If you have used Windows, then you will know that there is a somewhat simple way to setup folder sharing, but this requires you to be connected via a cable to the network. Not sure why.

To share a folder in Windows with the rest of the network, you just right-click on the folder you wish to share, then Properties > Sharing Tab > go down a bit. Then, you might see "Network Setup Wizard" or you'll see two check boxes:
1-"Share this folder on the network" and
2-"Allow network users to change my files".
If you see the wizard, then you need to follow it through and hopefully select everything correctly; there's a guide here at the MS site. For you (the leet user) to be able to access your mates'(clueless drongo) computer, both of these boxes must be ticked. And I'm sorry, but you can't do this without the owners consent...

Just to check if you or your friend have done the setup right, the shared folder will come up in Network Places (I think, not using Windows atm) under the workgroup that you chose in the wizard.

Ok, so the folder is being shared, how do I access it from Ubuntu? Well the simplest way is to just click there by going to Places > Network. It might take a while to load because it does some sort of search. The other way to access it is from the command line, useful for those who want to move stuff from a dead server box that doesn't have any USB ports! Lol...

I'm running Ubuntu 10.10 and I didn't have any dependency problems but that may be different on other distros. There are two packages, CIFS and smbfs which can be used to mount local machines to a place on your computer. Currently, it seems that they can only mount machines that have a wired connection. Maybe something to do with too many fingerprints...not sure.

Create a mount point on your computer first: I went with /mnt/test. But any will do.
sudo mkdir /mnt/test

Now, assuming that you know the IP address of your mates computer and have already obtained their username/password, run the following command for CIFS:
sudo mount -t cifs -o username=drongo,password=password //192.168.1.1/shared-folder /mnt/test

And for smbfs just remove the -t cifs:
sudo mount -o username=drongo,password=password //192.168.1.1/shared-folder /mnt/test

If they didn't use a password, just leave it out and when it prompts for one, just hit ENTER. I did run into one hiccup and I'll just voice that here. The IP address that you use has to be the address of the wired modem not the wireless modem, otherwise it won't work. That's it. I'm sure I've left some other important information out so please correct me if you find it.

Other than that, the folder should now be accessible at /mnt/test for you to copy, write, delete or even put stuff there. Maybe you're a nice friend and you want to give them some music? It's possible.

Don't forget to unmount!
sudo umount /mnt/test

Friday, January 28, 2011

Quick styling




Quick styling no embedding!

<style type="text/css">
pre.source-code {
  font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;
  color: #000000;
  background-color: #eee;
  font-size: 12px;
  border: 1px dashed #999999;
  line-height: 16px;
  padding: 10px;
  overflow: auto;
  width: 100%
}
</style>

<pre class="source-code"><code>Quick styling no embedding!
</code></pre>

Quick styling embedded! 

Getting a VM to work...the hard way


What am I talking about? I still don't really understand the concept of a computer running inside a computer. And I don't mean a laptop running inside a desktop case! I'm talking about Virtual-Machines. Loading an OS from a recently acquired image and then making it run in the background of an already running OS. Sounds like I might need a faster computer. Or get some liquid N2 and just frost up the bottom of my laptop. At least my palms wouldn't get hot. It does sound like a bit much.

Kernel-based Virtual Manager looks like a decent package. A bare bones kind of software that hopefully won't weigh down the running system. Problem is that I don't know how to use it, and I think that it runs from a command-line, which is what I want. There is an ever-so-useful HowTo at there site, and I'm testing that the procedures do work as I type this. I should go to bed.

Install the packages below as a start.
sudo apt-get -y install kvm qemu bridge-utils uml-utilities
sudo modprobe kvm
sudo apt-get -y install libvirt-bin
sudo apt-get -y install virt-manager

The last one is meant to be some sort of GUI but I have no idea how to use it, yet. The modprobe line reloads KVM without having to restart your computer, even though I've restarted mine several times before even getting this far.

Next, is you'll want to create a disk image for the guest-image, or in other words, a place where the virtual machine will live/sleep. From what I gather, Qcow2 is some sort of tool which creates a standalone image from a cluster of memory which is then scanned by the header when it needs to be read. I don't know. It's a thing. Create one like this:

/path/on/computer/where/it/will/live create -f qcow2 imagename.img 10G

Qcow2 will do it's thing, the last paramater is the size of the image, 10G -- I haven't played around with this much. When you have finally downloaded your Free and Open Source Linux distro that you so desire, just go ahead and install it.

sudo qemu-system-x86_64 -hda imagename.img -cdrom /path/where/.iso/is -m 512

There is meant to be some sort of read error and the host os will be unable to determine if the system you are installing is 32 or 64 bit, so by assigning qemu-system-x86_64 as the pathway, no one gets confused. Although, it might actually be part of the command, not sure. The final -m tells qemu how much RAM you want to allocate to the VM. I'm finding out now that maybe I should have used -m 1024, 36mins57s remaining...uhg!

1:29:40AM - Still waiting...

1:34:46AM - Meanwhile, test that the printer works

1:49:05AM - Printer works, going to bed, check the install in the morning.

5:35:19AM - Still going, stupid WINS param...

8:54:24AM - Yay! It's working! I'm now running Debian 2.22.3

Lastly, when you need to start up the VM from scratch, it is a simple call of the OS file created and the image memory, or whatever you want to call it. As you will probably find out, it's much simpler to create a directory and store both of these files there, that's what I did.
qemu-system-x86_64 -hda /path/to/imagename.img

So that's it. The system seems to be working fine. I have somehow lost track of where the KVM functionality is taking place, as Qemu seems to be doing all the work. My understanding of KVM has been rewritten, again - I must have missed something.

Sunday, January 2, 2011

Creating an autorun script for when a specific USB device is plugged into your Computer

Much of my information came from this thread, very helpful: http://ubuntuforums.org/showthread.php?t=502864

Several steps are involved and several locations will be accessed heavily. These are:
/etc/udev/rules.d - where the .rules file will be kept for the computer to access when the USB device of choice is plugged in, this ultimately points to the script file below
/usr/local - or wherever your script file is located.
/home/... - any other places where script files that will be used are stored, python, C etc

/etc/udev/rules.d
A README file is available in this folder and it is helpful to read. You will need to create a file here which will be picked up by your computer and read when an action occurs.

The file must begin with two digits followed by a - and end with .rules, 70-filename.rules. It will contain the following script:

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0d49", ATTRS{idProduct}=="7350", RUN+="/usr/local/script_file.sh", SYMLINK+="my_device"

If you are lost, just take a look at the files in /etc/udev/rules.d and make a similar filename.

To make it work for a specific device, with the device plugged in, run lsusb in a terminal and find the device Vendor and Product numbers. For the Kodak Co. device below, Vendor is 040a and the Product is 0576:
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 040a:0576 Kodak Co.
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000

The RUN+= is the location of your script file. It is very important that this file has user executable permission as well as for all other .py files etc that will be used by the script. To do this, go to the directory with the file and run:

$ sudo chmod u+x filename

and check the permissions with

$ ls -all

It should be: -rwxr--r--
These are the permissions that work for me, I'm not sure if this is across all platforms.
The location of the script file is not important, but make it an easy place to remember. SYMLINK+= is a feature I'm not familiar as yet, however it does allocate the device to the variable given to a spot in the /dev folder, /dev/Maxtor.
The ATTRS before {idVendor} and {idProduct} can be changed to SYSFS if the device is not being recognised once plugged in. This can only be tested by you and your product, although there may be better explainations about this.

The SUBSYSTEM variable can be left out completely, however it does give useful information to the computer. Other variables such as usb_device and pci... exist but usb is the one that works for me.

At first, it is advised to make the script file a simple copy code like a cp command of a file you know to a place you know. If after you plug in the device, you find that the file has been copied to the new destination, you can be sure that the .rules file has been successfully read. This is definately the hardest part of the setup of this 'autorun' script.

Before I wrap things up, I did want to add a work-around for the .sh file, the file pointed to by the .rules file. I had problems when plugging in my device because the .sh file would read first, and then any other code already on the computer would read last. This was a problem because I wanted to point to a folder on the device but the device hadn't been mounted yet. I could have mounted it myself but I ran into a dead end. An alternative was using the sleep command followed by my code, inside some curly braces {}, looking like this:
{

sleep 5
cp -ar /a/folder/on/my/computer /folder/on/device

} &

The {} tells the interpreter to read to code, but run it in the background. With the sleep command, there is a 5 second pause while the computer runs it's usual code of mounting the device. After the 5 seconds it now copies the folder to the location on the device.

If you have a know fix for mounting a device manually using the /dev location, I'd be happy to hear. I'm now using this method to auto update my Uni files on my external HD whenever I plug it in. This is my first How-To so enjoy, rate, comment.

Thursday, December 30, 2010

Healthy Choices

After viewing several health sites and talking with some work friends about the conundrums of eating healthy, exercising and sticking to the goal...I have realised that it may be difficult, if I let it be. The "goal" calculator above was put together by a well known vlogger Scooby1961 who can be found on YouTube. I won't provide a link to his websites since it may come across as bad publicity to him...I'm sure you'll be able to find him. This post, I hope to outline some problems with having a busy work-life and trying to put on muscles, which requires an intake of plenty of healthy foods and protein.

So what seems to be one of the difficulties with maintaining a healthy diet to assist a complete body workout and to gain muscle, is sticking to the plan. What I believe needs to be taken into account when making a health plan is your situation. Firstly, the hours of work you do and the time that you are there can be critical: day-shit, afternoon-shift, graveyard-shift. The type of work, doesn't really matter I guess. If you are a student, then the schedule for the semester should be known. Work and Uni are similar in that they both follow a schedule and workout sessions must be planned around these two.

Next, is the workouts. As mentioned above, these need to be planned around all the stuff that keeps you busy. I've heard from many people that a workout in the morning is the best but some of us, including me, it cannot be achieved. Therefore, an afternoon workout is the only other option. What ever the case, workouts should be done in between meals. If you are using certain powders to assist muscle gain, i.e. creatine, then workout session need to be at least 1hr after taking a dose, and/or finish 30mins before taking a dose. It ain't rocket science, but it's no fun working out on an empty stomach, and the same for when you are full up from a meal, it just sloshes around and makes you sick.

Finally, hobbies and interests or study. Personally, I'm starting to read more, news sites like the Guardian or the Courier Mail make keeping up-to-date easy. Australasian Science is a good Australian monthly with articles that range from Astrology to Geological finds in Australia and these often tie in with my studies so it isn't a complete waste of time. Playing guitar is good also for me and very relaxing. It doesn't matter what you do to kill time, but you must always know what part of the day you are at and what is next on the health-agenda. What I mean, is always know what is next, protein shake, travel to work, morning tea, toilet time etc - and drink lots of water. So even though you may be just watching TV or checking flight prices for your winter holiday, in the back of your mind you should know what part of you day is next, food, water or workout. If you just focus too hard on the goal and the diet, you may find that even just thinking about it will become a drag and you will lose interest. Have a break. Think of something else. The only part when you should be thinking about your muscles is when you are at the gym concentrating of your form and your breathing. As soon as you leave, your body does the rest.

Now, add all that together and we have three activities that must be considered when planning a diet: Work/Uni, the Workouts, the Free-Time/Study. If you can draw up all the time slots for these activities, then you will be able to see the time in the week that is free. As a general rule, I keep the weekend free, gives me something to look forward to that I haven't planned. With this free time during the week, you need to be clever, because chances are you will not have much time to prepare food. A big time saver for me is, from Sunday - Thursday, cook a nice dinner and cook extra, enough for lunch tomorrow. That way, all you have to do is pack it in a lunch box, and you have a big lunch for tomorrow. Examples could be, Ginger and Lime Fried Chicken with steamed veges and rice, Thin sliced rump in a garlic soy sauce with rice or spaghetti bolognese (I love pasta).
     The night time is the only time of the day when I can use a stove top so I utilize this time and make something nice, something hot. I actually enjoy cooking (wouldn't mind if someone else did the cooking) and eating and if all the fun and enjoyment is taken away because of a diet, then it might be a little bit harder to reach your goal.
      Another problem may be if you like junk food, and I know that there are those people out there. All I can suggest here is to avoid junk-food outlets. Yes they are an easy option. Yes they appear cheap. Yes they can be convenient. But you can avoid this if you just do some clever planning. Find the times of the day that you have free, and prepare something that will be quick and filling. If you are wanting to gain muscle, you will know that you will need to eat 6 protein packed meals over the whole day. But no one ever said how long you need to eat for. Eating 23g of protein in 2 minutes is probably going to have the same affect as eating 23g of protein in 15minutes. Although you might get sick if you eat too quick...
      If your timetable doesn't coincide with lunch at 12PM, then unfortunately you will have to swap it in for one of the quick meals, i.e. protein shake, and have the bigger lunch a bit later on when you have more time. Once you have mastered your eating times, you will no longer even need to think about it, and you can do more of what you want, finish that novel, finish that assignment!

Dieting is hard. I know. I'm an amateur. What I'm finding is that it is getting easier. I'm learning more about the food that I eat, and I'm picking up tips on foods I don't eat that are a quick and healthy option, Walnuts for instance. I've only been watching what I eat for the last three months and I hope that I can continue this for longer. My goal is simple, put on muscle. Therefore, keep it simple and enjoy it as much I can.