Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, September 23, 2013

Creating a Swap Partition In Linux

Creating a Swap Partition In Linux


Step 1 ) Create the required partition (say 9 partition)

[root@client1 ~]# fdisk -l

[root@client1 ~]# fdisk /dev/hda
:p
:n
:t  { to change the partition ID}
:82 { for swap partition }
:w  { save & exit }
[root@client1 ~]#
[root@client1 ~]# partprobe /dev/hda

[root@client1 ~]# fdisk –l

Step 2 ) Make the partition as swap

[root@client1 ~]# mkswap /dev/hda9

To see the status

[root@client1 ~]# swapon –s

To on the swap partition

[root@client1 ~]# swapon /dev/hda9

Again  see the status

[root@client1 ~]# swapon -s

To put Off the swap partition

[root@client1 ~]# swapoff /dev/hda9

[root@client1 ~]# swapon –s






Logical Volume Manager


To view the Hard disk name and partition information

[root@client24 ~]# fdisk -l

Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14         523     4096575   83  Linux
/dev/hda3             524         778     2048287+  83  Linux
/dev/hda4             779        4865    32828827+   5  Extended
/dev/hda5             779         905     1020096   83  Linux
/dev/hda6             906        1032     1020096   83  Linux
/dev/hda7            1033        1097      522081   82  Linux swap / Solaris
/dev/hda8            1098        2314     9775521   83  Linux


Create 3 partitions

[root@client24 ~]# fdisk /dev/hda

The number of cylinders for this disk is set to 4865.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (2315-4865, default 2315):
Using default value 2315
Last cylinder or +size or +sizeM or +sizeK (2315-4865, default 4865): +200M

Command (m for help): n
First cylinder (2340-4865, default 2340):
Using default value 2340
Last cylinder or +size or +sizeM or +sizeK (2340-4865, default 4865): +200M

Command (m for help): n
First cylinder (2365-4865, default 2365):
Using default value 2365
Last cylinder or +size or +sizeM or +sizeK (2365-4865, default 4865): +200M




Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

[root@client24 ~]# partprobe /dev/hda

[root@client24 ~]# fdisk -l

Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14         523     4096575   83  Linux
/dev/hda3             524         778     2048287+  83  Linux
/dev/hda4             779        4865    32828827+   5  Extended
/dev/hda5             779         905     1020096   83  Linux
/dev/hda6             906        1032     1020096   83  Linux
/dev/hda7            1033        1097      522081   82  Linux swap / Solaris
/dev/hda8            1098        2314     9775521   83  Linux
/dev/hda9            2315        2339      200781   83  Linux
/dev/hda10           2340        2364      200781   83  Linux
/dev/hda11           2365        2389      200781   83  Linux

Create Physical Volumes

[root@client24 ~]# pvcreate /dev/hda9 /dev/hda10 /dev/hda11
  Physical volume "/dev/hda9" successfully created
  Physical volume "/dev/hda10" successfully created
  Physical volume "/dev/hda11" successfully created

To view Physical Volumes

