Friday, December 26, 2008

WORKING WITH TAPE DRIVES


Naming of SCSI tape device

The st driver provides the interface to a variety of SCSI tape devices under Linux.

  • First (auto rewind) SCSI tape device name: /dev/st0
  • Second (auto rewind) SCSI tape device name: /dev/st1
  • First the non-rewind SCSI tape devices: /dev/nst0
  • Second the non-rewind SCSI tape devices: /dev/nst1


Naming of IDE tape device

The ht driver provides the interface to a variety of IDE tape devices under Linux.

  • First (auto rewind) IDE tape device name: /dev/ht0
  • Second (auto rewind) IDE tape device name: /dev/ht1
  • First the non-rewind IDE tape devices: /dev/nht0
  • Second the non-rewind IDE tape devices: /dev/nht1

 

Find out at which block you are with mt command:

 

# mt -f /dev/st0 tell

 

 

Check if tape drive is online: # mt -f /dev/st0 status

OUTPUT :

SCSI 2 tape drive:

File number=0, block number=0, partition=0.

Tape block size 0 bytes. Density code 0x40 (DLT1 40 GB, or Ultrium).

Soft error count since last status=0

General status bits on (41010000):

BOT ONLINE IM_REP_EN

 

Rewind tape drive:# mt -f /dev/st0 rewind

 

Erase tape drive: # mt -f /dev/st0 erase

Copy some content to a tape drive : # tar -cvf /dev/st0 /content_path/content.archive

List files on a tape
: # tar -tvf /dev/st0

Restore from the tape: # tar -xvf /dev/st0

Restore an specific archive: # tar xvf /dev/st0 /folder/archive.dmp

 

Backup directory /www and /home with tar command (z - compressed):

# tar -czf /dev/st0 /www /home

 

Restore /www directory:

# cd /
# mt -f /dev/st0 rewind
# tar -xzf /dev/st0 www

 

Unload the tape:

# mt -f /dev/st0 offline

 

You can go BACKWARD or FORWARD on tape with mt command itself:
Go to end of data:# mt -f /dev/nst0 eod

Goto previous record:# mt -f /dev/nst0 bsfm 1

Forward record:# mt -f /dev/nst0 fsf 1

 

tar backup on tape through ssh

# tar -cvzf /www | ssh root@station.domain.com "cat > /backup/www.tar.gz"

OR

# tar zcvf - /www | ssh root@192.168.1.101 "cat > /backup/www.tar.gz"

Output:

tar: Removing leading `/' from member names
/www/
/www/n/xx.in/
/www/c/zasx.asd/
....
..
 

You can also use dd command for clarity purpose:

# tar cvzf - /www | ssh root@192.168.1.101 "dd of=/backup/www.tar.gz"

It is also possible to dump backup to remote tape device:

# tar cvzf - /www | ssh ssh root@192.168.1.101 "cat > /dev/st0"

OR

you can use mt to rewind tape and then dump it using cat command:

# tar cvzf - /www | ssh ssh root@192.168.1.101 $(mt -f /dev/st0 rewind; cat > /dev/st0)$

You can restore tar backup over ssh session:

# ssh root@192.168.1.101 "cat /backup/www.tar.gz" | tar zxvf - 

Thursday, December 4, 2008

How To Create LVM Partition

Hello Friends,

 

My friend asked me a query regarding the LVM Creation with a new harddisk. So i thought that it might be helpfull to all my friends using LVM on Linux.

 

To create LVM partition when we have a new hard disk installed on our server/system.

 

STEP 1. fdisk /dev/hdb    // create a partition in second HD

 

Now show the partition table on your system using p command.

 

Command (m for help): p          // show partition table


OUTPUT
Disk /dev/hdb: ---.- GB, xxxxxxxxxx bytes
xxxx heads, xx sectors/track, xxxxxx cylinders
Units = cylinders of xxxxx * xxx = xxxxxxxx bytes
 
Device Boot   Start   End   Blocks   Id   System     
 

// nothing

 

Create a new partition using n option

 

Command (m for help): n     // create partition

Command action
  e    extended
  p    primary partition (1-4)

p    // primary

Partition number (1-4): 1   // partition number


First cylinder (x-xxxxx, default 1):   // First cylinder


Using default value 1  Last cylinder or +size or +sizeM or +sizeK (x-xxxxx, default xxxxx):    // Last cylinder


Using default value xxxxx

 

After creation of new partition we need to see our partition table.

 

Command (m for help):  p   // show partition table

 

OUTPUT
Disk /dev/hdb: xxx.x GB, xxxxxxxxxxxx bytes
xxx heads, xx sectors/track, xxxxx cylinders
Units = cylinders of xxxxxxx * xxx = xxxxxxx bytes
 
   Device Boot Start End      Blocks   Id  System 
  /dev/hdb1      x   xxxxx  xxxxxxxxxx 83  Linux     // created

 

Command (m for help): t      // change partition type

Selected partition 1    // number

Hex code (type L to list codes): L    // show list of type

 

Hex code (type L to list codes): 8e    // Linux LVM


Changed system type of partition 1 to 8e (Linux LVM)
 
Command (m for help): p    // show partition table

 

OUTPUT
Disk /dev/hdb: xxx.x GB, xxxxxxxxxxx bytes
xxx heads, xx sectors/track, xxxxx cylinders
Units = cylinders of xxxxx * xxx = xxxxxxxxx bytes
 
Device Boot Start  End       Blocks         Id      System

/dev/hdb1     x     xxxxx    xxxxxxxx   8e   Linux LVM    // changed

 
Command (m for help):  w    // save and exit

 


STEP 2. fdisk -l /dev/hdb // show status

 

 

STEP 3. Now we need to create Physical Volume

 

pvcreate /dev/hdb1      // create Physical Volume

 

If we need to specify partition size, use command as below

 

pvcreate --setphysicalvolumesize 100G /dev/hdb1

 

 

To display status of Physical volume (Optional)

 

pvdisplay /dev/hdb1        // display status

 

STEP 4. We can change the volume size of Physical volume (Optional)

 

pvresize --setphysicalvolumesize 100G /dev/hdb1

 

STEP 5. To show the physical volume

pvs /dev/hdb1

 

STEP 6.  To Scan the Physical volume

pvscan  /dev/hdb1

 

 

Now we can create Logical Volume, using the following steps.

 

1.     lvcreate –L 10G –n lvm1 vg0

2.     lvdisplay // to display the logical volumes.

3.     lvextend –L 20G /dev/vg0/lvm1

4.      resize2fs /dev/vg0/lvm1   //Most important thing to do in last 

 


Note: Here i have used xxx for any number, depands on the size of the harddisk.