Linux Share your tips

~uNIx~

Disciple
Post your cool tips in this thread so it helps many newbies to linux :D

i post many tips here and on TA since i joined so now u all nix lovers post tips :)
 
one tip from a Demon too,

never think that u'll learn it very fast nd specially when u r turning from windows,
so u should try to spent more & more time to learn it insted of formating ur portion,

nd yes for help we all r here
 
Some very common tips ...

Resetting the root password

If you have forgotten your root password, it is pretty difficult to recover it from within the installed system, but you can use a bootable linux cd or floppy to set it to blank.

Note - the cd/floppy's kernel should have support for components like your processor, hard drive and filesystem being used.

Basic instructions - Boot into your cd/floppy, and mount your linux / partition (or /etc if you created a seperate partition for that) at a partition point like /mnt. Edit the /mnt/etc/passwd file, and blank out the encrypted password in the line for the root user.

Detailed instructions - After booting the cd/floppy, mount your linux partition usng the command

mount /dev/hda1 /mnt

Replace /dev/hda1 with the linux partition.

Incase this gives a problem recognising the filesystem, use the -t switch to specify the fs type, like ext2 or resierfs. Also make sure the directory /mnt exists, else create it.

Edit the file /mnt/etc/passwd with vi or any other editor

vi /mnt/etc/passwd

blank out the password field (it will possibly be marked with x), such that the line looks like

root::0:0:root:/:/bin/bash

Note that the two colons after the first word "root" indicates a blanked out password.

Reboot into linux, login as root, you wont be asked a password. Use the passwd command to set a new password.
 
Fixing LILO (the linux loader) badk in place

Reboot into a rescue cd/floppy, just like in the previous case, and mount your partitions.

Now, you have to "chroot" to your linux installation partition, that is, change the location of the / partition on the floppy to your linux installation partition.

chroot /mnt

That is, after you mount your linux partition on /mnt

Now edit the /etc/lilo.conf file if neccessary (this will be the case where you have freshly installed windows, or moved the linux partitions etc) and then restore lilo by running -

/sbin/lilo
 
ya good nice tips there ujjwal :)
all newbies may ask for specific tips :)

here some tips for newbies to linux i will add more later since me in hurry lol:

========================
TIPS For LINUX Newbies
=======================
To erase the MBR use this command:
dd if=/dev/zero of=/dev/hda bs=446 count=1

WARNING If you type bs(block size)=512 then it will wipe out your partition table !

~~
To create ISO image of /home/example/ use this command:
mkisofs -T -r -J -o /home/example.iso /home/example

To mount ISO images for eg. "if the example.iso is located in /home" then use this command.
mkdir /home/iso ; mount -o loop /home/example.iso /home/iso

~~
If you want to make a bootdisk to boot the system:
fdformat /dev/fd0H1440
mkbootdisk `uname -r`

~~
If you want to create a partition of 100MB with ext3 file system on hda --> Primary master HDD
fdisk /dev/hda
n <------for new partition
l <-----for logical or p <---- for primary
type default cylinder
+100M
w <-- to write the partition table
partprobe
fdisk -l
mkfs -t ext3 /dev/hdaxx <--- x=partition number of the newly created partition of 100MB

~~~
To mount a partition for example hda1(FAT32) or cdrom:
mkdir /mnt/hda1 ; mount /dev/hda1 /mnt/hda1
cd /mnt/hda1 ; ls

For cdrom:
mount /dev/cdrom /mnt/cdrom
cd /mnt/cdrom ; ls

For Floppy:
mount /dev/fd0 /mnt/floppy

To unmount hda1:
umount /mnt/hda1

To unmount cdrom
cd /
umount /mnt/cdrom ; eject

To mount hda1 everytime system boots:
kwrite /etc/fstab
Add this entry:
/dev/hda1 /mnt/hda1 vfat defaults 0 0

To aply the changes to fstab use command:
service netfs restart