[root@client24 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/hda9
  VG Name               vg1
  PV Size               196.08 MB / not usable 4.08 MB
  Allocatable           yes (but full)
  PE Size (KByte)       4096
  Total PE              48
  Free PE               0
  Allocated PE          48
  PV UUID               5r8qvn-GF0k-NAfo-Rhqc-I3Qn-ZWws-zLCvks
 
  --- Physical volume ---
  PV Name               /dev/hda10
  VG Name               vg1
  PV Size               196.08 MB / not usable 4.08 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              48
  Free PE               21
  Allocated PE          27
  PV UUID               ys5Wd9-YiQ5-mM7c-sjrt-Mcwb-35oF-8mFyDW
 
  --- Physical volume ---
  PV Name               /dev/hda11
  VG Name               vg1
  PV Size               196.08 MB / not usable 4.08 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              48
  Free PE               48
  Allocated PE          0
  PV UUID               5U81jh-Uddd-0giT-GYUT-pkvu-3MK3-KNkZJi
 
To create Volume Group

[root@client24 ~]# vgcreate vg1 /dev/hda9 /dev/hda10 /dev/hda11
  Volume group "vg1" successfully created

To display Volume Group Information.

[root@client24 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg1
  System ID          
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               576.00 MB
  PE Size               4.00 MB
  Total PE              144
  Alloc PE / Size       75 / 300.00 MB
  Free  PE / Size       69 / 276.00 MB
  VG UUID               P1zXt6-yBWW-SoUq-ZeF1-K7pf-Z69D-GVz8Up
 
To create logical Volume

[root@client24 ~]# lvcreate vg1 -L +300M -n lv1
  Logical volume "lv1" created





To view Logical Volume Information.

[root@client24 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg1/lv1
  VG Name                vg1
  LV UUID                ZvsfPh-Ve0c-y4Qa-VUYy-HbdR-lG3G-66703a
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                300.00 MB
  Current LE             75
  Segments               2
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0
 
[root@client24 ~]#

Format the Logical Volume

[root@client24 ~]# mkfs.ext3 /dev/vg1/lv1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
102400 inodes, 409600 blocks
20480 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
50 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

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

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

[root@client24 ~]# mkdir /mylvm

[root@client24 ~]# mount /dev/vg1/lv1 /mylvm

[root@client24 ~]# mount
/dev/hda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/hda5 on /home type ext3 (rw)
/dev/hda2 on /usr type ext3 (rw)
/dev/hda6 on /var type ext3 (rw)
/dev/hda8 on /dada type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/mapper/vg1-lv1 on /mylvm type ext3 (rw)


To resize the Logical Volume

[root@client24 ~]# lvresize -L +100M /dev/vg1/lv1

Extending logical volume lv1 to 400.00 MB
Logical volume lv1 successfully resized


[root@client24 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg1/lv1
  VG Name                vg1
  LV UUID                ZvsfPh-Ve0c-y4Qa-VUYy-HbdR-lG3G-66703a
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                400.00 MB
  Current LE             100
  Segments               3
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0
 
[root@client24 ~]# cd /mylvm

[root@client24 mylvm]# ls
lost+found

[root@client24 mylvm]# touch file1 file2 file3

[root@client24 mylvm]# mkdir hyd sec

[root@client24 mylvm]# ls
file1  file2  file3  hyd  lost+found  sec

To remove logical Volume

[root@client24 ~]# cd

[root@client24 ~]# umount /mylvm

[root@client24 ~]# lvremove /dev/vg1/lv1

Do you really want to remove active logical volume "lv1"? [y/n]: y
Logical volume "lv1" successfully removed





[root@client24 ~]# fdisk /dev/hda

The number of cylinders for this disk is set to 4865.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (2390-4865, default 2390): +300M
Value out of range.
First cylinder (2390-4865, default 2390): w
First cylinder (2390-4865, default 2390):
Using default value 2390
Last cylinder or +size or +sizeM or +sizeK (2390-4865, default 4865): +300M

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@client24 ~]# partprobe /dev/hda


[root@client24 ~]# fdisk -l

Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14         523     4096575   83  Linux
/dev/hda3             524         778     2048287+  83  Linux
/dev/hda4             779        4865    32828827+   5  Extended
/dev/hda5             779         905     1020096   83  Linux
/dev/hda6             906        1032     1020096   83  Linux
/dev/hda7            1033        1097      522081   82  Linux swap / Solaris
/dev/hda8            1098        2314     9775521   83  Linux
/dev/hda9            2315        2339      200781   83  Linux
/dev/hda10           2340        2364      200781   83  Linux
/dev/hda11           2365        2389      200781   83  Linux
/dev/hda12           2390        2426      297171   83  Linux






[root@client24 ~]# pvcreate /dev/hda12

  Physical volume "/dev/hda12" successfully created

To extend the volume group.

[root@client24 ~]# vgextend vg1 /dev/hda12
  Volume group "vg1" successfully extended

[root@client24 ~]# vgdisplay

  --- Volume group ---
  VG Name               vg1
  System ID          
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               864.00 MB
  PE Size               4.00 MB
  Total PE              216
  Alloc PE / Size       0 / 0
  Free  PE / Size       216 / 864.00 MB
  VG UUID               P1zXt6-yBWW-SoUq-ZeF1-K7pf-Z69D-GVz8Up
 

Looking forward for your suggestions.. please feel free to write to me.. Your help would definitely help to improve our blog. Chetan Yadav

Saturday, September 21, 2013

how to do linux partitions

how to do linux partitions  

Linux Partitions

Step 1 ) To Create the partitions

[root@client1 ~]# fdisk -l

[root@client1 ~]# fdisk /dev/hda

Command (m for help): m
d   delete a partition
      m   print this menu
    n   add a new partition
p   print the partition table
    q   quit without saving changes
    w   write table to disk and exit

Command (m for help):

Command (m for help): n
First cylinder (1098-2434, default 1098):
Using default value 1098
Last cylinder or +size or +sizeM or +sizeK (1098-2434, default 2434): +100M
Command (m for help): p
Command (m for help): n
Command (m for help): p
Command (m for help): n
Command (m for help): p
Command (m for help): d
Command (m for help): 10 #write the number of partition
Command (m for help): w

[root@client1 ~]#

To update the kernel without restarting

[root@client1 ~]# partprobe /dev/hda

[root@client1 ~]# fdisk -l


Step 2 ) Make the filesystem ( i.e format the partition) ext2, ext3, vfat

[root@client1 ~]# mkfs.ext2 /dev/hda8

[root@client1 ~]# mkfs.ext3 /dev/hda9

[root@client1 ~]# mkfs.vfat /dev/hda10









Step 3 ) Create a folder & Mount the partition to use

