Partitioning Your Hard Drive During A Linux Install

Hard DriveWhen you install Linux for the first time, you will need to partition your hard drive during the install process. If you’re using one of the more friendly distros such as Ubuntu it will by default partition your hard drive in a logical manner (this is called guided partitioning). However the partitioning it does is very basic, if you want to get more power from your Linux install, you will need to manually partition your hard drive during the installation. Most people shy away from this thinking that it is too difficult to know what part of the file system should get it’s own partition and what the partition size should be. Things, however, are not as difficult as you might believe and I will attempt to give a quick guide to how you can manually partition your hard drive to get more out of your Linux installation (I use Ubuntu so everything will be biased towards that distro).

Ubuntu Guided Partitioning

To make Ubuntu easier to install for those not familiar with Linux, it provides guided partitioning. Basically, the installation process will partition your hard drive without you having to get involved. This is fine if you’re new to Linux or are just not comfortable partitioning your hard drive manually. However, guided partitioning is very basic, it simply divides your drive into two partitions. The smaller one will be the swap partition (this one will usually be no more than a few gigabytes). The larger part of the hard drive will contain everything else (i.e. will house the root of the file system – /). While this type of partitioning is easy and will serve your basic needs, if you decide to manually allocate partition sizes for your hard drive you can get the following advantages:

  • isolate parts of the file system, so that they can be preserved if you reinstall the operating system (e.g. you can reuse your home folder so that all your documents and customizations are preserved)
  • separate data that changes frequently from data that changes infrequently, which can reduce disk fragmentation and prolong the life of the system
  • separating data that you want backed up into a separate partition can make your back up procedures much simpler
  • make your system more resilient to attack, if your system becomes the target of an attack or one of your programs behaves badly, it can create large log files or other files which can fill up the whole disk, however if you have multiple partitions, it can only ever fill up one partition which means your system is less likely to crash

Manually Partitioning Your Drive

Obviously if you decide to go with manually partitioning your drive you will need to consider the kinds of activities that are likely to occur on your system, this will determine what partitions you’ll need. This is completely up to you, however, generally the following parts of the Linux file system are good candidates to get their own partition (pick and choose the ones you think you will require).

/ (known as root) – this is the root of the file system (clearly :)) and will always get it’s own partition. Anything that doesn’t get a partition of it’s own will become part of the root partition.

/boot – the kernel and various other data needed for the system to boot live here. This partition can usually be pretty small. The data on this partition changes very infrequently and therefore you may not even need the ext3 file system on it (it can use ext2 instead) and having it as a separate partition can facilitate this.

swap – the swap partition is used to temporarily store data when the system does not have enough RAM for it’s current tasks. As a guide the swap partition should be double the size of system RAM and doesn’t need to be bigger than about 2 gigabytes. These days, systems often have more than 2Gb of RAM, but you do still need a swap partition (a system could, technically speaking, function without a swap partition, but I wouldn’t recommend it). Considering that disk space is so cheap these days, it is usually not an issue to have a 2Gb (or more) swap partition. The swap partition is never mounted and so does not get a mount point of it’s own (i.e. you won’t be able to browse the files on your swap partition).

/home – this is where the home directories of all users of your system will live. Having this as a separate partition allows you to reinstall the operating system without losing all your personal data. The other advantage is, if you have a multi-user system, a single user won’t be able to fill up the whole drive with their data and crash the system (at most only this partition will get filled up).

/usr – most of the packages you install on the system will end up here. Having this as a separate partition will allow you to backup or export this partition to another system easily (if you need to).

/usr/local – many additional packages (those other than Ubuntu core packages, if you’re using Ubuntu), will end up here. Some of the software packages you compile from source will also often end up here. You can have this one as a separate partition for similar reasons to /usr.

/opt – other packages you install and compile from source get installed here, so once again, for similar reasons to /usr and /usr/local – you might want a separate partition for it.

/var – the data here usually changes frequently (hence the name). Much of the system log data, package and accounting information resides here. It is a good idea to have it as a separate partition, if someone runs a job that consumes a lot of disk, this area won’t be affected and you will still have the information you need (such as logs) to diagnose the problem. The only caveat if you’re using Ubuntu is the fact that, the Apache web server will store all it’s web content under /var. So if you’re planning to use the system as a web server, it might be prudent to configure a different location for Apache to use.

