Sunday, February 12, 2012

Linux Disk utilities


fdisk /dev/hda
(= "fixed disk". As root.) Linux hard drive partitioning utility (DOS has a utility with the same name). In the example above, I specified that I would like to partition the first harddrive on the first IDE interface, hence "hda". If I were you, i would backup any important data before using fdisk on any partition. I do not not know anybody who likes fdisk (either Linux or DOS edition)--I prefer easier to use cfdisk, see next command.

cfdisk /dev/hda
(as root) Hard drive partitioning utility, menu-based. Easier to use then the plain-vanilla fdisk (see the previous command). Physical drives can contain primary partitions (max 4 per disk), and logical partitions (no restriction on number). A primary partition can be bootable. Logical partitions must be contained within "extended partitions"; extended partitions are not usable by themselves, they are just a container for logical partitions. When partitioning a disk, I typically: (1) create a primary partition (2) make the primary partition bootable (3) create an extended partition, (4) create logical partition(s) within the extended partition.

sfdisk -l -x |more
(as root) List the partition tables (including extended partitions) for all drives on my system.

parted /dev/hda
A partition manipulation utility for Linux (ext2), and DOS (FAT and FAT32) hard drive partition. It is for creation, destroying, moving, copying, shrinking, and extending partitions. You should really like to backup your data and carefully read info parted before using it.

fdformat /dev/fd0H1440
mkfs -c -t ext2 /dev/fd0
(=floppy disk format, two commands, as root) Perform a low-level formatting of a floppy in the first floppy drive (/dev/fd0), high density (1440 kB). Then make a Linux filesystem (-t ext2), checking/marking bad blocks (-c ). Making the filesystem is an equivalent to the high-level formatting. I can also format floppies to different (also non-standard) densities; try ls /dev/fd0 .I am also able to format to the default density (normally 1440k) using fdformat /dev/fd0.

badblocks /dev/fd01440 1440
(as root) Check a high-density floppy for bad blocks and display the results on the screen. The parameter "1440" specifies that 1440 blocks are to be checked. This command does not modify the floppy. badblocks can be also used to check the surface of a hard drive but I have to unmount the filesystem first to do a full read-write check:
mount [to find out which device contains the disk partition I wish to check for bad blocks]
umount /dev/hda8 [unoumnt the selected partition]
badblocks -n /dev/hda8 [check the selected partition in a non-destructive read-write mode, so that my data is not erased!]
mount /dev/hda8 [mount the partition back since no info on bad blocks was printed]
If bad blocks are found, they can be marked on the hard drive so that will not be used using:
e2fsck -c /dev/hda8

fsck -t ext2 /dev/hda2
(=file system check, as root) Check and repair a filesystem, e.g., after an "unclean" shutdown due to a power failure. The above example performs the check on the partition hda2, filesystem type ext2. You definitely want to unmount the partitions or boot Linux in the "single mode" to perform this (type "linux single" at the LILO prompt or use init 1 as root to enter the single user mode). If errors are found during the filesystem checkup, I accept the defaults for repair.

tune2fs -j /dev/hda2
(as root, only for kernel that support ext3--RH7.2) Adjust the tuneable parameter of an ext2 filesystem. The example above shows how to add a journal to a disk partition (hda2 in this example), effectively converting the file system to ext3 (journaling) filesystem. To complete the transition, you must also edit the file /etc/fstab and change the filesystem type from ext2 to ext3, else you may run into problems--ext2 will not mount an uncleanly shut down journaled filesystem! To check what is the type of the filesystem use mount (with no arguments) or cat /etc/mtab. If you need more information on ext3 setup,
Other options of tune2fs let you me add a volume label, adjust the number of mounts after which the filesystem check is performed (maximal mount count), or turn on time-based filesystem checks instead (less often used).

dd if=/dev/fd0H1440 of=floppy_image
dd if=floppy_image of=/dev/fd0H1440
(two commands, dd="data duplicator") Create an image of a floppy to the file called "floppy_image" in the current directory. Then copy floppy_image (file) to another floppy disk. Works like DOS "DISKCOPY".

mkbootdisk --device /dev/fd0 2.4.2-3
Make an emergency boot floppy. You are typically asked if you would like to make a boot disk during the system installation. The above command shows how to make it after install, on the first floppy drive (/dev/fd0). Your kernel name (needed in the command, here 2.4.2-3) can be determined either by running uname -a or ls /lib/modules . 

How to Reset forgotten Root passwords How to Reset forgotten Root passwords


1.0 Introduction

Suppose you have just taken over as a new system administrator from another person just before they left and they forgot to give you the root password. Now, let's say you have to install the latest version of PHP on the system so that the sales department's website works the way its supposed to. You have to get the website up yesterday, since you are losing money every minute it doesn't work. Or maybe you simply need to add another user to the system.
The above scenarios are just two possible cases when you might need to reset the root password on a system; there are hundreds of other possible cases when you might need to do this, but I am not going to list all of them. Most of us know what to do when something like this happens on a Windows machine, but not a lot of us know how to recover lost passwords from Linux machines. This document attempts to rectify this situation by telling you about the different options available to recover passwords from YOURmachines. (Don't use this to break into other people's systems as that would be stupid and will get you into big trouble if you are caught.)

