Friday, January 9, 2015

Test/Development Database Refresh From Production Procedure

Test/Development Database Refresh From Production Procedure

The following note describes the generic procedure to be followed to refresh a Energy Test or Development environment database from a Energy production database backup.

In this example, we are refreshing the DEVE72 database from a backup taken of the PRD22 database.

The assumption here is that the required RMAN production backup has already been either copied from the production database via scp or has been restored from tape or has been placed in an NFS shared location which is accessible from both machines.

On the target machine the backups have been restored in the location u02/backup/DEVE72


Procedure:

Shutdown the DEVE72 database if it is already running


[oracle@DEVE72 DEVE72]$ ps -ef |grep pmon
oracle 12701 29275 0 15:36:00 pts/3 0:00 grep pmon
oracle 7377 2235 0 May 19 ? 84:59 ora_pmon_DEVE72

[oracle@DEVE72 DEVE72]$ echo $ORACLE_SID
DEVE72


[oracle@DEVE72 DEVE72]$ sqlplus sys as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Thu Jun 17 15:36:22 2010

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Enter password:

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

Delete the database data files, redo log files and control files

Note:

**Ensure we are connected to the right server and are in the appropriate directory location**


[oracle@DEVE72 DEVE72]$ hostname
DEVE72

[oracle@DEVE72 DEVE72]$ pwd
/u03/oradata/DEVE72

[oracle@DEVE72 DEVE72]$ rm *.dbf

[oracle@DEVE72 DEVE72]$ cd /u04/oradata/DEVE72

[oracle@DEVE72 DEVE72]$ ls
control2.ctl redo01a.log redo02a.log redo03a.log

[oracle@DEVE72 DEVE72]$ rm *.ctl
[oracle@DEVE72 DEVE72]$ rm *.log
[oracle@DEVE72 DEVE72]$ cd /u05/oradata/DEVE72
[oracle@DEVE72 DEVE72]$ ls
control3.ctl redo01b.log redo02b.log redo03b.log


Copy the current init.ora parameter file of the DEVE72 database and create a parameter file with the name of the source production database (PRD22)

[oracle@DEVE72 ~]$ cd $ORACLE_HOME/dbs

[oracle@DEVE72 dbs]$ pwd
/u01/app/oracle/product/10.2.0/db_1/dbs

[oracle@DEVE72 dbs]$ cp initDEVE72.ora initprd22.ora

Make the following changes to the initprd22.ora

*.db_name='prd22'


Set the environment to reflect the source production database and start the instance in NOMOUNT mode

[oracle@DEVE72 dbs]$ export ORACLE_SID=prd22
[oracle@DEVE72 dbs]$ sqlplus sys as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Mon Jun 21 12:58:32 2010

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Enter password:
Connected to an idle instance.


SQL> startup nomount pfile=$ORACLE_HOME/dbs/initprd22.ora
ORACLE instance started.

Total System Global Area 3154116608 bytes
Fixed Size 2043904 bytes
Variable Size 637538304 bytes
Database Buffers 2499805184 bytes
Redo Buffers 14729216 bytes
SQL> quit


Restore the control file from the backup location

The control file backup exists in the format “c-<DBID>-<DATE>-<BACKUP SEQUENCE NUMBER>

Select the controlfile appropriate to the period of time that we wish to restore the database from

[oracle@DEVE72 DEVE72]$ rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Fri Jun 18 11:05:20 2010

Copyright (c) 1982, 2007, Oracle. All rights reserved.

connected to target database: prd22 (not mounted)

RMAN> restore controlfile from '/u02/backup/DEVE72/c-4031762323-20100616-00';

Starting restore at 18-JUN-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=538 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:06
output filename=/u03/oradata/DEVE72/control1.ctl
output filename=/u04/oradata/DEVE72/control2.ctl
output filename=/u05/oradata/DEVE72/control3.ctl
Finished restore at 18-JUN-10


Mount the database

RMAN> alter database mount
2> ;

database mounted
released channel: ORA_DISK_1


Catalog the RMAN backup sets which have been copied from the source production database

RMAN> catalog start with '/u02/backup/DEVE72';

searching for all files that match the pattern /u02/backup/DEVE72

