Copy files/folders accross a network in Linux using ssh, tar, scp and rsync.

SCP or secure copy is probably the easiest of all the methods, its is designed as a replacement for rcp, which was a quick copy of cp with network funcationability. Before scp does any copying it first connects via ssh. SCP encrypts data over your network connection, but by using the -C switch you can compress the data before it goes over the network. This can significantly decrease the time it takes to copy large files.

scp -r directory user@server:~/

or default port

scp "-P 7787" -r directory user@server:~/

TAR is usually used for achiving applications, but what we are going to do in this case is tar it then pipe it over an ssh connection. TAR handles large file trees quite well and preserves all file permissions, and works quite well with symlinks.

tar -czf - directory | ssh -p 7787 user@server tar -xzf - -C .

or default port

tar -czf - directory | ssh user@server tar -xzf - -C .

or

tar -xzf - directory | ssh user@server "cat > /directory/tarball.tar.gz"

or

dpkg -l | ssh user@server "cat > /directory/dpkg-list.txt"

RSYNC speciality lies in its ability to analyse files and only copy the changes made to files rather than all files. This can lead to enormous improvements when copying a directory tree a second time.

rsync -avze "ssh -p 7787" directory user@server:~/

or default port

rsync -avze ssh directory user@server:~/

Mounting a NetWare volume on a Linux box

To mount a NetWare volume on a Linux box, the ncpfs must to be installed on a Linux box.
For a “rpm” distribution:

yum install ncpfs

For a “deb” distribution:

apt-get install ncpfs

then try mount the volume on the Linux box:

ncpmount -A 192.168.1.25 -S name_of_netware_server -V volumin_to_mount -U username.context -P password /mnt

to add this to /etc/fstab please use the following:

nbcs_data_server/xxhr.genacc.ndsadmin /share/Shared/XXHR/EBSPROD ncp volume=data/Shared/XXHR/EBSPROD,uid=ebsprod,gid=dba,mode=660,owner=root,A=nbcs_gisdata_server,passwdfile=/etc/edirpass 0 0

and create an edirpass password file in /etc/edirpass

echo "nbcs_gisdata_server/xxhr.genacc.ndsadmin:password" >> /etc/edirpass

Broken Grub menu – Debian.

Broken Grub menu: boot to the menu, drop to a consloe and boot Debian direct.
Sometimes the only thing that works when you boot is the Grub menu appears on your screen.
When you see Grub’s boot menu on your screen, instead fo selecting a boot item, press the “c” key.
That brings up a messages like this:

GNU GRUB version 1.99-14
Minimal BASH-like line editing is supported. For the firs word,
TAB lists possible command completions. Anywhere else TAB lists
posssible device or file completions. ESC at any time exits.

grub>

Now carry out the following commands at the grub prompt:

grub> search.file /sbin/init
hd0,msdos1
grub> search.file /boot/grub/device.map
hd0,msdos1
grub> search.file /vmlinuz
hd0,msdos1

Whatever you use, will ok. What we looking for is:
– Grub pointer to my Debian installation on drive number 1, partition number 1, your pointer
will be different from my example (hd0,msdos1)
– UUID assigned to this partition 625b756b-737e-4502-a914-9d351d50603a


grub> ls (hd0,msdos1)
Partition hd0,msdos1: Filesystem type ext2 - Last modification time
2012-01-11 10:57:44 Wednesday, UUID 625b756b-737e-4502-a914-9d351d50603a -
Partition start at 2048 - Total size 40134656 sectros
grub> set root='(hd0,msdos1)'
grub> linux /boot/vmlinuz-{press TAB key}
Possible files are:
vmlinuz-2.6.32-5-686 vmlinuz-3.2.0-1-686-pae
grub> linux /boot/vmlinuz-3.2.0-1-686-pae ro root=UUID=625b756b-737e-4502-a914-9d351d50603a
grub> initrd /boot/initrd.img-{press TAB key}
Possible files are:

initrd.img-2.6.32-5-686 initrd.img-3.2.0-1-686-pae
grub> initrd /boot/initrd.img-3.2.0-1-686-pae
grub> boot

and the machine boots 🙂

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.”

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.”

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

Turn off periodic FSCK at booting time.

Forces drives to be checked once for every 30 times the filesystem is mounted. This means that on an average, once every 30 times you bootup your computer, the filesystem integrity is checked.
To disable filesystem integrity check forever do:

$sudo tune2fs -c -1 `mount | awk '$3 == "/" {print $1}'`

or

$sudo tune2fs -c -1 /dev/yourhdd

but if you don’t want disable filesystem check forever, only for the next bootup, create a file called /fastboot.

$sudo touch /fastboot

will disable filesystem check for the next time you bootup. Since the /fastboot file is removed during bootup, this will disable filesystem check only once – for the one time you bootup after you create the /fastboot file
On the contrary to force a filesystem check the next time you bootup, create a file called /forcefsck by doing

$sudo touch /forcefsck