sobota 11. februára 2012

Post install settings 3

1.Locate
Basically, you have two ways how to search files through filesystem.
You can use command "find" or "locate".
Find: - this is live search as you know and scans. You can be 100% sure about results, because they are current.
Locate: - first you have to build a database of files stored in filesystem and then this command searches within this indexed database. So search results are instant but database don't have to be up to date, accordingly your results will not get entire results.
 
To update local database use:
/usr/libexec/locate.updatedb

Depends on amount of files, this process can take a lot of time.
You can run this script periodically via "cron" etc. after midnight (on server). 


Can happen, you don't need to index some filesystems, directories or so. Than look into /etc/locate.rc. This is config file for above script. You can configure for example:
SEARCHPATHS="/" - this causes to start indexing all files beyond "/" (root path).
PRUNEPATHS="/tmp" - this exclude paths from indexing
With above, you can make indexing more effective and faster.

I use "locate" very often to localize commands to check full path etc. It makes your work (scripting) easier because of speed. Be sure your database is up to date.


2. Set password
After minimal install, your root password is blank. It's better to use password for further purposes and basic security. (Generally all varies whether you use computer alone or it's shared or it's server.)
Very simple:
passwd - prompts you to type your new password
passwd [user] - same, but for another user

3. Connectivity
Your system don't have connectivity to network after base installation, even you have router on the end side with DHCP.
Basically, you can set network parameters statically or dynamically.
You need to know the name of your NIC. One way is to use "ifconfig" command to figure it out. 
For example I can see: ale0
"ale0" is mentioned name of NIC. To check little bit more use:
dmesg | grep ale0
result: ale0: <Atheros AR8121/AR8113/AR8114 PCIe Ethernet>
Don't forget to change interface to yours.