List of Files Unknown to the Database
=====================================
File Name: /u02/backup/DEVE72/c-4031762323-20100616-00
File Name: /u02/backup/DEVE72/21lgatsk_1_1
File Name: /u02/backup/DEVE72/c-2263349373-20100419-00
...
...

Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u02/backup/DEVE72/c-4031762323-20100616-00
File Name: /u02/backup/DEVE72/21lgatsk_1_1
File Name: /u02/backup/DEVE72/2flgdi89_1_1
...
...

List of Files Which Where Not Cataloged
=======================================
File Name: /u02/backup/DEVE72/c-2263349373-20100419-00
RMAN-07518: Reason: Foreign database file DBID: 2263349373 Database Name: DEVE72


Note – ignore any errors reported for files that are not cataloged


Determine the last archivelog sequence included in the backup. We will be recovering the database until this particular sequence number.

Look for the string "List of archived logs"

RMAN > list backup of archivelog all

List of Archived Logs in backup set 69
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 79 7970987 16-JUN-10 7973402 16-JUN-10

In this case, the last archivelog backed up belongs to sequence number 79. If we wish to recover the database until the last archived log which has been backed up, we need to increment the last sequence number by 1. So in this case it will be 79+1 or 80

Create the following files in the location “/u02/backup/{DB_NAME}”

vi rman_head

RUN
{
# allocate a channel to the tape device
ALLOCATE CHANNEL d1 DEVICE TYPE disk;

# rename the datafiles and online redo logs



vi rman_tail

# Do a SET UNTIL to prevent recovery of the online logs
SET UNTIL SEQUENCE 80;

# restore the database and switch the datafile names
RESTORE DATABASE;
SWITCH DATAFILE ALL;

# recover the database
RECOVER DATABASE;
}

vi generate_datafiles.sql

set head off pages 0 feed off echo off verify off
set lines 200
spool rename_datafiles.lst
select 'SET NEWNAME FOR DATAFILE ' || FILE# || ' TO ''' || '/u03/oradata/&1/' || substr(name,instr(name,'/',-1)+1) || ''';' from v$datafile;
spool off
exit;

vi generate_logfiles.sql

