Archive for the 'Solaris' Category

Solaris – format

February 11th, 2010

 # format
Searching for disks…done
AVAILABLE DISK SELECTIONS:
0. c0t0d0 <drive not available: formatting>
/sbus@6,0/SUNW,socal@d,10000/sf@0,0/ssd@w210000163787753a,0

Sometimes

# format -Mm
may be helpful as this reports additional messages about what is happening.

Get a list of disks

# format < /dev/null or echo “\n” | format

format non destructive commands
disk, current, defect, verify, save, inquiry

format destructive commands
type, partition, format, repair, label, analyze, backup

formating using another disk
# prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s – /dev/rdsk/c0t2d0s2

Install boot block
# installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/c0t2d0s0

A fairly typical layout is

0. /
1.  swap
2. whole disk
3.  /var
4. /data

If the system has has a database locally and there is a need for a bit of extra speed then /data can always be put on the faster part of the disk. Not to many systems swap much anymore since there is the ability to put in as much memory as is needed. Although if needed a seperate filesystem can be created for a swap partition.
0. /data
1. /
2. whole disk
3. /swap
4. /var

Solaris – Compress, Uncompress

September 1st, 2009

Backup to a USB drive

Mount USB drive and check contents

# volrmmount -i rmdisk0; cd /rmdisk/rmdisk0; ls -FC

tar -cf foobar.tar /tmp/dir

jar cf foobar.jar /tmp/dir/*

jar are cool, they do however require the Jave Runtime Engine.  jar’s do not maintain soft links the do follow the soft link and copy the contents. 

compress -v foobar.tar

ends up with foobar.tar.Z

to view compress files use zcat foobar.tar.Z | less

or extract the output in conjunction with tar

zcat foobar.tar.Z | tar xf –

uncompress -v foobar.tar.Z

look at contents with uncompress

uncompress -c foobar.tar.Z | tar xvf –

compress and uncompress with 7za

7za a foobar.7z file1 file2

7za x foobar.7z

gzip -v filename

gunzip filename

gzcat filename to view contents of zip file

use unzip on .jar .zip files

Ultra2 Backup Boot Disk Script

August 18th, 2009

This script is a bit crude but it does work if the system is not real busy.  Another solution is to use SVM and mirror the disks.  The problem there however is; if a disk is lost and the system goes down it will not come up since SVM needs a quarum (over half) with the metadb’s. 

 I use the below scipt plus dump a flar to another system.  I really need to convert this disk to cpio.

#!/bin/csh
#
# This script backs up the primary to secondary hard disk on an ultra class machine.
# c0t0d0 is the primary disk
# c0t1d0 the secondary disk
# s0 is / s3 is /var s7 is /work.

# This partitions the secondary disk to match the primary disk of same geometry.
prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s – /dev/rdsk/c0t1d0s2

# Make backup directory mount points if not present.
if (! -d /root1) mkdir /root1
if (! -d /var1) mkdir /var1
if (! -d /work1) mkdir /work1

# Unmount the partitions of secondary disk if they are mounted.
if ( -e /root1/lost+found) umount /dev/dsk/c0t1d0s0
if ( -e /var1/lost+found) umount /dev/dsk/c0t1d0s3
if ( -e /work1/lost+found) umount /dev/dsk/c0t1d0s7

# Newfs partitions of the secondary disk.
newfs -v /dev/rdsk/c0t1d0s0 < /dev/null
newfs -v /dev/rdsk/c0t1d0s3 < /dev/null
newfs -v /dev/rdsk/c0t1d0s7 < /dev/null

# Mount secondary disks
mount /dev/dsk/c0t1d0s0 /root1
mount /dev/dsk/c0t1d0s3 /var1
mount /dev/dsk/c0t1d0s7 /work1

# Dump from primary to seconday
ufsdump 0sf 5000000 – / | (cd /root1; ufsrestore rf – )
ufsdump 0sf 5000000 – /var | (cd /var1; ufsrestore rf – )
ufsdump 0sf 5000000 – /work | (cd /work1; ufsrestore rf – )

# Install boot block on secondary disk
installboot /usr/platform/`uname -i`/lib/fs/ufs/bootblk /dev/rdsk/c0t1d0s0

# Update motd
echo `uname -rsvi`” Primary disk” > /etc/motd
echo “Backup copy on “`date` >> /etc/motd
echo `uname -rsvi`” Secondary disk” > /root1/etc/motd
echo “Backup copy on “`date` >> /root1/etc/motd

# Change /root1/etc/vfstab to enable boot disk1
sed ‘s/c0t0/c0t1/g’ /etc/vfstab > /root1/etc/vfstab

# Unmount backup disk.
umount /dev/dsk/c0t1d0s0
umount /dev/dsk/c0t1d0s3
umount /dev/dsk/c0t1d0s7

Solaris – find

August 18th, 2009

# cd /work && find . -type d -exec ls {} \;

find the approximate number of files/inodes
#find /work -xdev -exec ls -id {} + | cut -c-11 | sort -u | wc -l

find 20 larges files over 90 days old.

# find /work/ftp/local -mtime +90 -print -type f -exec ls -la {} \; | sort -r -n -k 5,5 | head -20

remove files older that 60 days.
# find . -mtime +60 -exec rm -f {} \;

find largest files within last 30 days
# find /work/ftp/pub -mtime -30 -type f -exec ls -la {} \; | sort -r -n -k 5,5 | head -40

list size of directory in MegaBytes
# ls -lR | awk ‘{total +=$5};END {print “Total size: ” total/1024/1024 “MB” }’

find the 20 largest files
# find /tmp -type f -follow -print | xargs ls -l | sort -r -n -k 5,5 | head -20

look recusivly down for any file >= to 1meg then list path

#find . -size 1000000c -ls  #

# find . -mtime -1 -type f -print
finds all files that have been modified within the last 24 hours

# find Members/ -type f -print0 | xargs -0 grep “examplestring”

find files by user

# find . -name SCCS -prune -o -print

In the above example the find command finds all files in the Members
directory each file that is found is then searched using grep for
the text “examplestring”

Fast alternative to cp -pr
# find . -depth | cpio -pdmv /path/tobe/copied

To find files owned by a user, please use the following command
# find . -user <USERLOGIN ID> -a -type f -print

Find SUID and SGID programs
# find . \( \( -perm -04000 -a -perm +011 \) -o \( -perm -02000 -a -perm +01 \) \) -print