Also
man mount
man fstab
~~~
To shutdown the machine:
init 0 or shutdown or poweroff or halt
To restart:
init 6 or reboot
To boot in graphical mode from text mode:
startx or init 5

also:
man shutdown or man halt
~~~

bye
 
About that root password thingy...
is it possible to do that from booting into linux in single user mode? Much easier than all the bootable floppy / cd stuff
 
Yeah, it should be possible to enter single user mode by typing "linux 1" at the LILO prompt, but some systems ask you for the root password anyway for entering this mode ... I think Abhay had written about this in his security guide, with instructions on securing your system to prevent people getting access to the single user mode. If you can enter the single user mode, then there is no need of a floppy or cd :)
 
Taking screenshots using simple command line tools

Sure, its simple to use The Gimp or KSnapshot to take linux screenshots, but many a time one may not want to use these heavy and cumbersome tools for a simple thing.

Make sure you have ImageMagick installed (its a versatile console based image manipulation toolset), else get it from http://www.imagemagick.org/

Now, you can use the command

import -window root screen.jpg

You can also specify a single windows of which to capture an image (root captures whole screen)

To view the image, type

display screen.jpg

Timed screenshots

Now for the fun part, we shall use the sleep command to get the screenshot after a small delay, so that we can arrange the screen the way we like ;)

sleep 5 ; import -window root screen2.jpg

This statement will first execute "sleep", so it will go idle for 5 seconds, in which you can do what you like, and then execute "import" to capture your screen.

Also, Captura is a simple tool to get screenshots, and it is vert easy to use

http://www.hernansoft.com/downloads_en.html
 
For prompting root password when entering single user mode:

Open the "/etc/inittab" file with a text editor and add a new entry below "id:x:initdefault:" where x=3,5
Code:
id:x:initdefault:
~~:S:wait:/sbin/sulogin

Regards.
 
Tuning IDE HDD:

first install hdparm package:

rpm -ivh hdparm.version.rpm

Add this line in /etc/rc.local

Code:
/sbin/hdparm -q -c3 -K1 -k1 /dev/hdx
where x = a b c or d

To find settings of your drive:
Code:
hdparm -i /dev/hda

Regards.
 
Good tips there ferrar! :) hdparm is a great boon if you happen to posess a slow processer or disk ...

Also check the manpage of hdparm for info

man hdparm

To enable a setting temporarily, enter "hdparm [options] /dev/hdx". For permanent results save the settings in a script like rc.local :)

You may want to experiment with differentsettings to see the result, use the following to test the disk speeds before and after -

hdparm -tT /dev/hdx

x is a for first hard drive, b for second etc.
 
Mounting your Windows/DOS partitions with specific permissions

DOS partitions do not support file system permissions, unlike linux ones, so while mounting them, they get a set of default permissions, and these may not be the ones desired.

In this example, FAT partitions will be mounted with permissions such that the root user can read/write to them, while other users have read-only access.

To mount the partitions, create the directories /mnt/dos/c, d, etc. Add a line to the bottom of the fstab file (/etc/fstab) -

Code:
/dev/hda1 /mnt/dos/c vfat umask=022 0 0

hda1 indicates the first primary partition of the first hard drive. Use hda5 for D drive, hda6 for E etc.

Basically, umask "masks" the write permission for all other users, apart from root.

Read up on file system permissions and umask (man chmod, man umask) for more info, and to customise the permissions.
 
Although defragmentation of common linux filesystems is rarely needed, if you feel that a particular folder is slow to access, because of file fragmentation (package manager cache, directories in /var may be prone to this), there is a really simple way to defragment it. Simply copy it to a temporary folder, delete the original, and then move the copy to replace the original.

If the directory is called /var/cache

Code:
cp -r /var/cache /var/cachebackup
rm -r /var/cache
mv /var/cachebackup /var/cache

Courtesy : http://bbs.archlinux.org/viewtopic.php?t=11840
 
Back
Top