1.1 Disclaimer

Use the information in this document at your own risk. I disavow any potential liability for the contents of this document. Use of the concepts, examples, and/or other content of this document is entirely at your own risk.
The information in this document should only be used to recover passwords from machines to which you have legal access. If you use this information to break into other people's systems, then I am not responsible for it and you deserve your fate when you are caught.So don't blame me.
You are strongly advised to make a backup of your system before performing any of the actions listed in this document.

1.2 Credits

In this version, I have the pleasure of acknowledging the following people without whose input this would have never seen the light of the day:
  • The creators and maintainers of the various Linux documentation sites using which I gathered this information.
  • Matt Hoskins and Kevin Walsh, for getting me interested in Linux in the first place.
  • My friends and family, for bearing with me when I was compiling this document.

1.3 Before you start

Before you attempt to change or replace the password of any machine, make sure you get permission from the management authorizing it, 'cause otherwise it can be mistaken as an attempt to hack into the machine, which is not good.
Secondly, create a backup of all important data before you do anything else, so if anything goes wrong you'll still have a copy of your data. If you didn't, and something went wrong, don't blame me. I tested most of this stuff on my system and it worked, but you are responsible for your system, not me, so don't blame me if something did go wrong.

2.1 Various Options available

There are various methods available for resetting a root password. In this section, I will list all the major ones, and we will go over each in detail later in the document. I will also go over some steps to prevent some other person from doing this and hacking your machine.
The various methods are:
  • Boot into single-user mode (easiest, least risky)
  • Boot using a boot disk and edit the password file
  • Mount the drive on another computer and edit the password file

2.1.1 Reseting passwords by booting into single-user mode

This is the easiest and the fastest method to reset passwords. The steps are a little different depending on if you are using GRUB or LILO as a bootmanager.
Booting into single-user mode from LILO
Follow these steps to reset the password when using LILO:
  • Reboot the system. When you see the LILO: prompt (see Fig. 1 below), type in linux single and press 'Enter'. This will log you in as root in single-user mode. If your system requires you to enter your root password to log in, then try linux init=/bin/bash instead.
  • Once the system finishes booting, you will be logged in as root in single-user mode. Use passwd and choose a new password for root.
  • Type reboot to reboot the system and then you can login with the new password you just selected.
Lilo Boot Menu
Figure 1. Lilo Boot Menu
If you have a new version of LILO which gives you a menu selection of the various kernels available press Tab to get the LILO: prompt and then proceed as shown above.
Booting into single user mode from GRUB
Follow these steps to reset the password when using GRUB:
  • Reboot the system, and when you are at the selection prompt (See Fig. 2 below), highlight the line for Linux and press 'e'. You may only have 2 seconds to do this, so be quick.
  • This will take you to another screen where you should select the entry that begins with 'kernel' and press 'e' again.
  • Append ' single' to the end of that line (without the quotes). Make sure that there is a space between what's there and 'single'. If your system requires you to enter your root password to log into single-user mode, then append init=/bin/bashafter 'single'. Hit 'Enter' to save the changes.
  • Press 'b' to boot into Single User Mode.
  • Once the system finishes booting, you will be logged in as root. Use passwd and choose a new password for root.
  • Type reboot to reboot the system, and you can login with the new password you just selected.
GRUB boot screen
Fig. 2: GRUB Boot Screen

2.1.2 Reseting passwords by using a boot disk and editing the password file

