Yum local repository to be able to access a CDROM/DVD iso.

You do not have access to the network and you would like to install some packages from CDROM/DVD, please follow the instructions:

First take a backup of /etc/yum.repos.d/ then remove these repo files:
CentOS-Base.repo, CentOS-Debuginfo.repo and CentOS-Media.repo
and add a new file called CentOS_local.repo with the following lines:

[root@localhost yum.repos.d]# cat CentosOS_local.repo
[dvd]
name=Centos DVD
baseurl=file:///media #mount location
enabled=1
gpgcheck=0
[root@localhost yum.repos.d]#

Here baseurl=file:///media is the location of CentOS iso. Now you have to mount your CentOS iso into the media folder:

[root@localhost]# mount /dev/cdrom /media

Once this is done, you can go ahead with yum to install packages from CD/DVD.

RAID in Linux, using mdadm in Linux.

Linux software RAID has nothing to do with hardware RAID controllers. You don’t need an add-on controller, and you don’t need the onboard controllers that come on most motherboards.

The RAID  devices  are virtual devices created from two or more real block devices. This allows multiple devices (typically disk drives or partitions thereof) to be combined into a single device to hold (for example) a single filesystem.
Some RAID levels include redundancy and  so  can  survive some degree of device failure.

Currently, Linux supports LINEAR md devices, RAID0 (striping), RAID1 (mirroring), RAID4, RAID5, RAID6, RAID10, MULTIPATH, FAULTY, and CONTAINER.
Continue reading “RAID in Linux, using mdadm in Linux.”

Increase an ext2/3 partition without lossing data.

Resize ext3 partition using resize2fs which support ext3.

root@deb:/disk# ls -la
total 664228
drwxr-xr-x 3 root root 4096 Dec 19 18:29 .
drwxr-xr-x 22 root root 4096 Dec 19 17:19 ..
-rwxrwxrwx 1 nobody nogroup 679477248 Nov 26 11:31 debian-6.0.3-i386-CD-1.iso
drwx------ 2 root root 16384 Dec 19 17:18 lost+found
root@deb:/disk#

There is an ISO of Debian system. I don’t want loose it 🙂
Continue reading “Increase an ext2/3 partition without lossing data.”

Find file by access, change or modify time.

How to find files that were last modified 10 days ago, use:
root# find / -iname "*" -mtime -10 -print

How to find files that were last modified 10 days ago and for each of them do stat:
root# find / -iname "*" -mtime -10 -exec stat {} ;

How to find files that were last modified 24 hours ago and move them to some directory:
root# find / -name "*.png" -mmin -1440 -exec mv {} some_directory ;

How to find all files in your home directory modified or created today. By default, find counts days from midnight, so an age of zero means today.
user~> find ~ -type f -mtime 0

Find all file belongs to group “ftpusers” in /home directory, enter:
root# find /home -group ftpusers

Find all file belongs to user root in / directory
root# find / -user root

Find files and directories that are not owned by user, use:
find ~ ! -user ${USER}

Find anything in the current user’s directory that is not owned by that user and fix the permissions:
find ~ ! -user $USER -exec sudo chown ${USER}:"{}" ;

Find file and redirect errors to /dev/null
find / -name "apache2" -print 2>/dev/null


Other options:
access (read the file’s contents) – atime
change the status (modify the file or its attributes) – ctime
modify (change the file’s contents) – mtime

LVM – create, resize, remove, scan, reduce, etc.

LVM enables flexible distribution of hard disk space over several file systems. It was developed because the need to change the segmentation of hard disk space might arise only after the initial partitioning has already been done during installation. Because it is difficult to modify partitions on a running system, LVM provides a virtual pool (volume group or VG) of memory space from which logical volumes (LVs) can be created as needed. The operating system accesses these LVs instead of the physical partitions.
Continue reading “LVM – create, resize, remove, scan, reduce, etc.”

Spying on the console.

Some software prints error messages to the console that may not necessarily show up on your SSH session. Using the vcs devices can let you examine these. From within an SSH session, run the following command on a remote server:

# cat /dev/vcs1