/var/log – system logs usually live here, and so it may be a good idea to isolate the system logs from other parts of the system, considering how important logs can be do diagnose problems when something goes wrong.

/tmp – this one is pretty self explanatory. It can be used as a temporary space to store files or for programs to write temporary data. Strictly speaking you don’t really need a separate partition for this, but it certainly won’t hurt.

Possible Sizes For Your Partitions

  • /boot – usually don’t need more than 200Mb but disk space is cheap so give it 500Mb (0.5Gb).
  • (swap) – depends on amount of RAM, but for modern system with lots of RAM, make it the same size as the amount of RAM you have (e.g. 2Gb RAM – 2Gb swap)
  • /home – this one depends on how you plan to use the system, how many users you plan to have and the kind of work they plan to do. It is hard to give a guide for this one, however for a single heavy user (lots of data in home directory), you can plan anywhere between 20Gb – 100Gb or more.
  • /usr – depends on how many packages you plan to install on your system. For standard number of packages plan around 4Gb, for lots of packages anywhere up to 20Gb or more. For a regular home system, 20Gb should be plenty.
  • /usr/local – once again depends on how many packages you plan to install, but as disk space is cheap, for a regular home system you can make this one the same size as /usr.
  • /opt – similar situation as /usr and /usr/local here, make it the same size as the other two.
  • /var – if you don’t plan to run many severs this doesn’t need to be too big, so around 2Gb should be enough. If you do plan to run a few servers, this may need to be much bigger (depending on what servers you plan to run). Use your judgment here and remember that disk space is not expensive. To give yourself some future flexibility make this one around 20Gb.
  • /tmp – once again depends on how you plan to use your system (yeah I know, it always depends :)). This one is normally less important, give it around 10Gb.
  • / (root) – it is always a good idea to create the root partition last. Since this partition will contain all the data which you decide not to put in a partition of it’s own, the size required can change drastically. If everything else has it’s own partition then this doesn’t need to be much bigger than 2Gb or so. However, if you decide not to have a separate partition for something else, you will need to increase the size of this partition accordingly.

Depending on the size of your drive, you may have a lot of space left over after this. It is up to you how you dispose of that space. You may want to increase the size of each of your partitions proportionally to use up your whole drive. You may also want to use the rest of the space for another OS (dual boot).

That’s all there is to it. As you can see, manually partitioning you drive during a Linux install does not have to be a major drama. Having said that, I am not a great Linux guru, this is just the way I understand it. If you ARE a Linux guru, or simply have some extra tips in addition to the above, please feel free to share so that everyone can learn.

Image by Andres Rueda

The Most Handy NetBeans Shortcuts For Ruby Development

