Monday, April 20, 2009

step-by-step SUDO in linux

http://www.linuxhelp.net/guides/sudo/

Sunday, April 19, 2009

Step-By-Step Configuration of NAT with iptables

http://www.howtoforge.com/nat_iptables

Replacing Hard disk in RAID 1

http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array

http://www.howtoforge.com/how-to-resize-raid-partitions-shrink-and-grow-software-raid

http://lists.us.dell.com/pipermail/linux-poweredge/2003-July/008898.html

Personally I would give milions hi5 to above link ;-)

Implementing RAID in LINUX

Create a RAID Device /dev/md4 by creating equal two disks from available free space on your harddisk and mount it on /data. 


Let's say we have /dev/hdd as our added disk and we don't have extra harddisk.. becoz i am poor guy and i can't buy new disk during the current economic recession ;-)
I can create two partitions which can be treated as two disks for the RAID implementation.

Create the Two partitions having equal size.

Change the Partition ID to fd (Linux raid Autodetect)


#fdisk /dev/hdd
........
.........
/dev/hdd3            2001        2500      252000   fd  Linux raid autodetect
/dev/hdd4            2501        4161      837144    5  Extended
/dev/hdd5            2501        3000      251968+  fd  Linux raid autodetect
.......

Use partprobe command to synchronic the partition table. 

[root@localhost ~]# partprobe

[root@localhost ~]# mdadm --create /dev/md4 --level=1 --raid-devices=2 /dev/hdd3 /dev/hdd5
mdadm: array /dev/md4 started.

[root@localhost ~]# mkfs -t ext3 /dev/md4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
62992 inodes, 251904 blocks
12595 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
31 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks: 
8193, 24577, 40961, 57345, 73729, 204801, 221185

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


[root@localhost ~]# mkdir /data

[root@localhost ~]# cd /data
[root@localhost data]# ls
lost+found

(which implies that /dev/md4 is sucessfully mounted )

http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array





Why SGID bit?

Who ever creates the files/directories on /mygrpdir group owner should be 

automatically should be the same group owner of /mygrpdir. 


1.     chmod g+s /mygrpdir

2.     Verify using: ls -ld /mygrpdir 

Permission should be like: 

drwxrws--- 2 root sysusers 4096 Mar 16 18:08 /mygrpdir 


If SGID bit is set on directory then who every users creates the files on directory group 

owner automatically the owner of parent directory. 

 

To set the SGID bit: chmod g+s directory 

To Remove the SGID bit: chmod g-s directory 

Extending and Reducing LV in LINUX

Lets extend the size of  testlv

[root@localhost ~]# lvdisplay /dev/testvg/testlv
  --- Logical volume ---
  LV Name                /dev/testvg/testlv
  VG Name                testvg
  LV UUID                jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                100.00 MB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0


[root@localhost ~]# umount /dev/testvg/testlv 

[root@localhost ~]# fsck -f /dev/testvg/testlv 
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/25792 files (9.1% non-contiguous), 8927/102400 blocks

[root@localhost ~]# lvextend -L +150M /dev/testvg/testlv 
  Rounding up size to full physical extent 152.00 MB
  Extending logical volume testlv to 252.00 MB
  Logical volume testlv successfully resized


[root@localhost ~]# resize2fs /dev/testvg/testlv 
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/testvg/testlv to 258048 (1k) blocks.
The filesystem on /dev/testvg/testlv is now 258048 blocks long.


[root@localhost ~]# lvdisplay /dev/testvg/testlv 
  --- Logical volume ---
  LV Name                /dev/testvg/testlv
  VG Name                testvg
  LV UUID                jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                252.00 MB
  Current LE             63
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0



****************************************************
After we are done with increasing the size of testlv, let's reduce the size of testlv

[root@localhost ~]# umount /dev/testvg/testlv

[root@localhost ~]# fsck -f /dev/testvg/testlv
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/63488 files (9.1% non-contiguous), 14193/258048 blocks

[root@localhost ~]# resize2fs /dev/testvg/testlv 150M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/testvg/testlv to 153600 (1k) blocks.
The filesystem on /dev/testvg/testlv is now 153600 blocks long.


[root@localhost ~]# lvreduce -L 150M /dev/testvg/testlv 
  Rounding up size to full physical extent 152.00 MB
  WARNING: Reducing active logical volume to 152.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testlv? [y/n]: y
  Reducing logical volume testlv to 152.00 MB
  Logical volume testlv successfully resized