1.Static configuration
ifconfig ale0 inet [IP] netmask [mask]
ifconfig ale0 up
route add default [IP] 
(if you don't know what some parameter mean or you want to know more, check man ifconfig)
If you want preserve network parameters after system start, you have to edit "/etc/rc.conf" file:
ifconfig_ale0="inet [IP] netmask [mask]"
defaultrouter="[IP]"
Your DNS servers put into "/etc/resolv.conf"
etc.: nameserver [IP]

2.Dynamic configuration
dhclient ale0
To check assigned parameters do "ifconfig" + you can take a look into "/var/db/dhclient.leases.[interf]".
You can affect some parameters of dhcp via "/etc/dhclient.conf". Check the man for this config.
Put follows into rc.conf to preserve dhcp after next boot:
ifconfig_ale0="DHCP"
or ifconfig_ale0="SYNCDHCP" - booting will continue after dhcp assignment. 


After your interface is set, try to ping internal IP, public IP and public name (google.com).


For more informations check handbook / handbook.







štvrtok 9. februára 2012

Post install settings 2

We will continue in "tcsh" shell customization.

3. Customize shell prompt.:
You can achieve nice and pragmatic prompt really fast but what's perfect, you can use colors in your prompt. It's a little bit hard to understand, because of color syntax but you will be rewarded with fancy prompt. First take a look at b/w prompt and colored afterwards.

In "if" section of ".tcshrc" check the "set prompt" line.
The prompt is bordered with quotes.
You can put your "own words and symbols" to your prompt with combination of system variables like hostname, username, date, time and so. The list of variables can be found in "man tcsh".
The b/w prompt which I use:

set prompt = "[%n@%m|%~]>"
- [: my own character
- %n: prints username
- @: my own character to separate username and hostname
- %m: prints hostname
- |: (pipe character) my own character do separate directory from others
- %~: prints current directory (~will show instead home dir.)
- ]: my own character
- >: my own character
My prompt then looks like: 
[root@MCBSD|/etc]>

I use above prompt, but with colors. I use red for username letters, blue for [@|] and white for the rest. To understand color syntax, practice with it. Below example is for color of letters, you can set color even for background and so.

Color codes:
30m - black
31m - red
32m - green
36m - cyan
and so...for more check google: bash prompt color codes

Syntax:[starting string][your string][ending/reset string]

[starting string]: %{\033[36m%}
-just change "36m" to color you want. 36 is for cyan
[your string]: your symbol "etc. @" or variable "%n" for username"
[ending/reset string]: %{\033[0m%}
- leave this as it is, it resets color back to default


You have to use this syntax for every symbol in prompt in order to have colored this symbol.


Small example: word TEST with half cyan and half  red


%{\033[36m%}TE%{\033[0m%}{\033[31m%}ST{\033[0m%}
- %{\033[36m%} will make  "TE" to have cyan color 
- {\033[0m%} will reset color after "TE" back to default
- {\033[31m%} will make "ST" to have red color
- {\033[0m%} will reset color after "ST" back to default 


My prompt:
set prompt = "%{\033[36m%}[%{\033[0m%}%{\033[31m%}%n%{\033[0m%}%{\033[36m%}@%{\033[0m%}%m%{\033[36m%}|%{\033[0m%}%~%{\033[36m%}]%{\033[0m%}>"


If you compare letters marked with red, it's the same as in b/w prompt. Rest contains starting and ending strings.

That's it. Your life in CLI is more comfortable now. 
You have nice overview where and "who" you are by nice prompt.
You can use TAB key for better orientation in usable commands and for overview of listed files/folders in actual position.
You have shortcuts for faster executing your frequent commands.

 
 







Post install settings 1

Regarding previous post about minimal base install, the next handy steps are to adjust environment we will working through.
1.Change shell:
The default shell in FBSD is "sh". SH is shell with basic functions but nothing more. If you work in CLI often, it's better to use sophisticated shell. 
I use "tcsh" shell for CLI and "bash" for scripting. 
TCSH exists in base install but BASH not. If you want bash, you have install this via ports. (More about installing software in further time).

Changing shell is very simple:
For current user: chsh -s [shell]
Change shell for another user: chsh -s [shell] [username]
Etc. To change my current shell: chsh -s tcsh


Now you can log out and log in back to see the difference.
Before you have made a change, the sign of the shell was "#" what means you are in "sh" shell. Now you should see "%" in prompt line what means "tcsh" shell. 

Some ways to verify the current shell:
echo $SHELL
cat /etc/passwd (see end of line for particular user)
cat /etc/master.passwd (see end of line for particular user)


More about shells you can find in handbook

2.Customize shell prompt
As you can see, "%" at the beginning of the prompt doesn't seem nice and you can't list of possible commands by pressing TAB key.  Next handy trick is using aliases. Alias is CLI shortcut for whatever command.


Change your current directory to "home" (press cd).
By "ls - la" you should see file ".cshrc". Dot means something like hidden file. 
".cshrc" is configuration file for "csh" shell which is similar to "tcsh" shell.
Copy ".cshrc" to ".tcshrc" because we use "tcsh" shell.
Now you can edit ".tcshrc" for example with "vi" editor.
(Adjustment of vi editor in further time)
So what we are going to do:


1.Aliases etc.:
alias [shortcut] [command]
alias df /bin/df -h
alias cl /usr/bin/clear
alias re rehash
alias etc cd /etc
alias shut /sbin/shutdown -p now
and so.....what you want


2.Autolist:
In "if" section of the file (it should work placed anywhere) add:
set filec
set autolist


For apply the change, log out and log in back. Now press TAB key, and you should see suggestions. It works for commands suggestions and list of files suggestions. It's very helpful.


See the continue of this article.
 

nedeľa 5. februára 2012

Base install (minimal)

As I mentioned, I prefer minimal install and then adjust the system in way of my ideas.
Here you have a list of few installation steps. 
(FBSD 8.2-Release,64Bit).
(I suggest to install 64 bit version if you can, anyway everything is going towards 64bits)
1.Select country and eventually key-map after
2.Main menu
We are not installing Standard or Express install so choose "Custom" as we have everything under control.

3.Main menu
"Options" are not interesting at this moment. First we'll create a slice. More about disk geometry see etc. handbook. Everything regarding our BSD system will be stored in slice.

4. Partition - select disk
Select a disk you want to BSD install on. If you are not sure on which you have free space selected for your install there is a hint. In Windows etc. via Partition Magic or similar create random partition with space you want to spend on it. Etc. ext4(linux partition) with 60GB space. So this way your space for BSD will be marked and then you can browse disks (ad0/ad2 on the picture) and look for this partition. Then you can select that "marked" partition and delete it, so you are sure the new space created after is safely selected and you can't make a mistake by removing "live" filesystem. If you have hard drive dedicated for new BSD installation, then don't bother with that.
5. Partition - create slice
As you can see, there is a legend with letters assignment. See the unused space, select this row and press "C". The new slice is going to be created. Assign all possible space, so don't touch the number and press OK. That's it. 
 6. Create labels
See the step 3. Select the label. Then you will see picture below.
See the highlighted row. Every time you want to create "label" or mount point, go to this row first.
So you have highlighted the row and now press C. As description says, you can specify amount of space for particular mount point. If you don't know what the mount point is, check the google.
You can assign selected space to file-system or to swap. We are going to do both.
I prefer to create isolated mount points for root(/), /usr, /var, and /tmp. You can even create one mount point  associated with the root (/). Check the google if you don;t know how much space assign to particular mount points. It depends on purpose of your system. You will do nothing apocalyptic if you mounted all space to the root(/). Do not forget to reserve the space for SWAP partition. How much the size? Check the google. I have 6GB of RAM so its generally enough to live without SWAP, but for sure, I have 2GB of swap but I have not seen the SWAP in use on my system.
7. Select stuff to install
Check the step 3. Select the "Distributions". 
Here you can choice, what will be installed on your system. We prefer minimal install so choose minimal and then little bit more so select "Custom" on the same page and press OK.
Choice "Minimal" ends in self "base" and "kernels" selection. I have 64 bit system and i want to compatibility with i386 system so I've selected lib32 and for better orientation in commands we will need "man" pages. That's it. All further we are going to do or add manually - that's the purpose.
Select OK and you should appear in step 3.
8. Commit 
In step 3. select the media you want to istall from and again from step 3. menu select "Commit" and above dialogue will appear. "Yes" you want. Consequently the installation will start. 
At the end the following will appear:

 Select "No". Then select "Cancel" to end the installation.
Don't be scared, everything is installed and OK, remove CD eventually, select "YES" and system will be rebooted. Afterwards select default boot option and see the system booting. BSD will scan all the system to gather information about CPU, motherboard and connected devices. Than some self-checks and basic services will start. You should end in LOG IN prompt. 
That's it, you have fresh and powerful BSD install on your computer waiting to play with.

Why FreeBSD?

FreeBSD, in my opinion, is the best to start with from all BSDs.
It's well supported with ports (linux like packages), always up to date and increasingly supported by vendors.
FBSD little differs from Linux distributions in way of system administration.
I've tried many Linux distributions but FBSD fits me the best.
(Update: FBSD is UNIX-like system, not Linux-like or Linux distro)
I prefer to install minimal-base and adjust everything according to my ideas. The benefit of doing this, you are always familiar with your system, you don't have unnecessary balast arround and you will become professional by solving all snags on the way of adjustment your system.
FBSD is great as server OS or even Desktop. 
There is one "negative" about all of this: It often takes a long time to get your system adjusted and familiarized with so patient is appreciated and for those who has IT as hobby it won't be the problem, even vice versa.