Now that we've secured access to your Gentoo 10.1 slice we can update it and get it ready for the rest of the server install.
In part 1 of the Gentoo 10.1 setup, we completed the ssh configuration along with a basic iptables setup.
Now let's run some checks and install some personal configuration files to make life easier. Once done, we can update the install and create a solid base for the 'meat' of the server.
First thing is to confirm what OS we're using. We know we should be using Gentoo but let's see:
You should get an output similar to this:
Gentoo Base System release 1.12.13
That release number is what it should be when starting with Gentoo 10.1 as a base. The "release number" for Gentoo actually reflects the version of the "baselayout" package portage used for the install.
Memory usage should be very low at this point but let's check using 'free -m' (the -m suffix displays the result in MB's which I find easier to read):
It's nice to know what is going on so let's look at that output:
. total used free shared buffers cached Mem: 254 55 199 0 2 21 -/+ buffers/cache: 30 223 Swap: 511 0 511
The line to take notice of is the second one as the first line includes cached memory - in this demo slice I have 254MB memory in total with 30MB actually used, 223MB free and no swap used. Nice.
Normally the "ls" command doesn't list files that start with a period. Those are usually configuration files or directories, and ls hides them so they don't clutter up your directory view. To see all of what's there, run:
ls -a ~
The "-a" option is what tells ls to list all files, not just the non-configuration files.
You'll see several files, but let's focus on ".bashrc" right now. This is ultimately where your user environment (the "shell") will look for its settings. Go ahead and open it for editing:
Inside you'll see a lot of shell script commands — don't worry if you don't understand it all. Anything we add at the end of the file will override what came before. If you want to, say, change your prompt, you don't necessarily need to figure out what all the "if" statements in there by default are for, and which line you need to edit. You can just add your own setting at the end.
With that in mind, let's look at how to change your prompt. At its simplest, the prompt's format is set with the "PS1" environment variable. It consists of some numbers that determine color and some codes that act as stand-ins for variables like the current working directory and your hostname. To set your prompt to just your hostname and working directory, both in different colors, you could add this line to the end of the .bashrc file:
PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '
The chunks like "0;35m" and "0;33m" are what control the colors - those are pink and brown, for example. Other colors you can substitute include "0;32m" for green and "0;36m" for blue — it's just a matter of changing those numbers.
Other important parts of that jumbled collection of characters are "\h" and "\w", which represent the hostname and working directory, respectively. If you wanted to include your username in the prompt you could add the "\u" code along with an "@" symbol, and it would look like this:
PS1='\[\033[0;35m\]\u@\h\[\033[0;33m\] \w\[\033[00m\]: '
Before we see what that will look like, however, let's also look at another useful feature of your shell, aliases.
The "alias" keyword lets you set a shortcut for another command. Some examples to get you started, which can be added to the end of your .bashrc file:
alias free="free -m" alias update="sudo emerge --sync" alias install="sudo emerge" alias upgrade="sudo emerge --update --ask world" alias remove="sudo emerge --unmerge" alias search="sudo emerge --search"
They're pretty simple examples, and are just meant to save you a little typing. Notice that you can essentially replace a command with an alias, like we did by setting the alias "free" to be a shortcut for "free -m". With that alias set, when you type "free" on the command line, behind the scenes the shell actually runs "free -m", so you don't have to type the extra characters to get the memory usage numbers in megabytes.
Similarly, those other aliases are shorthand for some aptitude commands to update or install packages. Since "sudo" is run behind the scenes you'll still have to type your password, but at least before that you won't have to type as much to run an update or install a package.
To activate the changes you've made to the .bashrc file, either log out and log back in or enter this command:
If you set a value for "PS1" above, you'll see your prompt change. Feel free to go back and change the colors or format of the prompt, or add your own aliases.
You can check the current locale setting for your slice by running:
If the code doesn't match what it should be for the localization you would like to use for your slice (or if it uses a generic locale like 'POSIX'), you'll need to make a couple changes.
First, open the "/etc/locale.gen" file for editing:
sudo nano /etc/locale.gen
Inside you'll see a list of possible locales. The lines with "#" in front of them are commented out, which means they are not actively supported right now. The lines without the "#" are active.
A typical entry in this file looks something like:
The first part, "en", represents the language used. The second part, "US", is the country of the locale. The ".UTF-8" in the example indicates the Unicode version of the locale (recommended), and the last "UTF-8" also tells the system to use Unicode.
A complete list of language and region codes can be found here. You can search the file in nano with "control-W". That makes it easier to jump to a locale once you know the language and country code combination you want. If the combination isn't already in the file, you can add a line for it yourself.
For example, if you wanted to enable the Welsh language (cy) for the Great Britain region (GB), you would add or uncomment a line that contains:
To disable an enabled locale just insert a "#" in front of that line to comment it out.
Once the locale.gen file is the way you want it run the command:
With the locales generated you can set the default locale by creating or editing the "/etc/env.d/02locale" file:
sudo nano /etc/env.d/02locale
In that file set the "LANG" environment variable to the locale you'd like to be your default. For example, for English/US, your 02locale file would look like:
Once you've set the new default locale you'll need to update the system's environment variables with the command:
And then to change the locale without logging out you can pass the locale name directly to your shell as an environment variable:
You can also add that line to the .bashrc file to change the locale for a particular user when they log in (if they want to use something other than the system default).
In any event, you can run "locale" again at any time to check your current locale. To test the change to the system default locale you'll need to log out then log back in.
A Gentoo server comes configured to select a random mirror when downloading packages.
Have a look at the global make config file, which includes the portage sync address used, by running:
You'll see a number of configuration entries. Right now the ones we're looking for are:
# Default rsync mirror SYNC="rsync://rsync.gentoo.org/gentoo-portage" # Default distfiles mirrors GENTOO_MIRRORS="http://distfiles.gentoo.org http://distro.ibiblio.org/pub/linux/distributions/gentoo"
The first setting, "SYNC", tells portage to use an address that automatically chooses a random mirror when fetching packages. This is usually fine, but that address can be edited to limit the random choice to mirrors in a particular country by inserting the country between "rsync" and "gentoo" in the address. For the US, that would look like:
The second setting, "GENTOO_MIRRORS", defines the possible sources for lists of mirrors to select from. This setting should usually be left alone.
Now we can update the package list that portage uses.
sudo emerge --sync
NOTE: If you have used the .bashrc aliases shown above you just need to enter 'update' as the alias will use the entire command. I've put the whole thing here so you know what is happening.
Odds are good that the first thing you'll need to update is portage itself (and if not, running this command won't hurt anything):
sudo emerge portage
And now let's see if there are any upgraded packages available:
sudo emerge --update --ask world
As with all installs have a careful look at the list and, once happy, press 'y' to continue.
That's really the basics done for the Slice.
The console is now informative and less drab, locales have been configured and your system has been updated. Quite a lot happening here but now we have a more secured Slice with updated packages ready for the meat of the server to be put in place.