set head off pages 0 feed off echo off
spool rename_logfiles.lst
SELECT 'SQL "ALTER DATABASE RENAME FILE '''''|| MEMBER ||'''''' ||chr(10)||'to ''''' || member || '''''" ;' FROM V$LOGFILE;
exit


Generate data file rename script

While in directory /u02/backup/{DB_NAME}, connect as sys as sysdba via SQL*PLUS session and run the generate_datafiles.sql script.

The generate_datafiles.sql script accepts a parameter which is the target database name.

SQL> @generate_datafiles DEVE72

It will create a file rename_datafiles.lst . The contents of this file will be like this:

SET NEWNAME FOR DATAFILE 1 TO '/u03/oradata/DEVE72/system01.dbf';
SET NEWNAME FOR DATAFILE 2 TO '/u03/oradata/DEVE72/undotbs01.dbf';
SET NEWNAME FOR DATAFILE 3 TO '/u03/oradata/DEVE72/sysaux01.dbf';
….
….

Generate redo log file rename script

While in directory /u02/backup/{DB_NAME}, connect as sys as sysdba via SQL*PLUS session and run the generate_logfiles.sql script.

SQL> @generate_logfiles.sql

It will create a file called rename_logfiles.lst

Edit the rename_logfiles.lst file and change values of prd22 to DEVE72


SQL "ALTER DATABASE RENAME FILE ''/u04/oradata/prd22/redo01a.log'' to ''/u04/oradata/DEVE72/redo01a.log''" ;

SQL "ALTER DATABASE RENAME FILE ''/u05/oradata/prd22/redo01b.log'' to ''/u05/oradata/DEVE72/redo01b.log''" ;

SQL "ALTER DATABASE RENAME FILE ''/u04/oradata/prd22/redo02a.log'' to ''/u04/oradata/DEVE72/redo02a.log''" ;

SQL "ALTER DATABASE RENAME FILE ''/u05/oradata/prd22/redo02b.log'' to ''/u05/oradata/DEVE72/redo02b.log''" ;

SQL "ALTER DATABASE RENAME FILE ''/u04/oradata/prd22/redo03a.log'' to ''/u04/oradata/DEVE72/redo03a.log''" ;

SQL "ALTER DATABASE RENAME FILE ''/u05/oradata/prd22/redo03b.log'' to ''/u05/oradata/DEVE72/redo03b.log''" ;


Specify the archive log sequence until which recovery will be performed

Edit the rman_tail file and change the line with the words “>> SET UNTIL SEQUENCE 80” to include the appropriate archive log sequence which was noted in an earlier step.

Prepare the RMAN restore and recover database script

[oracle@DEVE72 DEVE72]$ cat rman_head rename_datafiles.lst rename_logfiles.lst rman_tail > rman_recovery.rcv


Connect to the target database via RMAN and execute the rman_recovery.rcv script

[oracle@DEVE72 dbs]$ rman target /

Recovery Manager: Release 10.2.0.4.0 - Production on Mon Jun 21 13:04:04 2010

Copyright (c) 1982, 2007, Oracle. All rights reserved.

connected to target database (not started)

RMAN> @rman_recovery.rcv


Note:

At this stage, we can continue to recover the database and keep it in sync with the source production database by manually applying the archive log files which are copied from the production server to the log archive destination of the test
database on the target server.

We can do this via SQL*PLUS connected as SYS by issuing the command

RECOVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE

When there are no more archive log files to apply, we enter CANCEL

Open the database with RESETLOGS

After the RMAN script has successfully run and recovered the database until the last archive log sequence, we will now open the database using the ALTER DATABASE OPEN RESETLOGS command executed either via RMAN or from SQL*PLUS connected as SYS.

SQL> alter database open resetlogs;

Database altered.

Temporary Tablespace Reconfiguration

After the restore, we will note that the temporary tablespace files are still pointing to the source production database as these tempfiles have not been renamed when we renamed all the database data files in an earlier step.

Obtain the name of the current tempfile -

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------
/u03/oradata/prd22/temp01.dbf

Drop the tempfile-

SQL> ALTER DATABASE TEMPFILE '/u03/oradata/prd22/temp01.dbf' drop including datafiles;

Database altered.

Add a new tempfile for the refreshed database in the appropriate location-

SQL> ALTER TABLESPACE temp ADD TEMPFILE '/u03/oradata/DEVE72/temp01.dbf' size 2G;

Tablespace altered.

At this stage we will change the passwords if required for the SYS and SYSTEM or any other database accounts.

Change the database name using nid

We will now shutdown the database and then mount it.

We will then run the nid utility to change the database name – we need to provide the appropriate password for the user SYS and the new value we want for the database name.

[oracle@DEVE72 dbs]$ nid target=sys dbname=DEVE72

DBNEWID: Release 10.2.0.4.0 - Production on Fri Jun 18 13:55:14 2010

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Password:
Connected to database PRD22 (DBID=4031762323)

Connected to server version 10.2.0

Control Files in database:
/u03/oradata/DEVE72/control1.ctl
/u04/oradata/DEVE72/control2.ctl
/u05/oradata/DEVE72/control3.ctl

Change database ID and database name PRD22 to DEVE72? (Y/[N]) => Y

Proceeding with operation
Changing database ID from 4031762323 to 2271553224
Changing database name from PRD22 to DEVE72
Control File /u03/oradata/DEVE72/control1.ctl - modified
Control File /u04/oradata/DEVE72/control2.ctl - modified
Control File /u05/oradata/DEVE72/control3.ctl - modified
Datafile /u03/oradata/DEVE72/system01.dbf - dbid changed, wrote new name
Datafile /u03/oradata/DEVE72/undotbs01.dbf - dbid changed, wrote new name
Datafile /u03/oradata/DEVE72/sysaux01.dbf - dbid changed, wrote new name
Datafile /u03/oradata/DEVE72/users01.dbf - dbid changed, wrote new name

...
...
...

Datafile /u03/oradata/DEVE72/COGNOSPAD_CLOB01.dbf - dbid changed, wrote new name
Datafile /u03/oradata/DEVE72/temp01.dbf - dbid changed, wrote new name
Control File /u03/oradata/DEVE72/control1.ctl - dbid changed, wrote new name
Control File /u04/oradata/DEVE72/control2.ctl - dbid changed, wrote new name
Control File /u05/oradata/DEVE72/control3.ctl - dbid changed, wrote new name
Instance shut down

Database name changed to DEVE72.
Modify parameter file and generate a new password file before restarting.
Database ID for database DEVE72 changed to 2271553224.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.


At this stage the database has been shutdown and now we need to mount it and issue the RESETLOGS command after the database change.

Note:

We will now set the environment to the target database (until this stage, for example, ORACLE_SID had been set to the production database value)

[oracle@DEVE72 backup] export ORACLE_SID=DEVE72

[oracle@DEVE72 backup]$ sqlplus sys as sysdba

SQL*Plus: Release 10.2.0.4.0 - Production on Mon Jun 21 14:12:00 2010

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Enter password:
Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 3154116608 bytes
Fixed Size 2043904 bytes
Variable Size 637538304 bytes
Database Buffers 2499805184 bytes
Redo Buffers 14729216 bytes


SQL> alter database open resetlogs;

Database altered.

Post Database Refresh Tasks

Create import and export directories required for Data Pump

/u02/export/{DB_NAME} - export_dir
/u02/import/{DB_NAME} - import_dir

RMAN – run the appropriate script to register details in the RMAN catalog database where required.

Monday, December 8, 2014

Getting Yesterdays or Tomorrows Day With Bash Shell Date Command

Getting Yesterdays or Tomorrows Day With Bash Shell Date Command


When invoked without arguments, the date command displays the current date and time. Depending on the options specified, date will set the date and time or print it in a user defined way. I've seen many sysadmin writing perl scripts for calculating relative date such as yesterdays or tomorrows day. You can use GNU date command, which is designed to handle relative date calculation such as:
  • 1 Year
  • 2 Days
  • 2 Days ago
  • 5 Years
The syntax is as follows:
 
date  --date="STRING"
date  --date="next Friday"
date  --date="2 days ago"
 
The --date=STRING is a human readable format such as "next Thursday" or "1 month ago". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers.

Why Use Relative GNU/date Formats?

  • Ease of use
  • Write your own shell scripts
  • Automate task using cron (example run a job on last day of the month or Nth day of the month or 3rd Friday and so on)

Examples

First, to display today's date, enter:
$ date
Sample outputs:
Wed Jun 15 04:47:45 IST 2011
To display yesterday's date, enter:
$ date --date="1 days ago"
OR
$ date --date="1 day ago"
OR
$ date --date="yesterday"
OR
$ date --date="-1 day"

Adding Disks under Linux

Adding Disks under Linux

Once the disk has been physically connected, the system should detect it during the boot process. The dmesg command can be used to check the boot messages:

  Vendor: HP        Model: C3724S            Rev: 5173
  Type:   Direct-Access                      ANSI SCSI revision: 02
Detected scsi disk sdc at scsi0, id 3, lun 0

Device nodes

It may be necessary to create device nodes for the new disk. Under Linux, device nodes use the format /dev/[r]sdXN, where X is a letter specifying the drive number (with a being the lowest SCSI ID, bbeing the next highest, etc), and N is the partition number on that drive. The MAKEDEV command is used to create new device nodes. For example, to create a device node for the third SCSI disk:

# cd /dev; MAKEDEV sdc

It is important to note that disk ordering is done at boot time, so there is not a direct mapping between the letter used to identify the drive and the SCSI ID of that drive. If the SCSI ID of the new drive is lower than that of one of the existing drives, the naming scheme for all of the higher-numbered will be changed, possibly causing problems in the /etc/fstab configuration.

Partitioning

Partitioning and labeling a disk under Linux is done with the fdisk command. There is also a screen-oriented version called cfdisk, which has essentially the same commands.
For instructions on how to use fdisk to partition a drive, see the Linux Installation and Getting Started guide, particularly the section on Creating Linux partitions

Making new filesystems

To create a new filesystem on the disk, use the mkfs command:
# mkfs -t ext2 /dev/sdc1
This will create an ext2 type filesystem on the third SCSI disk, first partition.
To check the new filesystem for integrity, use fsck# fsck -f -y /dev/sdc1 The -f option forces fsck to check the new filesystem, even if it is considered to be clean. The -y option tells fsck to assume a "yes" answer to any questions normally posed to the user.

Adding Disks under Solaris

Adding Disks under Solaris

Once the disk has been physically installed, the system should recognize a new device on the SCSI bus. After powering up the system, hold down the Stop key (on some Suns, this is labeled L1), and hit the A key to enter the boot monitor.
At the boot monitor, probe-scsi can be used to list the SCSI devices the system recognizes:

Type 'go' to resume
Type help for more information
ok probe-scsi
   .
          .
Target 5
  Unit 0  Disk     HP        C37245       5153
          .
          .

Note: on some older Suns, it may be necessary to enter "n" at the boot monitor to enter the newer command mode before probing for disks.
After verifying that the new disk is recognized by the system, reboot the machine by issuing "boot -r" from the boot monitor. The -r option tells the system to reconfigure for the new device.
During the boot process, the new disk should be recognized and a message should be printed to the console. (On some Suns, it may not be printed to the screen, but will be written to the system log -- in this case, the dmesg command should be used to review the boot messages). The messages should be similar to this:

   sd5 at esp0: target 5 lun 0
   sd5 is /iommu@f,e0000000/sbus@f,e0001000/espdma@f,400000/esp@f,800000/sd@5,0
   WARNING: /iommu@f,e0000000/sbus@f,e0001000/espdma@f,400000/esp@f,800000/sd@5,0 (sd5):  
    corrupt label - wrong magic number
    Vendor 'HP', product 'C3724S', 2354660 512 byte blocks 

In this example, the disk is located on controller 0, SCSI ID 5. The "corrupt label" warning means that the disk doesn't have a Solaris label on it yet.

Device nodes

The correct device nodes for the disk are automatically added when a "boot -r" is issued. If the system hasn't been rebooted using the -r option, here is a script that will configure the system for the new disk.

Formatting, Partitioning and Labeling

The format utility is used to format, partition, and label disks. It is menu driven. The raw disk device is given as an argument; if no argument is given, format will print a list of available disks and ask the user to pick one.

# format /dev/rdsk/c0t5d0s2
selecting /dev/rdsk/c0t5d0s2
[disk formatted]
 
 
FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        quit

Typing format at the prompt will perform a low-level format on the disk. This is usually not necessary with a new disk, since they generally come pre-formatted, but may help to map out any additional defects the drive may have developed.
The next step is to partition the drive. Type partition at the prompt to switch to the partition menu:

format> partition

PARTITION MENU:
        0      - change `0' partition
        1      - change `1' partition
        2      - change `2' partition
        3      - change `3' partition
        4      - change `4' partition
        5      - change `5' partition
        6      - change `6' partition
        7      - change `7' partition
        select - select a predefined table
        modify - modify a predefined partition table
        name   - name the current table
        print  - display the current table
        label  - write partition map and label to the disk
        quit

Type in print to get a listing of the current partition table. Note that the second partition represents the entire disk:

partition> print
Current partition table (original):
Total disk cylinders available: 3361 + 2 (reserved cylinders)
 
Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       0               0         (0/0/0)          0
  1 unassigned    wm       0               0         (0/0/0)          0
  2     backup    wu       0-3360          1.12GB    (3361/0/0) 2352700
  3 unassigned    wm       0               0         (0/0/0)          0
  4 unassigned    wm       0               0         (0/0/0)          0
  5 unassigned    wm       0               0         (0/0/0)          0
  6 unassigned    wm       0               0         (0/0/0)          0
  7 unassigned    wm       0               0         (0/0/0)          0
 

We will be splitting the disk up into two equal partitions, numbers 3 and 4. The first partition will span cylinders 0 through 1680, the second will span cylinders 1681 through 3360. The partition size can be specified in blocks, cylinders, or megabytes by using the bc, and mb suffixes when entering the size.

partition> 3
Part      Tag    Flag     Cylinders        Size            Blocks
  3 unassigned    wm       0               0         (0/0/0)          0
 
Enter partition id tag[unassigned]: 
Enter partition permission flags[wm]: 
Enter new starting cyl[0]: 0
Enter partition size[0b, 0c, 0.00mb]: 1680c
partition> 4
Enter partition id tag[unassigned]: 
Enter partition permission flags[wm]: 
Enter new starting cyl[0]: 1681
Enter partition size[0b, 0c, 0.00mb]: 1680c

Once the disk has been partitioned, the label should be written to the disk:

partition> label
Ready to label disk, continue? y

The new partition table can be printed from the format utility, or may be viewed using the prtvtoc command:

# prtvtoc /dev/rdsk/s0t5d0s2
* /dev/rdsk/c0t5d0s2 partition map
*
* Dimensions:
*     512 bytes/sector
*     140 sectors/track
*       5 tracks/cylinder
*     700 sectors/cylinder
*    3363 cylinders
*    3361 accessible cylinders
*
* Flags:
*   1: unmountable
*  10: read-only
*
* Unallocated space:
*       First     Sector    Last
*       Sector     Count    Sector 
*     1176000       700   1176699
*
*                          First     Sector    Last
* Partition  Tag  Flags    Sector     Count    Sector  Mount Directory
       2      5    01          0   2352700   2352699
       3      0    00          0   1176000   1175999
       4      0    00    1176700   1176000   2352699


Creating new filesystems

Finally, new filesystems can be created on the disk using the newfs command, and each filesystem is checked for integrity using fsck:

# newfs /dev/rdsk/c0t5d0s3
newfs: construct a new file system /dev/rdsk/c0t5d0s3: (y/n)? y
/dev/rdsk/c0t5d0s3:     1176000 sectors in 1680 cylinders of 5 tracks, 140 sectors
        574.2MB in 105 cyl groups (16 c/g, 5.47MB/g, 2624 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
 32, 11376, 22720, 34064, 45408, 56752, 68096, 79440, 89632, 100976, 112320,
 123664, 135008, 146352, 157696, 169040, 179232, 190576, 201920, 213264,
 224608, 235952, 247296, 258640, 268832, 280176, 291520, 302864, 314208,
 325552, 336896, 348240, 358432, 369776, 381120, 392464, 403808, 415152,
 426496, 437840, 448032, 459376, 470720, 482064, 493408, 504752, 516096,
 527440, 537632, 548976, 560320, 571664, 583008, 594352, 605696, 617040,
 627232, 638576, 649920, 661264, 672608, 683952, 695296, 706640, 716832,
 728176, 739520, 750864, 762208, 773552, 784896, 796240, 806432, 817776,
 829120, 840464, 851808, 863152, 874496, 885840, 896032, 907376, 918720,
 930064, 941408, 952752, 964096, 975440, 985632, 996976, 1008320, 1019664,
 1031008, 1042352, 1053696, 1065040, 1075232, 1086576, 1097920, 1109264,
 1120608, 1131952, 1143296, 1154640, 1164832,
# fsck -y /dev/rdsk/c0t5d0s3
** /dev/rdsk/c0t5d0s3
** Last Mounted on 
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
2 files, 9 used, 551853 free (13 frags, 68980 blocks, 0.0% fragmentation)

Adding Disks with HP-UX

Adding Disks with HP-UX

Once the disk has been physically installed, the system should detect the device that a new device is available on the SCSI bus. After the power to the system has been restored, press the Esc key to get to the Boot PROM prompt where Boot_Admin> is offered. At the Boot_Admin> prompt, type search:

Boot_Admin> search [return]

This will return the list of scsi devices:

Device Path             Device Type
----------------        -----------------
scsi.6.0                HP C2247
scsi.2.0                TOSHIBA CD-ROM XM-340ITA

After verifying the disk drive is detected by the Boot PROM, continue the initialization sequence by entering boot. When the boot process has completed, ensure that the drive was detected by the kernel by reviewing the kernel messages in /var/adm/syslog/syslog.log. They should look somewhat similar to the following:
Mar 19 15:21:47 bud vmunix: 2/0/1.0 tgt
Mar 19 15:21:47 bud vmunix: 2/0/1.0.0 sdisk
Mar 19 15:21:47 bud vmunix: 2/0/1.1 tgt
Mar 19 15:21:47 bud vmunix: 2/0/1.1.0 sdisk
Mar 19 15:21:47 bud vmunix: 2/0/1.6 tgt
Mar 19 15:21:47 bud vmunix: 2/0/1.6.0 sdisk
This system located three disk drives on controller 0 located at the controller device address 1 and at SCSI IDs 0, 1 and 6. Additionally, the command /usr/sbin/ioscan may be run to show further information about the disk drives detected.
# /usr/sbin/ioscan -C disk
H/W Path   Class                Description
===========================================
2/0/1.0.0               disk    HP      C2247
2/0/1.1.0               disk    HP      C2247
2/0/1.6.0               disk    SEAGATE ST31200N
If the disk device is not found, determine if the device driver needed for the disk and interface are available. If any necessary device driver is absent from the kernel, the kernel will need to be rebuilt incorperating the new driver.
Here is a brief overview of the steps to rebuild a kernel.
  • Go to the build directory and from there, run the script, system_prep. This script will extract the system file from the current kernel.
    # cd /stand/build                          
    # /usr/lbin/sysadm/system_prep -v -s system
    
  • Modify the /stand/build/system file, adding the driver. Rebuild the kernel with the command:
    # /usr/sbin/mk_kernel -s system 
    
    The new kernel /stand/build/vmunix_test is created
  • Save the copy of the old kernel and move the new one in its place and reboot the system.
    # mv /stand/system /stand/system.old
    # mv /stand/vmunix /stand/vmunix.old
    # mv /stand/build/system /stand/system     
    # mv /stand/build/vmunix_test /stand/vmunix
    

Device nodes

During HP-UX boot-up, /sbin/insf is executed to create the character and block device special /dev files that allow communication with the disk. HP-UX uses a somewhat standard SVR4 device file naming system. For each disk device, the following special files are created:
  • Block device file:
    /dev/dsk/ccardttargetddevice
  • Charater device file:
    /dev/rdsk/ccardttargetddevice
Where card is the (SCSI) controller number, target is the SCSI ID number, and device is the logical unit number, or lun. The lun is 0 for the majority of devices. An example for a disk at controller 0, target 6, lun 0, is /dev/dsk/c0t6d0.
A disk is usually divided into file systems, areas that can hold files, or raw data areas such as swap. File systems are created in disk partitions or logical volumes. To view the size of the drive to be configured use the command, diskinfo.
# /usr/sbin/diskinfo /dev/rdsk/c0t6d0
SCSI describe of /dev/rdsk/c0t6d0:
             vendor: HP      
         product id: C3324A          
               type: direct access
               size: 1025730 Kbytes
   bytes per sector: 512
Though HP-UX does support standard (BSD) style filesystems, it is recommended that the logical volume manager (LVM) be used because of the following reasons.
  • They offer greater flexiblity for disk partitioning.
  • The size of logical volumes can be modified according to need.
  • Logical volumes can span disks.
More recommended reading about LVM is availbable in the Logical Volume White paper.

Creating traditional filesystems

To initialize the disk and check the disk for bad blocks the command, mediainit can be used. This is usually not necessary with HP-UX 10.x.
# mediainit /dev/rdsk/c0t1d0
The newfs command has been updated, from the 9.x version, to prompt for disk specific information, thereby overriding the information directives found in the, now obsolete, /etc/disktab file.
# newfs -F hfs /dev/rdsk/c0t5d0
mkfs (hfs): Warning - 121 sector(s) in the last cylinder are not allocated.
mkfs (hfs): /dev/rdsk/c0t5d0 - 990071 sectors in 2947 cylinders of 12 tracks, 28 sectors
1013.8Mb in 185 cyl groups (16 c/g, 5.51Mb/g, 832 i/g)
Super block backups (for fsck -b) at:
    16,   5424,  10832,  16240,  21648,  27056,  .....

Creating logical volume filesystems

The system administration tool, sam, can be used to perform most of the tasks involved with adding a new disk. Optionally, the commands to activate this disk can be given from the command line, which is demonstrated here. The physical disk drive should be added to either and an existing volume group or to a newly created volume group. These tasks are done with the commands/usr/sbin/vgextend and /usr/sbin/vgcreate respectively.
In either case pvcreate needs to run to initializes the device (a raw disk device) for use as a physical volume in a volume group.
# pvcreate /dev/rdsk/c0t5d0
Physical volume "/dev/rdsk/c0t5d0" has been successfully created.
Then to create a new volume group, the directory /dev/vg01 with the character special file called group, execute vgcreate.
#mkdir /dev/vg01
#mknod /dev/vg01/group c 64 0x010000
# vgcreate /dev/vg01 /dev/dsk/c0t5d0
Volume group "/dev/vg01" has been successfully created.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf
Note that the last argument to the mknod command must be unique for each volume group that exists on the system.
Otherwise, to add or extend an existing volume group, executed vgextend.
# vgextend /dev/vg00 /dev/dsk/c0t5d0
Volume group "/dev/vg00" has been successfully extended.
Volume Group configuration for /dev/vg00 has been saved in /etc/lvmconf/vg00.conf
Utililizing the increased disk space in the volume group, create a single or multiple logical volumes that will contain filesystems. In this example a single logical volume and file system of 1 gigabyte is created.
# lvcreate -L 1000 /dev/vg00      
Logical volume "/dev/vg00/lvol9" has been successfully created with
character device "/dev/vg00/rlvol9".
Logical volume "/dev/vg00/lvol9" has been successfully extended.
Volume Group configuration for /dev/vg00 has been saved in /etc/lvmconf/vg00.conf

# newfs -F hfs /dev/vg00/rlvol9
mkfs (hfs): Warning - 608 sector(s) in the last cylinder are not allocated.
mkfs (hfs): /dev/vg00/rlvol9 - 1024000 sectors in 1642 cylinders of 16 tracks, 39 sectors
1048.6Mb in 103 cyl groups (16 c/g, 10.22Mb/g, 1600 i/g)
Super block backups (for fsck -b) at:
    16,  10040,  20064,  30088,  40112,  ....

Mounting the new filesystem

Add this filesystem to the ones that are automatically mounted by system initialization, by updating the file /etc/fstab with the following entry. It specifies the device and the mount point for the filesystem.
/dev/vg00/lvol9 /usr/local hfs defaults 0 2

Mount the filesystem using the command /usr/sbin/mount -a. Check the mount table to ensure the partition was mounted and check the filesystem size with the /usr/bin/bdf command.
# mount -a
# mount
/ on /dev/vg00/lvol1 defaults on Thu May 23 08:10:01 1996
/var on /dev/vg00/lvol8 defaults on Thu May 23 08:10:14 1996
/usr on /dev/vg00/lvol7 defaults on Thu May 23 08:10:15 1996
/tmp on /dev/vg00/lvol6 defaults on Thu May 23 08:10:15 1996
/opt on /dev/vg00/lvol5 defaults on Thu May 23 08:10:15 1996
/home on /dev/vg00/lvol4 defaults on Thu May 23 08:10:15 1996
/usr/local on /dev/vg00/lvol9 defaults on Thu May 23 08:37:17 1996
# bdf /usr/local
Filesystem          kbytes    used   avail %used Mounted on
/dev/vg00/lvol9    1001729       9  901547    0% /usr/local

Thursday, November 6, 2014

常見的裝置與其在Linux當中的檔名

常見的裝置與其在Linux當中的檔名


裝置裝置在Linux內的檔名
IDE硬碟機/dev/hd[a-d]
SCSI/SATA/USB硬碟機/dev/sd[a-p]
USB快閃碟/dev/sd[a-p](與SATA相同)
軟碟機/dev/fd[0-1]
印表機25針: /dev/lp[0-2]
USB: /dev/usb/lp[0-15]
滑鼠USB: /dev/usb/mouse[0-15]
PS2: /dev/psaux
當前CDROM/DVDROM/dev/cdrom
當前的滑鼠/dev/mouse
磁帶機IDE: /dev/ht0
SCSI: /dev/st0

  DAILY CHECKLIST Oracle Database instance is running or not select name,open_mode from V$database; Note: Check the Oracle databases are ru...