Entries Tagged as 'Unix'

Solaris: How to view partition slices

solaris.jpg In Solaris, partitioning is a little different that linux. Everything is divided into slices, and there is a total of eight slices per partition. Each partition pertains to a disk.
So to access the partition menu, you type the format command, and after selecting the disk you want to view, you would type partition at the format prompt:
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
! – execute , then return
quit

From here, you would only need to type print, to print the partition slices.
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

And there you have it. In slice 2 of that particular disk, you have 1.12GB set up. This doesn’t necessarily mean that there isn’t extra space on the disk partition that isn’t being used, it just means that only 1.12GB has been set for slice 2 and nothing else for the rest. When you begin to set slices, you can actually see how much there is left.

Solaris: Basic commands with services

solaris.jpg One of the most basic things about Solaris are the services just like the linux daemons. To list all the services that are active, do:
# svcs
If you add the -a flag, then it’ll list all services that are enabled and disabled. If you use the -x flag, it’ll actually breakdown the services.
If you need to enable a service, you do:
# svcadm enable service
Where service is the name of the service. Obviously disabling would be:
# svcadm disable service

Setting up RAID-5 in Solaris

solaris.jpg In Solaris, you can set up a software RAID-5 if you have enough of the drives. Here’s a quick howto:
First you would find the drive designations. Take for example:
c0t2d0s7 c0t3d0s7 c1t4d0s7 c1t5d0s7 c1t6d0s7 c1t7d0s7
At the prompt, you would add them to the database with the metadb command:
#metadb -a -f c0t2d0s7 c0t3d0s7 c1t4d0s7 c1t5d0s7 c1t6d0s7 c1t7d0s7
To check if they were added, you would get the information from the metadb command:
#metadb -i
To add all of the drives into a RAID volume, assign a number to your raid. You can use pretty much any digit but most people use single digits since they don’t have that many RAID volumes. I’ve used d9 in the example:
#metainit d9 c0t2d0s7 c0t3d0s7 c1t4d0s7 c1t5d0s7 c1t6d0s7 c1t7d0s7
Then you just wait as it initializes the volume. To check the status of the RAID volume, you use the metastat command:
#metastat d9
Finally the last thing you have to do is create a file system on the RAID volume:
#newfs -i 8192 /dev/md/rdsk/d9
Obviously this system would need to be mounted after the filesystem is in place, so you make a directory, mount the volume, and set the vfstab.
#mkdir /db9
#mount -F ufs /dev/md/dsk/d9 /db9

In vfstab add the line:
/dev/md/dsk/d9   /dev/md/rdsk/d9   /db9   ufs   2   yes   –
And there you go. Your very own software RAID-5 on a Solaris box.

ncftp is just so beautiful when it comes to recursion

I happen to adore ncftp. When it comes to server to server transfers, there are a couple ways to approach this. One is to use a ftp client that supports fxp. I’ll go into this in more detail later.
Another way is to use one server, and access the other via a ftp transfer. Unfortunately, regular ftp doesn’t allow recursion into subdirectories and thus making it a nightmare to move files. Not really a problem at all. Just fire up the ole’ shell and use ncftp. ncftp actually allows you to enter username and password (anonymous ftp by default) and also has recursion built in.
When you’re in the directory that you need to grab, just do: get -r *
Then you can wait while this nifty ftp client just grabs everything for you. Saves the day many times over. And allows you time for that coffee that you usually don’t have time for.

Using .netrc for automated ftp

Sometimes there comes a need to actually automatically ftp things. But usually when you automatically ftp things, you have to enter in a password. The way around this is to use the .netrc file.
The .netrc file stores the machine name, the login, and the password for the ftp. This allows you to set up ftp actions without having to mess with the interactive parts and do everything else directly from a shell script.
Not exactly something that you’d want to always do for everything, but now and again behind a firewalled network, isn’t a bad idea for automated backups. Even if your passwords change constantly through a time seeded hardware device, you can set it up so that everything is still running from a shell script and the only thing you would have to do is type in the password. Beats doing things manually, eh?

Setting up no password ssh keys

One of the more interesting things that you can do with ssh is set up public and private keys and make it so that transactions between systems require no passwords. The bad thing about this is the obvious. If one of your systems inside get compromised, then your internal network is compromised without any work necessary.
The good thing though is that you can then set up automatic transfers through shell scripts or perl scripts. Either way, it’s definitely has its useful sides too. While this howto is for a Debian installation, it’s really no different at all when it comes to configurations.

Changing your Unix environment to use vi

Every so often, you’ll run into a Unix box somewhere that has the editor defaulted to sed. Yes, you heard me. sed.
Don’t ask me why. While sed is pretty powerful, it’s a lot easier to mess with vi, isn’t it. Well what’s missing is the change in the .profile. You need to edit the .profile so that there is the following commands:
EDITOR=vi
export EDITOR
That’s it. But these two commands will set it up so that your environment defaults to vi when you relogin or you re-launch the .profile.

Tracing hung processes through the ppid

One of the easiest ways to troubleshoot hung processes is trace it to the source. This works for cpu intensive things also, when dealing with a *nix based system. So if you look at the process ids, there are always a parent process id that’s associated with it.
It’s usually always in this format: So if you just trade those ppids as the pid, you can eventually find out what script or tool is dragging your entire system down. Basics of troubleshooting processes, but you’d be surprised how many people do not understand it.
If the process is eventually owned by root (or pid of 1) then it’s been zombied meaning the parent dropped out and tossed the reins to the root process. Zombie processes sometimes can actually never go away until they’re killed and just sit there taxing resources from your system.

How to create automatic ftp scripts in bash

You can do this in any operating system that allows you to do bash shell scripting, but if you know a little about shell scripting, then all you need to know is that you can do:
ftp -i << **
After you put this in the script, this will allow you to login and password to whatever is set in your .netrc. If you don’t have one, then you should set it before starting off a script like this.
All the commands after this line will be your usual ftp commands. When you’re done, then do a:
bye
**

Everything outside of this line will be back on your bash scripting syntax.

metastat command for Solaris

The metastat command is very useful if you have meta devices and or what is known as a hot spare pool. This command basically shows the status of your meta device (basically, a software RAID, or volume) and lets you know if there is a need to do maintenance on any of the drives or what not.
Great tool to have handy, especially if you’ve set up a software RAID. Makes it extremely useful to not only do spot-checks, but see how each physical device is doing within the meta device.