ShortcutAs some of you know I’ve been digging more deeply into Ruby lately, using various libraries and in general having some Ruby fun. Well, throughout all this I’ve been using NetBeans as my IDE. It’s been interesting switching over from Eclipse, I’ve been feeling a little unproductive since I didn’t know any of the shortcuts. After a while it got particularly annoying so I decided to force myself to learn all the useful shortcuts, mostly by denying myself the use of the mouse as much as I could :). Many of the shortcuts that work for a Java in NetBeans don’t work for Ruby, but I did eventually settle on a list of the most useful ones (slowly starting to learn to use these instead of doing things the hard way). Anyways, I thought I’d share:

  • Ctrl+Shift+Up – copy line under cursor up.
  • Ctrl+Shift+Down – copy line under cursor down.
  • Alt+Shift+Up – move line under cursor  up.
  • Alt+Shift+Down – move line under cursor  down.
  • Alt+Shift+Period – this one is used for selection, every time you press this one the selection widens to capture the next logical syntactic element. For example if you have your cursor over a word, pressing this ones would select the whole word, pressing again would select the whole line. If you’re inside a method definition, pressing it again would select the content of the method (between def .. end), once more would select the whole method. If you continue pressing it, you will eventually select the whole file. Very handy.
  • Alt+Shift+Comma – this one is the opposite of the one above, it will narrow the selection every time you press it.
  • Ctrl+/ – comment or uncomment line.
  • Ctrl+R – in-place rename entity under cursor. If it is a class, it will take you to the refactor dialog box. If it is a variable it will highlight all usages of that variable and attempt to change all of them to your new value (i.e. it is basically a rename refactor).
  • Ctrl+Q – go to last edited document/position. This will jump you to the last position you were editing before your current edit. If you were editing a different document before, it will jump you to that one. Keep pressing it to jump between positions you’ve been editing.
  • Ctrl+Shift+M – bookmark current line. This one is difficult to get used to, but if you want to remember a particular place for some reason, this is a handy one to know.
  • Ctrl+Shift+Period – cycle forward through bookmarks. Complements the one above.
  • Ctrl+Shift+Comma – cycle backwards through bookmarks. Complements the two above.
  • Alt+Enter – select quick fix. When the little light bulb appears offering a quick fix for a problem, you can use this one instead of clicking on it if your cursor is on the line.
  • Ctrl+B – go to declaration of symbol under caret. If it is a variable will jump to the first time the variable was declared. If it is a method name (i.e. method call) will jump to the definition of the method.
  • Alt+Shift+F – format code selection or file. If there is a selection, will format the selection, otherwise the whole file.
  • Ctrl+G – go to line. Will let you jump to a particular line number.
  • Ctrl+E – delete line under cursor. I love the ability to do this in Eclipse, so a really handy one to remember for NetBeans.
  • Ctrl+K – complete word by inserting word from buffer. This one is awesome! Start typing a word then press the shortcut – it will attempt to complete the word based on what else is currently in the file. If you press it repeatedly, it will cycle through all possible words in the file that might complete what you started typing. It does this very simply by scanning backwards through the file from your current position. It is usually correct the first time. Considering that IntelliSense is almost useless for Ruby development, this one is especially handy.
  • Ctrl+[ – jump to matching. This one is probably more useful for a language with brackets, but it can still be handy for Ruby to find a matching end for a do or an if.
  • Ctrl + Home – move cursor to start of file.
  • Ctrl + End – move cursor to end of file.
  • Alt + Shift + Right – move line one tab to the right. You can indent a line without having to move the cursor to the start of it.
  • Alt + Shift + Left – move line one tab to the left. Same as the one above, but lets you un-indent.
  • Shift + Enter – start new line below the current line and jump the cursor to the new line. Surprisingly handy.
  • do+Tab – insert do..end block. You just need to type do and then press TAB.
  • if+Tab – insert if..end block. Once again just type if and press TAB
  • ife+Tab – insert if..else..end block. Same story, type ife and press TAB.
  • Ctrl+Tab – scroll down through open files. If you have many files open in the IDE, this is a handy one to know. Pressing it once will pick the last open file you were in before the current one, keep pressing to scroll down through all the files currently open in the IDE.
  • Ctrl+Shift+Tab – scroll up through open files. The same as the one above but will let you scroll up through all the open files rather than scrolling down.
  • Ctrl+Shift+T – jump between tested file and test file. This one can be a little flaky but does work most of the time. If it doesn’t work for you, use one of the next two instead.
  • Ctrl+O – open a particular type. Search for a class by class name rather than file name.
  • Alt+Shift+O – open file by name. This one is complementary to the one above and will let you open a file rather than a type. Note that it is extremely slow if you have a large project (or several projects).
  • Ctrl+Shift+1 – select currently edited file in project view. I was so happy when I found this one, can be really annoying not to be able to jump to the file you’re editing (in project view).
  • Ctrl+Shift+2 – select currently edited file in files view. The brother of the one above, but lets you select the currently edited file in file view as opposed to project view.

If you have any other NetBeans shortcuts that would be particularly useful for Ruby development (i.e. I don’t just want any random ones, I know NetBeans has lots), please share and I’ll add them to the list.

Update: Here are some more handy shortcuts from the comments below (thanks to all the readers who shared their favorite ones)

  • Ctrl+1 – jump to files in project view
  • Ctrl+0 – jump back to editor (complements the one above)
  • Ctrl+Shift+V – pastes the code and formats it at the same time (very handy)
  • Ctrl+Shift+P – reformats/wraps comment lines to the designated right margin
  • Alt+Shift+F6 – run current test under cursor

Image by kathryn_rotondo

Why Open Source Rules And Commercial Drools

DroolsI saw a great post this afternoon by Rob Walling of Software By Rob, where he talks about Competing With Open Source. His main point was the fact that while there are some great open source projects, most open source software suffers from usability, support and documentation issues (amongst other things) and this is where commercial software can have the upper edge. While I could see the point he was trying make, I found that over the last few years I have developed pretty much the opposite view. Of course, it all depends on the segment of the software market that you’re looking at (enterprise, mass market etc.), but lets start with the big ones.

Enterprise Software Development

If you’ve done enterprise software development for any length of time you would have heard of or used some of the biggies (note I have predominantly been doing Java development):

All commercial, all owned by big companies, all established players in the market place with years of development effort put into them. So, let us examine these against some of the more pertinent points:

  • Easy of installation – I don’t know about you, but I would say all three that I mentioned above get a massive fail for this one (if you disagree please, I’d love to hear you explain how all those are easy to install)
  • Great documentation – Sure there is a LOT of documentation for all of them, the value of it however is marginal. Most of the information is probably there, finding what you need is a whole other story. Another big fail.
  • Usability – yeah all right, they are usable (sort of), but they have nothing over their open source counterparts in this department. Maybe not a fail, but certainly far from brilliant.
  • Support – well, it is certainly there somewhere. You know it exists, getting your hands on some of this support is a whole other matter. Even if you do manage to get through the layers of bureaucracy and get a hold of someone who knows what they are talking about, it gets you precisely nowhere if you found a bug with the software. It’s not as if IBM will be rushing out a new Websphere release just to fix your little issue any time soon and even if they did, let’s see you easily upgrade.

Notice that I only named 3 big commercial products, that’s not by accident. Undoubtedly there are hundreds of others used in enterprise software development, but the number pales in comparison to the sheer amount of open source libraries and products that are in general circulation. Lets see how many I can list off the top of my head in 5 seconds:

Pretty impressive, and that was the very tip of the iceberg. And the interesting thing about most of those that I listed is the fact that they have decent documentation (for the most part), are reasonably easy to use, are reasonably easy to install (if you know what you’re doing, at least a little) and have great support not only from the developers but from the community. Which is the truly awesome thing about open source products, even the smallest ones will often have a community form around them, a community that is usually vociferous, helpful and that includes developers who actually wrote the product. This is something that even the biggest commercial products usually lack – a helpful community. And consider that with open source software if you do find a bug, you sometimes actually have a chance of getting the products fixed and a new version released pretty much just for you. Granted, this will never happen with the bigger open source products but at least you have a chance and at the end of the day, you can always just patch it yourself and build your own copy (and submit your fix to the developers) because the source code is right there (difficult yes, but at least possible). And to get back to documentation, if you really think about it, open source software is the best documented software of all because you always have the god’s own truth to have a look at – the code. If you don’t understand the doco for an open source product, you can read the code as a last resort; for a commercial product – good luck!

Software For The Masses

Of course we have so far been happily ensconced in developer land, but what about the average Joe Bloggs out there, what’s the landscape like for him/her (Joanne Bloggs :)) when it comes to open source vs. commercial. The field is a little more even here, Joe is not going to read the code, he pretty much wants his software to just work and you know what more and more often these days open source software just does. Sure, commercial products probably have the majority of the market at the moment when it comes to mass-market software, but I would guess that their market share is shrinking. Open source developers have learned that they need to build for the consumer and not for other developers and they’re slowly starting to do so. And the abundance of open source tools and frameworks is making this easier and easier for them.