[root@localhost ~]# lvdisplay /dev/testvg/testlv 
  --- Logical volume ---
  LV Name                /dev/testvg/testlv
  VG Name                testvg
  LV UUID                jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                152.00 MB
  Current LE             38
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0



(have u noticed the sequence of commands: lvextend and resize2fs commands are in different order for two different operations. Keep only one thing in mind, resize2fs should be run before lvextend while reducing the size of LV )

Sunday, April 12, 2009

Step by Step guide: Manage additional disk on Linux using LVM

Let's we have physical drive connected in slave of secondary IDE i.e /dev/hdd

#fdisk /dev/hdd (and create following partitions with id:8e)

Device Boot Start End Blocks Id System
/dev/hdd1 1 1000 503968+ 8e Linux LVM
/dev/hdd2 1001 2000 504000 8e Linux LVM

[root@localhost ~]# pvcreate /dev/hdd1 /dev/hdd2
Physical volume "/dev/hdd1" successfully created
Physical volume "/dev/hdd2" successfully created

[root@localhost ~]# pvdisplay [compare with the o/p of same command after creating f/s of LV]
"/dev/hdd1" is a new physical volume of "492.16 MB"
--- NEW Physical volume ---
PV Name /dev/hdd1
VG Name
PV Size 492.16 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID lanTX2-t6KC-MTID-Ag8V-un2g-R6a9-janMLC

"/dev/hdd2" is a new physical volume of "492.19 MB"
--- NEW Physical volume ---
PV Name /dev/hdd2
VG Name
PV Size 492.19 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID W29vIo-K2SN-07Zl-3Xn8-1pDX-hkxQ-P3gk2h


[root@localhost ~]# vgcreate testvg /dev/hdd1 /dev/hdd2
Volume group "testvg" successfully created


[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 980.00 MB
PE Size 4.00 MB
Total PE 245
Alloc PE / Size 0 / 0
Free PE / Size 245 / 980.00 MB
VG UUID TbRxlH-zYl9-Y3zz-tsEH-1ASj-1uma-qhVLo8


[root@localhost ~]# lvcreate -L 124M -n testlv testvg [creating LV of size 124M with name testlv ]
Logical volume "testlv" created

[root@localhost ~]# lvdisplay /dev/testvg/testlv
--- Logical volume ---
LV Name /dev/testvg/testlv
VG Name testvg
LV UUID jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
LV Write Access read/write
LV Status available
# open 0
LV Size 124.00 MB
Current LE 31
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0


[root@localhost ~]# mkfs -t ext3 /dev/testvg/testlv [ creating filesystem ]
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
31744 inodes, 126976 blocks
6348 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
16 block groups
8192 blocks per group, 8192 fragments per group
1984 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@localhost lvmmntpt]# pvdisplay
--- Physical volume ---
PV Name /dev/hdd1
VG Name testvg
PV Size 492.16 MB / not usable 4.16 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 122
Free PE 122
Allocated PE 0
PV UUID lanTX2-t6KC-MTID-Ag8V-un2g-R6a9-janMLC

--- Physical volume ---
PV Name /dev/hdd2
VG Name testvg
PV Size 492.19 MB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 123
Free PE 92
Allocated PE 31
PV UUID W29vIo-K2SN-07Zl-3Xn8-1pDX-hkxQ-P3gk2h

[root@localhost lvmmntpt]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 980.00 MB
PE Size 4.00 MB
Total PE 245
Alloc PE / Size 31 / 124.00 MB
Free PE / Size 214 / 856.00 MB
VG UUID TbRxlH-zYl9-Y3zz-tsEH-1ASj-1uma-qhVLo8

[root@localhost lvmmntpt]# lvdisplay /dev/testvg/testlv
--- Logical volume ---
LV Name /dev/testvg/testlv
VG Name testvg
LV UUID jFiX1B-SL0k-bZZ3-yHMb-zO4h-OySU-1Sw3a9
LV Write Access read/write
LV Status available
# open 1 [ here open is 1 because it's mounted]
LV Size 124.00 MB
Current LE 31
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

[root@localhost ~]# vi /etc/fstab
…....
…....
/dev/testvg/testlv /lvmmntpt ext3 defaults 0 0


[root@localhost ~]# mount -a

[root@localhost ~]# cd /lvmmntpt/

[root@localhost lvmmntpt]# ls
lost+found
(It indicates successful mounting of newly created LV )