[root@client1 ~]# mkdir /mnt/song /mnt/video /mnt/music

[root@client1 ~]# mount /dev/hda8 /mnt/song

[root@client1 ~]# mount /dev/hda9 /mnt/video
[root@client1 ~]# mount /dev/hda10 /mnt/music

[root@client1 ~]# mount

Step 4 ) Write the data inside the partition

[root@client1 ~]# cd /mnt/song

[root@client1 song]#

[root@client1 song]# touch myfile1 myfile2 myfile3

[root@client1 song]# mkdir hyd sec bhills ameerpet

[root@client1 song]# ls

*****************  This is the output  ********************

ameerpet  bhills  hyd  lost+found  myfile1  myfile2  myfile3  sec
[root@client1 myfolder]#

Converting from ext3 to ext2

[root@client1 ~]# umount /dev/hda8

[root@client1 ~]# tune2fs -O ^has_journal /dev/hda8

[root@client1 ~]# mount /dev/hda8 /myfolder/

[root@client1 ~]# mount

Convert from ext2 to ext3

[root@client1 ~]# umount /dev/hda8

[root@client1 ~]# tune2fs -j /dev/hda8

[root@client1 ~]# mount /dev/hda8 /myfolder

[root@client1 ~]# mount



Looking forward for your suggestions.. please feel free to write to me.. Your help would definitely help to improve our blog. Chetan Yadav

Thursday, September 19, 2013

Basic Linux Command


Basic Linux  Commands


1. To check the present working directory

 [root@database ~]# pwd
/root

2. To show the contents of a directory (folder)

[root@database ~]# ls
3145.zip  args1    database_notes  Documents   ifcfg-eth1_March25  linux_image.iso  names         phonenubers  uln_migrate             uln_register.tar
args      BegPerl  Desktop         hello2.plx  index.html.1        mbox             oradiag_root  scripts    

3. To see more details including the permission regarding the contents of a
directory (folder)