The only commercial software I have on my machine is … well the operating system (I am a gamer so Windows is a must), and even there my machine is dual boot :). Aside from that, everything else I need to do with my machine is done by free or open source software:

All of these were easy to install (they just worked), intuitive to use and have decent documentation as far as I know (never had to look at any). And as far as support goes, well once again we have the community which is more passionate and helpful around all of the apps that I listed than around most commercial products.

But, I am a developer, I hear you say, I know how to use and tweak all this stuff, surely Joe Bloggs would find things much tougher. Well, to that I have this to say, the only commercial software my parents have on their machine is … once again the operating system, and only because I didn’t want to confuse them too much (they are not developers :)). They’ve been using it fine and I haven’t heard any complaints about lack of documentation, support or usability, the machine does everything they want it to do, what else do you need?

This day and age commercial software is going to find it harder and harder to compete as the world is getting more connected and more savvy. Sure they can make the documentation great (which historically has not been the case), but so can open source software, and the 8020 rule applies where it all becomes moot after a certain point. Commercial can be more useable, but once again 8020 rule and you really need to innovate hard to stand out. Easy of installation is getting tougher and tougher to compete on as open source tools get more savvy about this one. Finally support is left, and honestly, no commercial software company has the same type of flexibility to offer support as a great open source product with a strong community. The only thing that you end up competing on is price and ‘nothing’, is going to beat ‘something’ every time.

Image by BL1961