This will show you what is on the first console. You can also look at the other virtual terminals using 2, 3, etc. If a user is typing on the remote system, you’ll be able to see what he typed.

SSH login without password.

If you need to login from a serverA to a serverB using no password.

First what you have to do is login to a serverA as a user to generate a pair of authentication keys.
Do not enter a passphrase!

user@serverA:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Created directory '/home/user/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
90:48:02:a5:3a:55:28:91:e2:29:7d:f8:e6:93:a1:e4 user@serverA
user@serverA:~>

Now use the ssh to create a directory ~/.ssh as a user “user” on a serverB. The directory may already exist there, in this case do not create that directory:

user@serverA:~> ssh user@serverB mkdir -p .ssh
user@serverB password:

Finally copy a new public key to user@serverB .ssh/authorized_keys and enter the userB password the last time:

user@serverA:~> cat .ssh/id_rsa.pub | ssh user@serverB 'cat >> .ssh/authorized_keys'
user@serverB password:

From now, you can login to a serverB as a user “user” from a serverA without typing a password.

Network File System in Debian.

Installing NFS in Debian

Making your computer an NFS server or client is very easy. The Debian NFS client needs:

# apt-get install nfs-common portmap

while a Debian NFS server needs:

# apt-get install nfs-kernel-server nfs-common portmap

NFS Server Configuration.

NFS exports from a server are controlled by the file /etc/exports. Each line begins with the absolute path of a directory to be exported, followed by a space-seperated list of allowed clients.

/etc/exports
/home 192.168.1.2(rw,no_root_squash) www.domain.com(ro)
/usr 192.168.1.2/24(ro,insecure)

A client can be specified either by name or IP address. Wildcards (*) are allowed in names, as are netmasks (e.g. /24) following IP addresses, but should usually be avoided for security reasons.

A client specification may be followed by a set of options, in parenthesis. It is important not to leave any space between the last client specification character and the opening parenthesis, since spaces are intrepreted as client seperators.

For each options specified in /etc/exports file can be check export man pages.
If you make changes to /etc/exports on a running NFS server, you can make these changes effective by issuing the command:

# exportfs -a

NFS Client Configuration

NFS volumes can be mounted by root directly from the command line. For example:

# mount files.domain.com:/home /mnt/nfs

mounts the /home directory from the machine files.domain.com as the directory /mnt/nfs on the client. Of course, for this to work, the directory /mnt/nfs must exist on the client and the server must have been configured to allow the client to access the volume.

It is more usual for clients to mount NFS volumes automatically at boot-time. NFS volumes can be specified like any others in /etc/fstab.

/etc/fstab
192.168.1.3:/home /home nfs rw,rsize=4096,wsize=4096,hard,intr,async,nodev,nosuid 0 0
192.168.1.3:/usr /usr nfs ro,rsize=8192,hard,intr,nfsvers=3,tcp,noatime,nodev,async 0 0

There are two kinds of mount options to consider: those specific to NFS and those which apply to all mounts. Consider first those specific to NFS.

For each options menctioned in /etc/fstab file check the man pages of fstab.

How to mount SMB/CIFS/Windows shares under Linux.

Just type:
apt-get install smbfs
then use the mount command to mount remote windows partition or windows share under Linux as follows:

mount -t cifs //192.168.1.10/download -o username=julia,password=julia /mnt/Julia

or with all rwx permissions:

mount -t cifs //192.168.1.10/download -o iocharset=utf8,file_mode=0777,dir_mode=0777,username=julia,password=julia /mnt/Julia

also you can add it to /etc/fstab (make it “automatic”)

//192.168.1.10/download /mnt/Julia smbfs auto,username=julia,password=julia,uid=1000,umask=000,user 0 0

but the better way is keep your username & password in a file only readable by root

//192.168.1.10/download /mnt/Julia cifs credentials=/root/.mnt_Julia,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

what should be in .mnt_Julia and how to make it:

touch /root/.mnt_Julia
echo "username=julia" >> /root/.mnt_Julia
echo "password=julia" >> /root/.mnt_Julia