This method is a little bit more complicated than the previous one and has a very high chance of success (assuming your filesystem is not encrypted and you didn't forget the password to decrypt it if it is). As before, get permission before you do this.
To start, you need a Linux boot disk or a rescue disk. (If you didn't create one when prompted during the installation then let this be a lesson for you.) You can use your installation CD as a rescue disk; most distros have an option to allow you to boot into rescue mode. With my Redhat Linux CD, I have to enter linux rescue to start the rescue mode. But this might be a bit different in each distro. You can also use a live linux CD like Knoppix or Gnoppix for system recovery. (Click here for a list of all the live Linux CD's). In this tutorial I will use Knoppix as my rescue CD but the process is almost the same for any rescue CD you might use.
[ You can also download one of the many single-floppy Linux distributions (e.g., Tom's RootBoot ), and use it to bring up the machine as described. This is, of course, much faster than downloading and burning a rescue CD, especially on a slow connection. -- Ben ]
Follow these steps to reset the password using Knoppix:
  • Reboot the system and configure it to boot from the Knoppix CD (instructions available here)
  • At the Knoppix Boot Prompt (See Fig. 3 below) enter: knoppix lang=us to start boot Knoppix using the english locale. If you understand German, feel free to just hit 'Enter' to boot into Knoppix.
  • Once the system finishes booting, press  + +  (The Control, Alt and F1 key together) to switch to a virtual terminal.
  • Type mkdir mountplace to create a directory called 'mountplace'. This is where we will mount the filesystem.
  • Type mount /dev/hdaX mountplace, where /dev/hdaX is your root partition. More information on Linux partitions is availablehere.
  • Change to the "/etc" directory on your root partition by typing cd mountplace/etc.
  • Use your favorite text editor and open the 'shadow' file for editing. I use 'vi', so I type vi shadow (If you have a really old system, you won't have a shadow file, in which case you need to edit the 'passwd' file.)
  • Scroll down to the line containing the root user's information, which looks something like:
    root:dsfDSDF!s:12581:0:99999:7:::
  • Delete everything between the first and second colons, so that the line looks like:
    root::12581:0:99999:7:::
  • Save the file and exit your editor.
  • Type cd to return to your home directory.
  • Type umount mountplace to unmount the partition.
  • Type reboot to reboot your system, and remove the Knoppix CD from the drive.
  • Now you can log into your system as root with no password. Make sure you change the password immediately.
Knoppix boot screen
Fig. 3: Knoppix Boot Screen

2.1.2 Reseting passwords by mounting on another system and editing the password file

This option is a bit more work than any of the earlier options but is almost sure to work (except when the filesystem is encrypted).
Follow these steps to reset the password:
  • Shut down the machine after backing up all important data.
  • Open the casing, unplug the hard drive, and take it to another machine. (This system should be running Linux, since Windows can't read the Linux partition formats.)
  • Connect the hard disk as a slave drive and boot the new system.
  • Once the system finishes booting, mount the slave drive's root partition as shown above and edit the password file.

3.1 How to Prevent someone else from reseting your root password

If you are an even slightly security-consious sysadmin, the previous sections must have set off alarms while you were reading them. Is it really that easy to hack Linux? Yes and No. It all it comes down to the following: Physical Access is Root Access. Meaning, if you give someone physical access to a system, then you are giving them a very good chance of getting root access on your box. This is true for Windows, Linux, or any other OS out there.
But... you say that you need to give some people physical access to the server? There are some precautions you can take to slow down attackers and stop the noob's. In this section I will talk about various ways you can make your computer more secure against these types of attacks. So lets get started.

3.1.1 Password protecting GRUB and LILO

First, edit the /etc/inittab file and insert the following line, right after the "initdefault" line: ~~:S:wait:/sbin/sulogin. This will require a password to boot into single-user mode by making init run 'sulogin' before dropping the machine to a root shell. 'sulogin' requires the user to input the root password before continuing.
Unfortunately, the above step won't protect us against people who know what they are doing and pass init=/bin/bash to the kernel at the LILO prompt. To prevent unauthorized access I would suggest that you password protect LILO/GRUB by following these steps:
How to Protect LILO:
  • Open a shell prompt and log in as root
  • Open /etc/lilo.conf in your favorite text editor
  • Add the following line before the first image stanza: password= , where is your password.
  • Run /sbin/lilo -v to let the changes take effect
  • Type chmod 600 /etc/lilo.conf to give only root access to read and edit the file since all passwords are in plain text
  • Relax a bit, as your system is a little bit more secure
How to password-protect GRUB
  • Open a shell prompt and log in as root
  • Type /sbin/grub-md5-crypt and press enter
  • Enter the password you chose for GRUB when prompted. This will return an MD5 hash of your password
  • Open /boot/grub/grub.conf in your favorite text editor
  • Add password --md5  below the timeout in the main section (Replace with the hash you got in the previous step)
  • Save and exit
  • The next time you reboot, the GRUB menu will not let you access the editor or command interface without first pressing [p] followed by the GRUB password.

3.1.2 Password-protecting the BIOS

There are two primary reasons for password-protecting the BIOS of a computer:
  • Prevent Changes To BIOS Settings: if an intruder has access to the BIOS, they can set it to boot off of a diskette or CD-ROM.
  • Prevent Booting the System: Some BIOSes allow you to password protect the boot process itself. When activated, an attacker would be forced to enter a password for the BIOS to launch the boot loader.
Because the methods for setting a BIOS password vary between computer manufacturers, you should consult the manual for your computer. If you forget the BIOS password, it can often be reset either with jumpers on the motherboard or by disconnecting the CMOS battery. However, you should check the manual for your computer or motherboard before attempting this procedure.

The PC hard disk layout (About MBR and GRUB)

The PC hard disk layout
The diagram below is the disk layout of my linux laptop which is very standard. There are 4 primary partitions whose size and function are labeled, but this document is going to concentrate on the expanded area in the diagram at the start of the disk. I will describe its structure and how GRUB fits in. Note the structure is the same for windows systems, only the content (grub) is different.
PC hard disk layout

The Master Boot Record

The first sector (512 bytes) is the MBR and consists of, 446 bytes bootloader, 64 bytes partition table and a 2 byte signature (0xAA55). It get its name because it is the first boot record that is loaded, which can then load other boot records from various locations on the disk. To give a hexdump of this first sector of the disk you can do dd bs=512 count=1 if=/dev/hda | od -Ax -tx1z -v (changing /dev/hda as appropriate for your setup):
000000 eb 48 90 d0 bc 00 7c fb 50 07 50 1f fc be 1b 7c  >.H....|.P.P....|<
000010 bf 1b 06 50 57 b9 e5 01 f3 a4 cb be be 07 b1 04  >...PW...........<
000020 38 2c 7c 09 75 15 83 c6 10 e2 f5 cd 18 8b 14 8b  >8,|.u...........<
000030 ee 83 c6 10 49 74 16 38 2c 74 f6 be 10 07 03 02  >....It.8,t......<
000040 80 00 00 80 b8 85 64 00 00 08 fa 80 ca 80 ea 53  >......d........S<
000050 7c 00 00 31 c0 8e d8 8e d0 bc 00 20 fb a0 40 7c  >|..1....... ..@|<
000060 3c ff 74 02 88 c2 52 be 79 7d e8 34 01 f6 c2 80  ><.t...R.y}.4....<
000070 74 54 b4 41 bb aa 55 cd 13 5a 52 72 49 81 fb 55  >tT.A..U..ZRrI..U<
000080 aa 75 43 a0 41 7c 84 c0 75 05 83 e1 01 74 37 66  >.uC.A|..u....t7f<
000090 8b 4c 10 be 05 7c c6 44 ff 01 66 8b 1e 44 7c c7  >.L...|.D..f..D|.<
0000a0 04 10 00 c7 44 02 01 00 66 89 5c 08 c7 44 06 00  >....D...f.\..D..<
0000b0 70 66 31 c0 89 44 04 66 89 44 0c b4 42 cd 13 72  >pf1..D.f.D..B..r<
0000c0 05 bb 00 70 eb 7d b4 08 cd 13 73 0a f6 c2 80 0f  >...p.}....s.....<
0000d0 84 f0 00 e9 8d 00 be 05 7c c6 44 ff 00 66 31 c0  >........|.D..f1.<
0000e0 88 f0 40 66 89 44 04 31 d2 88 ca c1 e2 02 88 e8  >..@f.D.1........<
0000f0 88 f4 40 89 44 08 31 c0 88 d0 c0 e8 02 66 89 04  >..@.D.1......f..<
000100 66 a1 44 7c 66 31 d2 66 f7 34 88 54 0a 66 31 d2  >f.D|f1.f.4.T.f1.<
000110 66 f7 74 04 88 54 0b 89 44 0c 3b 44 08 7d 3c 8a  >f.t..T..D.;D.}<.<
000120 54 0d c0 e2 06 8a 4c 0a fe c1 08 d1 8a 6c 0c 5a  >T.....L......l.Z<
000130 8a 74 0b bb 00 70 8e c3 31 db b8 01 02 cd 13 72  >.t...p..1......r<
000140 2a 8c c3 8e 06 48 7c 60 1e b9 00 01 8e db 31 f6  >*....H|`......1.<
000150 31 ff fc f3 a5 1f 61 ff 26 42 7c be 7f 7d e8 40  >1.....a.&B|..}.@<
000160 00 eb 0e be 84 7d e8 38 00 eb 06 be 8e 7d e8 30  >.....}.8.....}.0<
000170 00 be 93 7d e8 2a 00 eb fe 47 52 55 42 20 00 47  >...}.*...GRUB .G<
000180 65 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 65  >eom.Hard Disk.Re<
000190 61 64 00 20 45 72 72 6f 72 00 bb 01 00 b4 0e cd  >ad. Error.......<
0001a0 10 ac 3c 00 75 f4 c3 00 00 00 00 00 00 00 00 00  >..<.u...........<
0001b0 00 00 00 00 00 00 00 00 5f 00 5f 00 00 00 00 01  >........_._.....<
0001c0 01 00 0b fe 7f 97 3f 00 00 00 59 03 64 00 00 00  >......?...Y.d...<
0001d0 41 98 83 fe 7f a4 98 03 64 00 cd 2f 03 00 00 00  >A.......d../....<
0001e0 41 a5 83 fe ff ff 65 33 67 00 fc 08 fa 00 80 fe  >A.....e3g.......<
0001f0 ff ff 0f fe ff ff 61 3c 61 01 1f ed f2 00 55 aa  >......aU.<
Note there is no mystery about or dissassembly required of the blue section above as GRUB is open source and one can download, inspect and modify its stage 1 source code.

The DOS compatibility region

This region is optional as far as linux is concerned at least, but is added by default by most partition managers. To understand why this region was required we need to describe how disks used to be addressed. Generally now disks are addressed in LBA mode which allows for greater capacity disks while abstracting software away from the specifics of the disk itself. Previously though disks were addressed inCHS mode, which represented the physical construction of the disk as can be seen in the diagram below:
Cylinders Heads Sectors
DOS had the requirement that its image did not span across cylinders, and so this region was added by partition managers so that the first partition was aligned on a cylinder boundary. Therefore this region's size is determined by the number of sectors (512 bytes) per cylinder. The maximum (and usual given todays disk sizes and LBA) sectors per cylinder is 63, which leaves 62 sectors free after the MBR (31,744 bytes).
GRUB uses this region to store its stage 1.5, which is filesystem specific code used to find the operating system image on the "boot" filesystem. Currently GRUB does not need all this space as can be seen for the copies of all the stage 1.5 files in the boot partition:
$ ls -lS /boot/grub/*stage1_5
-rw-r--r--  1 root root 9428 Mar  8 14:27 /boot/grub/reiserfs_stage1_5
-rw-r--r--  1 root root 9308 Mar  8 14:27 /boot/grub/xfs_stage1_5
-rw-r--r--  1 root root 8448 Mar  8 14:27 /boot/grub/jfs_stage1_5
-rw-r--r--  1 root root 7956 Mar  8 14:27 /boot/grub/e2fs_stage1_5
-rw-r--r--  1 root root 7684 Mar  8 14:27 /boot/grub/fat_stage1_5
-rw-r--r--  1 root root 7272 Mar  8 14:27 /boot/grub/ufs2_stage1_5
-rw-r--r--  1 root root 7188 Mar  8 14:27 /boot/grub/minix_stage1_5
-rw-r--r--  1 root root 7028 Mar  8 14:27 /boot/grub/iso9660_stage1_5
-rw-r--r--  1 root root 6996 Mar  8 14:27 /boot/grub/ffs_stage1_5
-rw-r--r--  1 root root 6612 Mar  8 14:27 /boot/grub/vstafs_stage1_5
Therefore one could theoretically use the last 43 sectors of this region (22,016 bytes) for anything. There is no point in creating a filesystem in here as the overhead would be too much, but you could dd stuff in and out like:
dd bs=512 seek=20 count=43 if=myfile of=/dev/hda
dd bs=512 skip=20 count=43 if=/dev/hda of=myfile
Note be very sure you know what your doing before running these commands.
Note on my laptop the last sector of this region contains the first sector of a MSWIN4.1 boot record (which I understand is 3 sectors in total), as it came with winxp installed (in a FAT32 partition). GRUB makes this sector redundant even in a dual boot situation, so don't worry about overwriting it. You can inspect this sector using: dd bs=512 skip=62 count=1 if=/dev/hda | od -Ax -tx1z -v

GRUB 1 boot process

GRUB or the GRand Unified Bootloader is the usual bootloader used on linux systems, and resides on the system as described above. The boot process with GRUB is as follows:
  • BIOS code reads MBR from a disk (looks at last 2 bytes to verify if MBR).
  • Starts executing bootloader code (GRUB stage 1).
  • Bootloader jumps to location (sector num) of next stage. This sector num is stored at a particular location in the bootloader "code" at GRUB install time and usually points to a stage 1.5 located in the "DOS compat space" immediately after the MBR.
  • Stage 1.5 knows about the boot filesystem so it opens the filesystem on the specified (at install time) partition. It looks for the stage 2 executable here and executes it. Note since stage 1.5 knows about the boot filesystem it gives much greater flexibility in upgrading stage 2 and the kernel etc. as their new locations don't need to be written to the earlier GRUB stages.
  • Stage 2 contains most of the GRUB logic. It loads the menu.lst file and executes the statements, usually providing a menu to the user etc.
  • Subsequent steps are distro specific but for completeness I'll describe them for my fedora linux distribution:
  • When GRUB starts booting one of the entries, it reads the initial ramdisk and starts the kernel running telling it about the ramdisk.
  • In the initial ramdisk, the nash shell is run to parse the /linuxrc file. It essentially finds the location of the filesystem it itself is on and passes that to the kernel as its root filesystem. This allows for greater flexibility of the devices the kernel resides on.
  • The kernel reads its root filesystem and executes /bin/init by default. This in turn parses /etc/inittab which usually sets up the login consoles and starts executing the scripts in /etc/init.d
  • These scripts start various subsystems, culminating in starting X. X in turn starts the display manager which gives a login prompt.

GRUB 2 boot process

The structure of GRUB has changed quite a bit with version 2, (which is still in development at the time of writing). Instead of stage 1, stage 1.5 and stage 2 images it has a collection of modules that can be combined in different ways. To mirror the functionality the original GRUB's stages as described above, you would have for example:
stage 1 = boot.img
stage 1.5 = diskboot.img+kernel.img+pc.mod+ext2.mod (the core image)
stage 2 = normal.mod+_chain.mod
The boot process for GRUB 2 then would be:
  • BIOS code reads MBR from a disk (looks at last 2 bytes to verify if MBR).
  • Starts executing bootloader code (boot.img).
  • This loads the first sector of the core image (diskboot.img), whose location was stored at a particular location in boot.img at GRUB install time and usually points to the core image located in the "DOS compat space" immediately after the MBR. diskboot.img in turn loads and executes the rest of the core image.
  • These core image modules know about the boot filesystem and can open the filesystem on the specified (at install time) partition. It looks for and loads modules there, including normal.mod
  • normal.mod loads the grub.cfg file and executes the statements, usually providing a menu to the user etc.
This is a more flexible mechanism. For example one can prepend pxeboot.img to the core image instead of diskboot.img. This will then load the whole core image from the network and then start executing kernel.img.

Synergy

Synergy lets you easily share your mouse and keyboard between multiple computers on your desk, and it's Free and Open Source. Just move your mouse off the edge of one computer's screen on to another. You can even share all of your clipboards. All you need is a network connection. Synergy is cross-platform (works on Windows, Mac OS X and Linux).


http://synergy-foss.org/

fastestmirror


The fastest mirror plugin is designed for use in repository configurations where you have more than 1 mirror in a repo configuration. It makes a connection to each mirror, timing the connection and then sorts the mirrors by fastest to slowest for use by yum.

If you are using the default CentOS configuration, and if you are not behind a proxy server, fastestmirror is highly recommended.

To be able to use this plugin, you must enable plugins in your /etc/yum.conf file, see Yum Plugins for details. Yum plugins are enabled by default starting with CentOS 5.

You can install the fastestmirror plugin by using this command:

yum install yum-plugin-fastestmirror

Or with the following command on CentOS 5:

yum install yum-fastestmirror

After fastestmirror is installed, make sure that it is enabled. Edit the file /etc/yum/pluginconf.d/fastestmirror.conf and ensure that it contains the following lines:

[main]
verbose = 0
socket_timeout = 3
enabled = 1
hostfilepath = /var/cache/yum/timedhosts.txt
maxhostfileage = 1

To exclude a specific mirror, TLD, or something in between, add an 'exclude=' line to /etc/yum/pluginconf.d/fastestmirror.conf:

[main]
...
exclude=.gov, facebook, myspace, junk-mirror.com

With both the protectbase and fastestmirror yum plugins installed, you should get the fastest updates with maximum protection from accidental damage from 3rd party repositories.

CrossOver


Run Windows Applications on Mac or Linux! 

CrossOver allows you to install many popular Windows applications on your Mac or Linux computer. You can think of it as an emulator, but it's different, because there's no Windows OS license required. Your applications integrate seamlessly in OS X or Linux; just click and run. No rebooting, no switching to a virtual machine, and no Windows Operating System license required!
Adding new Windows software is easy. Just place your install CD in your machine, and CrossOver will recognize it and offer to install it. Once installed, CrossOver will configure your application to run on your computer. That's all there is to it.

sed and awk usage


# # # # # # # # # # # # # # # # # #
A description of the basic special characters
# # # # # # # # # # # # # # # # # #

  . (Dot) 
      Newline character (\ n, newline) would match any character except:
      However, awk on the line (\ n) does not specify only the newline character (\ n) is the match come.

 * (Asterisk)
      General characters that match the regular expression does not have a limit on the number of characters (0 to infinity).

 [...] (Brackets)
     All characters in parentheses find a character that matches. For example, [aE] if he, a look or E character.
     - (Hyphen) when using a specific character to a certain point between all the characters are.
     In parentheses, the function of all meta-characters lose their will. ^ Just as the character with the exception of the features there are also.
     ^ (Caret) inside the parentheses! (Not) have the capability. For example, [^] is the 'non-whitespace character is any character point.

 ^ (Caret)
     The beginning of each line indicates. This is not the first character is also important to know.
     Only the beginning of each line will be called. The following is not a newline character in awk.

 $ (Dollar)
     Marks the end of each line. ^ (Caret) as well as the transfer is not a newline character in awk.

 \ {N, m \} (middle brackets)
     Single characters, meta characters shall specify the area that matches the number.
     \ {N \}, saying that the dog is exactly n,
     \ {N, \} n-2, or
     \ {, M \} refers to the m or less,
     \ {N, m \} is at least n, m more or less says.

 \ (Back slash)
     Next character is a special character (Special Character) Indicate that you are.

# # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # #

Replace

:% S / boy / girl / / / edit mode the letters in the file, the entire row of the boy and girl with the task of replacing the letters.

: 5,10 s / boy / girl / g / / 5 through 10 letters to change the row, you could come out in a line more than once to change the option g.

:., 20s/boy/girl / / / current row. Up to 20 rows.

:., $ S / boy / girl / / / current row. In the last row.

:., / Man / s / boy / girl / / / current row. In the next row that contains the letters of the man.

# # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # #

  sed [-e script] [-f script-file] [file ...]

Basic functions have been adopted from the ed, sed all these features are applied to. However, the interactive editor ed is
sed is a stream editor. Streaming, interactive editor and editor of the difference between the input and output is an interactive editor
One is made, a stream editor resulted in the input is the output of one.
\ N for newline character is used as a streaming editor.  

 Find (search), output (print),
    sed-n '/ abd / p' list.txt: list.txt file while reading line by line (-n: Do not print that reads) abd character finds the line output (p) is.

 Replacement (substitute),
    sed 's / addrass / address /' list.txt: addrass a change in address. However, the original file without changing the output is reversed.
     sed 's / addrass / address /' list.txt> list2.txt
     sed 's / \ t / \ /' list.txt: Convert Enterprise taepmunjareul
    sed 's / □ □ * / □ /' list.txt: (* display: □ indicates a space character.) one or more white space the above syntax string and turns it into one space.

 Add (insert)
     scriptfile - s /
     sed-f scriptfile 1.html:

 Delete (delete)
    sed '/ TD / d' 1.html: TD Delete the line containing the character to the output.
     sed '/ Src /! d' 1.html: Src characters do not delete the line.
     sed '1, 2d '1.html: the first one line, two lines, delete.
    sed '/ ^ $ / d 1.html: is the command to delete the blank line
  Regular expressions to extract only the file name
     s / ^. * \ / \ ([a-zA-Z0-9.] * \) ". * $ / \ 1 /: ^ at the beginning of the line. * any string, \ (, \) the regular expressions, grouping, and the top end of the line $.
    (S; ^. * \ / \ ([A-zA-Z0-9.] * \) ". * $; \ 1 ;) \ 1 refers to the first element of the grouped.
                                                                        [A-zA-Z0-9.], And the letters and numbers. (Comma) character to represent (character) says.
       That is the same string as the first group GF02.jpg and I grouped all of the following line is to change the contents. 

  / G: global meaning when there are multiple characters on each line target is to handle.

 who | sed-e 's;. * $;;': the first space of each line deleted from the final make up.

 who | sed-e 's; ^. *;;': from the beginning of each line, delete the last to make space.

 who | sed-e 's; ^. *:;;': from the beginning of each line: where there is a character (:) character) to make deleted.  

 The-n option
 sed on the input received is always stdout found that each line represents. However, sometimes a few lines from a file to extract a sed there are times when you want to use. In this case, use the-n option. This option is exactly what you tell me if you need to print any line you do not want to tell sed. Therefore p is used as the command. Line number and line number by showing a range of lines of text using sed optionally be able to print. As you can see in the next, the first two lines from a file was printed.

 $ Sed-n '1, 2p 'intro Just print the first 2 lines from intro file.

Surrounded by a forward slash instead of the line number sign p command if used with a string of characters that includes sed them through the lines of standard input will be printed. Thus, the first two lines from one file to print can be used as follows.

 $ Sed-n '/ UNIX / p' intro Just print lines containing UNIX
   sed '5 d ': line 5, delete
   sed '/ [Tt] est / d': Test or delete any line that contains the test
   sed-n '20, 25p 'text: text only print from the 20-25 to the line
   sed '1, 10s/unix/UNIX/g 'intro: intro of the first 10 lines of changes to the UNIX unix
   sed '/ jan/s/-1/-5': jan all the lines that contain the first change of -1 to -5
   sed 's / ... / /' data: each data line, delete them from the first three characters
   sed  'S / ... $ / /' data: each data line is deleted from the final 3 characters
   sed-n '1 'text: a non-printing characters \ nn as (where nn is the character of the octal value),
                                                    And tab characters> to print all lines from each text that represents

# # # # # # # # # # # # # # # # # #
awk command
# # # # # # # # # # # # # # # # # #

 awk '/ west /' datafile: west line output in the article

 awk '/ ^ north /' datafile: north of the line that begins with the output

 awk '/ ^ (no | so) /' datafile: no, or so the line that starts with the output

 awk '{print $ 3, $ 2}' datafile: datafile list, and the second field of the third to the clearance space output

 awk '{print $ 3 $ 2}' datafile: datafile third and second fields of the list, just attach the output 

 awk '{print "Number of fields:" NF}' datafile: datafile number of fields each of which returns julmadaui.

 awk '$ 5 ~ / \. [7-9] + /' datafile: fifth field is a number between 7 and 9 periods daeumet the record that at least one output

 awk '$ 2! ~ / E / {print $ 1, $ 2}' datafile: E pattern in the second field of the record is not the first and second field output

 awk '$ 3 ~ / ^ Joel / {print $ 3 "is a nice guy."}' datafile: Joel Starting with the third field "is a nice guy" with the output

 awk '$ 8 ~ / [0-9] [0-9] $ / {print $ 8}' datafile: If two numbers, the eighth field is the field output

 awk '$ 4 ~ / Chin $ / {print "The price is $" $ 8 "." } 'Datafile: After the fourth field in Chine "The price is $" 8 times the output field, and the period

 awk-F: '{print $ 1}' datafile:-F option to enter the field ':' as a distinction.

 awk-F "[:]" '{print $ 1, $ 2}' datafile: input field space and ':' as the field delimiter

 awk-f awk_script.file datafile:-f option when using the awk script file this content.

 awk '$ 7 == 5' datafile: 7 times the field is equal to 5, the output

 awk '$ 2 == "CT" {print $ 1, $ 2}' datafile: 2 times the field "CT" character is equal to 1 and 2 field output

 awk '$ 7 <5 {print $ 4, $ 7}' datafile: 7 times a field is less than 5, 4, 7 field output

 awk '$ 6> .9 {print $ 1, $ 6}' datafile: 6 times a field is greater than 0.9 times, six times the output

 awk '$ 8> 10 && $ 8 <17' datafile    

 awk '$ 2 == "NW" | | $ 1 ~ / south / {print $ 1, $ 2}' datafile

 Redirecting the output / input

     File descriptor 0: standard input
     File descriptor 1: The standard output
     The file descriptor 2: The standard error output
     $ Kill -1 1234> killout.txt 2> & 1: killout.txt as standard output and error output means saying.
     $ Kill -1 1234 1> & 2: the standard error output to the output means saying.

yum (rpmdb: PANIC: fatal region error detected; run recovery)


[root@localhost ~]# yum install squid
Loading "priorities" plugin
Loading "fastestmirror" plugin
Loading "skip-broken" plugin
Loading "protectbase" plugin
Loading "changelog" plugin
Loading "downloadonly" plugin
Loading "allowdowngrade" plugin
Loading "kernel-module" plugin
Loading "tsflags" plugin
rpmdb: PANIC: fatal region error detected; run recovery
error: db4 error(-30977) from dbenv->open: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 -  (-30977)
error: cannot open Packages database in /var/lib/rpm
Traceback (most recent call last):
  File "/usr/bin/yum", line 29, in ?
    yummain.main(sys.argv[1:])
  File "/usr/share/yum-cli/yummain.py", line 85, in main
    base.getOptionsConfig(args)
  File "/usr/share/yum-cli/cli.py", line 163, in getOptionsConfig
    disabled_plugins=self.optparser._splitArg(opts.disableplugins))
  File "/usr/lib/python2.4/site-packages/yum/__init__.py", line 164, in _getConfig
    self._conf = config.readMainConfig(startupconf)
  File "/usr/lib/python2.4/site-packages/yum/config.py", line 685, in readMainConfig
    yumvars['releasever'] = _getsysver(startupconf.installroot, startupconf.distroverpkg)
  File "/usr/lib/python2.4/site-packages/yum/config.py", line 755, in _getsysver
    idx = ts.dbMatch('provides', distroverpkg)
TypeError: rpmdb open failed

[root@localhost ~]# rm -f /var/lib/rpm/__db*
[root@localhost ~]# rpm --rebuilddb
[root@localhost ~]# yum clean all 
Loading "priorities" plugin
Loading "fastestmirror" plugin
Loading "skip-broken" plugin
Loading "protectbase" plugin
Loading "changelog" plugin
Loading "downloadonly" plugin
Loading "allowdowngrade" plugin
Loading "kernel-module" plugin
Loading "tsflags" plugin
Cleaning up Everything
Cleaning up list of fastest mirrors

[root@localhost ~]# yum install squid
Loading "priorities" plugin
Loading "fastestmirror" plugin
Loading "skip-broken" plugin
Loading "protectbase" plugin
Loading "changelog" plugin
Loading "downloadonly" plugin
Loading "allowdowngrade" plugin
Loading "kernel-module" plugin
Loading "tsflags" plugin
Determining fastest mirrors
 * rpmfusion-free-updates-testing: mirror.transact.net.au
 * base: mirror.pscigrid.gov.ph
 * updates: centosz3-msync-dvd.centos.org
 * rpmfusion-free-updates: mirror.transact.net.au
 * addons: mirror.pscigrid.gov.ph
 * extras: mirror.optus.net
rpmfusion-free-updates-te 100% |=========================| 2.8 kB    00:00     
47027e209e5c5c5d58719a490 100% |=========================|  57 kB    00:00     
base                      100% |=========================| 2.1 kB    00:00     
primary.sqlite.bz2        100% |=========================| 1.6 MB    01:34 
updates                   100% |=========================| 1.9 kB    00:00     
primary.sqlite.bz2        100% |=========================| 459 kB    00:04     
rpmfusion-free-updates    100% |=========================| 2.8 kB    00:00     
763a1aa69ace5e0d4f454974f 100% |=========================| 3.0 kB    00:00     
addons                    100% |=========================|  951 B    00:00     
primary.xml.gz            100% |=========================|  201 B    00:00     
extras                    100% |=========================| 1.1 kB    00:00     
primary.xml.gz            100% |=========================| 107 kB    00:02     
extras    : ################################################## 325/325
0 packages excluded due to repository priority protections
0 packages excluded due to repository protections
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package squid.i386 7:2.6.STABLE21-3.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Updating:
 squid                   i386       7:2.6.STABLE21-3.el5  base              1.3 M

Transaction Summary
=============================================================================
Install      0 Package(s)         
Update       1 Package(s)         
Remove       0 Package(s)         

Total download size: 1.3 M
Is this ok [y/N]: y
Downloading Packages:
(1/1): squid-2.6.STABLE21 100% |=========================| 1.3 MB    00:41     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating  : squid                        ######################### [1/2] 
  Cleanup   : squid                        ######################### [2/2] 

Updated: squid.i386 7:2.6.STABLE21-3.el5
Complete!