[[root@database ~]# ls -l
total 3511620
-rw-r--r--  1 root   root       422670 Dec 30 10:29 3145.zip
-rwxr--r--  1 root   root          105 Apr  8 21:45 args
-rwxr--r--  1 root   root           32 Apr  8 21:51 args1
drwxr-xr-x 17 root   root         4096 Dec 30 10:31 BegPerl
-rw-r--r--  1 root   root         5022 Jan  5 09:55 database_notes
drwxr-xr-x  3 root   root         4096 Mar 25 04:45 Desktop
drwx------  3 root   root         4096 Mar 30 21:33 Documents

3. To see all contents including hidden files of a directory (folder)

[root@database ~]# ls -a
.              .bashrc         .eggcups         .gstreamer-0.10     mbox                 scripts                 uln_register.tar             .xauthgXJKsS
..             BegPerl         .elinks          .gtkrc-1.2-gnome2   .metacity            .sqldeveloper           .vboxclient-clipboard.pid    .xauthixsRh6




4. To see tree structure of nested directories

[root@database ~]# ls -R /opt
/opt:
ORCLfmap
sqldeveloper
sun
VBoxGuestAdditions-4.2.6

/opt/ORCLfmap:
prot1_32

/opt/ORCLfmap/prot1_32:
bin
etc
log

/opt/ORCLfmap/prot1_32/bin:
Fmputl

To see a file starting from f

[root@database ~]# ls f*

To see a file have a middle string as disk

[root@database ~]# ls /bin/*disk*

To see a file whose length is 3 charaters

[root@database ~]# ls ???

To see a file which starts with single char & ends up with any number of character

[root@database ~]# ls ?edh*

5. To create a file
[root@database ~]# cat > file1
hi how are you

6. To see file content
[root@database ~]# cat file1

hi how are you


7. To append a file

[root@database ~]  cat >> file1
iam fine, it is very nice

[root@database ~] cat file1 file2 >> file3 #redirecting output to file3

[root@database ~] cat file3

8. To create a file using touch command

[root@database ~]# touch f1 f2 f3 f4

[root@database ~]# ls

9. Creating a single directory

[root@database ~]# mkdir dir

10. Creating multiple directories

[root@database ~]# mkdir dir1 dir2 dir3 dir4

[root@database ~]# ls

anaconda-ks.cfg  dir   dir2  dir4  f2  f4     file2  install.log      
labmanual
Desktop          dir1  dir3  f1    f3  file1  file3  install.log.syslog

11. To create nested directories

[root@database ~]# mkdir -p d1/d2/d3/d4

To see the tree structure

[root@database ~]# ls -R d1
d1:
d2

d1/d2:
d3

d1/d2/d3:
d4

d1/d2/d3/d4:




12. To change a directory

[root@database ~]# cd dir1

[root@database ~]# cd ..

[root@database ~]# cd ../..

[root@database ~]# cd -
/root

[root@database ~]# pwd
/root

[root@database ~]# cd

[root@database ~]# pwd
/root

[root@database ~]#

13. To remove files

[root@database ~]# rm file1

rm: remove regular file `file1'? y

14. To remove an empty directory

[root@database ~]# rmdir dir1

[root@database ~]# ls
anaconda-ks.cfg  Desktop  dir2  dir4  f2  f4     file3        install.log.syslog
d1               dir      dir3  f1    f3  file2  install.log  labmanual

15. To remove a directory
[root@database ~]# rm -rf dir

[root@database ~]# ls
anaconda-ks.cfg  Desktop  dir3  f1  f3  file2  install.log         labmanual
d1               dir2     dir4  f2  f4  file3  install.log.syslog

To copy files

[root@database ~]# cp anaconda-ks.cfg file1

To copy folders

[root@database ~]# cp -r dir2 Desktop

To rename  directories and files

[root@database ~]# mv dir3 d4


[root@database ~]# ls
anaconda-ks.cfg  d4       dir2  f1  f3  file1  file3        install.log.syslog
d1               Desktop  dir4  f2  f4  file2  install.log  labmanual

To move directories and files

[root@database ~]# mv dir2 /opt

[root@database ~]# ls
anaconda-ks.cfg  d4       dir4  f2  f4     file2  install.log         labmanual
d1               Desktop  f1    f3  file1  file3  install.log.syslog


[root@database ~]# cd /opt

[root@database ~]#  ls
dir2

To search a word from single or multiple file’s

[root@database ~]# grep tom  /etc/passwd /etc/group /etc/gshadow

/etc/passwd:tom:x:500:500::/home/tom:/bin/bash
/etc/group:tom:x:500:
/etc/gshadow:tom:!::

[root@database ~]# cat /etc/passwd | grep tom

To see the type of file

[root@database ~]# file *

To view the date

[root@database ~]# date

[root@database ~]# date -s "07/15/2008 00:06:00 "
 mm/dd/yyyy hh:mm:ss
Tue Jul 15 00:06:00 EDT 2008

[root@database ~]# cal

[root@database ~]# cal 12 2008

[root@database ~]# man mkdir

[root@database ~]# man cal

To see the content screen wise

[root@database ~]# ls -l /bin  | less


Visual Interface (VI)


Commands to Go into Insert mode

To open a file use vi

e.g.
# vi test.txt

i   -  inserts the text at current cursor position
I   -  inserts the text at  beginning of line
a   -  appends the text after current cursor position
A   -  appends the text at end of line
o   -  inserts a line below current cursor position
O   -  inserts a line above current cursor position
r   -  replace a single char at current cursor position

Commands at execute mode

:q -  quit without saving
:q!   -  quit forcefully without saving
:w   -  save
:wq   -  save & quit
:wq! -  save & quit  forcefully
:x -  save & quit
:sh -  Provides temporary shell
:se nu -  Setting line numbers
:se nonu -  Removing line numbers
:84   -  Press enter goes to line 84

To move the cursor, press the h,j,k,l keys as indicated.    
             ^
             k              Hint:  The h key is at the left and moves left.
       < h       l >               The l key is at the right and moves right.
             j                     The j key looks like a down arrow
             v

w forward   word to word
b     back side word to word

Command's at command mode

dd   -  Deletes a line
2dd   -  Deletes 2 lines
yy   -  Copy a line
2yy   -  Copies 2 lines
p -  put  (deleted or copied text)
u -  Undo (can undo 1000 times)
Ctrl+r -  Redo
G - Moves cursor to last line of file
5G - Moves cursor to 5th line of file
Shift+ZZ -  save & quit
/ -  locate word


To find and replace words
:1,$s///gc

e.g.
:1,$s/world/universe/gc
 
1-- To start the search at from 1st line
$ -> End of File
s -> substitute
g -> global
c -> confirmation

To power off machine

# poweroff


Looking forward for your suggestions.. please feel free to write to me.. Your help would definitely help to improve our blog. Chetan Yadav