Andy's Unix FAQ

Installing a new disk under Solaris

In this FAQ: What you want.., Cylinders, Planning, Creating partitions,
Newfs, parameters Mount, Swap partitions /etc/vfstab,
Also: fsck pass numbers


Unix FAQ Menu
Contents
Basic commands
Cron
Creating CDs
Device Files
DHCP server (Solaris)
Filesystem explained
Fsck
grub/lilo vanished!
Linux applications?
Linux databases?
Linux distributions
Serial Console
Solaris devices
Solaris disks - Intro
Solaris disks - Adding
Solaris x86 install
SQL/Shell script
Syslog/Monitoring
Time Synchronisation.
Virtual Memory
Web Multi-Language
Web Server Errors
Humour
Unix a Prank



 
Excellent This page has received an average rating of 88% from 49 readers

Question;

We have just fitted a new disk to one of our Solaris (sparc) machines. Can you explain how we put it to use?

Answer;

I hope you've sorted out your SCSI termination and addressing. This FAQ isn't about hardware issues. You should have done a probe-scsi-all from the boot prompt before rebooting the machine with boot -r. This answer assumes your new disk showed up on the probe and is visible to the O/S.

If you haven't already done so, you need to identify the device file related to you new disk, have a look at Introduction to Solaris Disks & Filesystems. If you think your new disk may have data, read the section Fsck - checking for Data

Decide what you want to do

Formulate a clear plan as to how you are going to use your new disk. If you are using a volume manager then you should go away and read the documentation for it. If you simply want to create one or more filesystems, swap, or raw partitions, then read on..

You need to decide whether you are going to use the whole disk for a single purpose or split it up into multiple areas ('Partitions'). Some of the different uses you may be considering are;

Filesystems
Most likely you'll want at least one filesystem on there whether it be for user data or additional application software.
A swap partition / device
If your system is paging heavily and more memory isn't an option, additional swap partitions can help. Paging is explained in more detail in Virtual Memory explained. Nip down to Swap Partitions if this is of interest.
Raw Partitions
Most likely for Database use. Oracle still quote a 10-15% performance improvement when raw partitions are used to hold tablespaces rather than filesystems.

Draw up a table on paper roughly outlining the space in MB you want to allocate to each purpose. Leave three empty columns in your table for the partition/slice number, the exact size, and the start position of each Partition. Use a spreadsheet if you like.
Part# Use MB start cyl #cyls
         
         
         
         
Simple, but dead useful for this exercise


A Cylinder

You need to understand the concept of a Cylinder. More than 30 years after the birth of Unix the cylinder remains a key concept in the filesystem. To do this job properly you need to understand it.

If you understand what a track on a floppy disk or CDROM is, then a Cylinder is simply an extension of that - a series of vertically aligned tracks on a multi-surface (aka multi-plattern) disk.
Diagram of a cylinder on disk
Most system utilities will report disk and filesystems sizes in user friendly units such as KB, but to setup a filesystem you should be working in cylinders.

Planning your partition table.

Now you need to find out how much space you really have on that disk - the salesman's waffle may start to look a little suspicious right about now. Run prtvtoc <raw_device>s2 to dump out the disk's label and existing partition information, for example;
sun (ksh) # prtvtoc /dev/rdsk/c0t1d0s2 
* /dev/rdsk/c0t1d0s2 partition map
*
* Dimensions:
* 512 bytes/sector
* 237 sectors/track
* 20 tracks/cylinder
* 4740 sectors/cylinder
* 7501 cylinders
* 7499 accessible cylinders
*
* Flags:
* 1: unmountable
* 10: read-only
*
*                     First   Sector  Last
* Partition Tag Flags Sector   Count  Sector Mount Directory
      1      3    01       0   237000   236999
      2      5    01       0 35545260 35545259
      5      4    00  237000  4266000  4502999 
      6      4    00 4503000  1422000  5924999 
      7      4    00 5925000 29620260 35545259 
You're only really interested in 3 numbers at the moment; bytes/sector, sectors/cylinder, & accessible cylinders. At this point you should calculate the size of a cylinder and the total space in MB. The calculations are;
cyl_size = (sectors_per_cylinders * bytes_per_sector) / 1024000 
total_space = cyl_size * accessible_cylinders

In our example these numbers come out to 2.37MB and 17773MB.

Armed with this information you can fill in the blanks on your paper or spreadsheet allocation table. The number of cylinders one of your partitions occupies is simply your MB size divided by the size of one cylinder - avoid odd numbers for this.

If first partition starts at cylinder 0 and is 300 cylinders long then the second partition starts at Cylinder 300 ( 0+300=300 ). Fill in your table until all the space on the disk is allocated somewhere.

Remember;
   next start cylinder = previous start cylinder + previous number of cylinders

Before putting your calculator away check that partition #2 represents the entire available space. Various utilities rely on this

Incidently, this drive was marketed as a 20GB....

Creating your partition table

If you want to use the entire disk for a single purpose you don't actaully need to create any partitions - you can simply use partition #2.

You are now ready to run format to create your new partition table. After selecting your NEW disk, type 'p' to get to the partition menu, and 'p' again to display the current partition table.

partition> p
Current partition table (original):
Total disk cylinders available: 2036 + 2 (reserved cylinders)

Part      Tag  Flag   Cylinders     Size         Blocks
  0       root  wm     0 -  101    50.20MB  (102/0/0)   102816
  1       swap  wu   102 -  305   100.41MB  (204/0/0)   205632
  2     backup  wm     0 - 2035  1002.09MB  (2036/0/0) 2052288
  3        usr  wm   306 - 1829   750.09MB  (1524/0/0) 1536192
  4        var  wm  1830 - 2033   100.41MB  (204/0/0)   205632
  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

All Sun supplied disks come with a pre-defined partition table. This you can safely ignore as you are repartitioning the entire disk. If wish you may like to remove any existing partitions by assigning them a start and cylinder count of zero, tag should be 'unassigned'. This is not strictly neccessary but it does make things neater.

Your new partitions can occupy any slot in the table, except #2. If you are creating swap partitions you may like to note that by convention partition #1 is used for this purpose. However nothing relies on this and it is only a convention.

I suggest you assign sequentially starting from partition 0. For a filesystem the partition tag is 'usr', for swap use 'swap' and for a raw partition use 'unassigned'. Record the partition number on your paper allocation table.

partition> 5
Part     Tag    Flag Cylinders   Size    Blocks
 5   unassigned  wm       0      0      (0/0/0) 0

Enter partition id tag[unassigned]: usr
Enter partition permission flags[wm]:
Enter new starting cyl[0]: 0
Enter partition size[0b, 0c, 0.00mb, 0.00gb]: 300c 
		

And continue on until all your partitions are defined.

CAUTION: Format will not prevent or warn you if you create overlapping partitions !
Concurrent use of overlapping partitions WILL cause system failure and data loss at some point in the future.

Before writing the new partition table to disk use the 'p' command to double check that none of your partitions overlap - use the 'Cylinder' column to check this. N.B. Partition #2 represents the entire disk, so it'll overlap all your partitions.

Write the partition table ("label") to disk with the label command and quit format.

What you do now depends on what use you are putting you partitions to. With raw partitions there is nothing left to do. For swap partitions skip on to Swap Partitions, just carry on reading if you are creating filesystems as newfs is what you need.

Creating a new filesystem - newfs

For all the partitions you just created that you intend to use for filesystems, you now need to create a filesystem on them. If you're a nervous about this (you ought to be), you might like to use the -N option to newfs. This is basically a dummy run - nothing gets written to disk, you simply see what it would do.

Creating a filesystem is as easy as this...

sun (ksh) # newfs  /dev/rdsk/c0t1d0s5
/dev/rdsk/c0t1d0s5: 1422000 sectors in 300 cylinders 
of 20 tracks,  237 sectors
        694.3MB in 19 cyl groups (16 c/g, 37.03MB/g, 17792 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
 32, 76112, 152192, 228272, 304352, 380432, 456512, 532592, 
 608672, 684752, 760832, 836912, 912992, 989072, 1065152, 
 1141232, 1217312, 1293392, 1369472,

So easy it's scary! No confirmations, no "ALL DATA ON HARD DRIVE WILL BE DELETED !" warnings. Just hit return and off it goes...

Newfs may take some considerable time to complete on a large partition - just leave it alone. Take a look at the disc activity light if you need some proof it's actually working.

Note that we created a filesystem on partition #5, as denoted by s5 in the device name 'c0d0t0s5'. 's' stands for slice, another name for a partition.

A brief explanation of newfs's output is in order:
The first line simply reports the vitals of the partition as you defined them in format.

Slightly more interesting is the total size of this filesystem, and the number of cylinder groups, the size of each group ( "16 c/g" = 16 Cylinders per group ).

The last entry ("17792 i/g") is the number of inodes per cylinder group. An inode stores the vitals of every file that will live on this filesystem. You can only have as many files on a filesystem as there are inodes - regardless of the size of those files.

A 'super-block' is a bit of Unix black magic, the simple explanation is that it stores a list free blocks on that filesystem. The backup numbers are sometimes useful if fsck gets into trouble later on - see Fsck, using alternate superblocks for more on that.

Inodes and Superblocks are covered in The Filesystem explained, along with many other filesystem terms.

Tweaking the Parameters of newfs

newfs is simply a wrapper around mkfs(1m). The wrapper came into being because the option list on mkfs is large and somewhat daunting. There are however a few parameters that you may want to think about. In alphabetical order;
-f fragment size
Under Solaris a fragment is a portion of a full block. Very small files will occupy fragments rather than a whole block. This parameter is only worth considering if you expect the filesystem to be largely occupied by very small files < 1024 bytes. The default value is 1024 bytes. The rules are very tight on this value - check your documentation.
-i inode density
Controls how many inodes to create on the filesystem. The default value of one inode for every 2048 bytes of data assumes an average filesize of 2048 bytes. This is woefully small and generally results in a lot of space being wasted on inodes. For user filesystems values like 16384 or 32768 are generally more appriopriate. For example, the numbers for a 2GB filesystem look like this;
Inode density Total inodes Size of inode table Tip: You can use the -g option of df
to check the inode table of a filesystem.
Under Solaris7, 1 inode occupies 320 bytes.
2048 976562 312 MB
32768 61035 19 MB
-m minfree
Allocating new space for data as files are created and extended is a computationally and I/O intensive operation. It can become up to 3 times more expensive when the filesystem gets more than 90% full. By default Solaris reserves 10% of free space which is off limits to user processes - root can use it. If you expect to have a largely static filesystem, with not many files created or extended you can safely reduce this figure. The value can be changed on a live filesystem using tunefs(1m).
-o optimisation
Optimise allocation of free space by either Time or Space. Basically do you want speed or reduced fragmentation ? Default is Time. When the filesystem is nearly full the kernel will automatically change this to space. The value can be changed on a live filesystem using tunefs(1m).

Mounting the new filesystem

Following the letter of the law now you should fsck your new filesystem prior to mounting it - feel free. What you really want to do however is mount it so that you check it out. You can actually mount a filesystem on ANY directory, though it ought to be an empty one. There is an empty directory just for this purpose - /mnt;

    sun# mount /dev/dsk/c0t1d0s5 /mnt
    sun# df -k /mnt
    Filesystem            kbytes    used    avail capacity  Mounted on
    /dev/dsk/c0t1d0s5    2100583      10  2100573     0%    /mnt
    sun# ls -l /mnt
    total 62
    drwxrwxrwx   4 root     root         512 Jan  2  1999 lost+found 
    sun# umount /mnt
     
Here we are using /mnt as a mount point. More about these in The Filesystem explained - Mount Points

When you are content umount the filesystem with 'umount /mnt'. Now you need to make things permanent - /etc/vfstab.

Swap Partitions - a.k.a. Swap Device

Solaris uses multiple swap partitions in parallel and shifting some of the paging load off the main system disk can make a big difference. By convention swap partitions should be placed on partition #1. This is however only a convention - nothing relies on it.

Notes: The slightest hiccup on a disk holding a swap partition can cause the system to crash. If you have any doubts about your new disk do not use it for this purpose.
It doesn't make any sense to put multiple swap partitions on a single disk - this can actually degrade performance.

Once you have a partition free and available, you activate it by using the 'swap -a' command.

Be very careful here if you get this wrong and specify a partition that has a filesystem on it, well it won't after this command !

Assuming you have adhered to the convention and defined partition #1 as the swap area then for our example disk the command would be;

     sun (ksh) # swap -a /dev/dsk/c0t1d0s1
     sun (ksh) #
In classic Unix style swap remains silent if all is well. You can confirm your swap partition is now live with swap -l;
      sun (ksh)# swap -l
      swapfile             dev  swaplo blocks   free
      /dev/dsk/c0t3d0s1   32,25      8 205624 165408
      /dev/dsk/c0t1d0s1   32,9       8 236992 236992
You now need to add it to vfstab.

/etc/vfstab

We are going to make our new filesystem available under a new directory called /data. This doesn't exist yet so we create it with 'mkdir /data'. After editing /etc/vfstab the new entry looks like this;
/dev/dsk/c0t1d0s5 /dev/rdsk/c0t1d0s5 /data   ufs  3  yes     - 

The seven fields of vfstab are;

  1. Block device - used for 'mount', and 'swap'
  2. Character (raw) device - used by fsck. (for swap partitions this should be "-")
  3. Mount point for the file system (for swap partitions ths should be "-")
  4. Filesystem type. 'ufs' for a filesystem, 'swap' for a swap partition.
  5. fsck pass number. See below
  6. mount at boot time ? YES|NO
  7. mount options. See the manual pages for mount(1m) and mount_ufs(1m) for a full list.

After saving it, you should be able to do a 'mount -a' and have your new filesystem mounted under /data.. You'll likely see some warnings about other filesystems already being mounted - these can be safely ignored.

Fsck pass number

The fsck pass number seems to be the source of some confusion
Solaris along with most other Unix variants is capable of checking multiple filesystems simultaneously - well it is a multi-processing system. fsck will perform as many passes as there are different pass numbers in /etc/vfstab. Filesystems on pass 1 will be checked on the 1st pass, those on pass 2 will be checked on the 2nd pass, etc. Your objectives when setting pass numbers are;

  1. Have as few passes as possible
  2. Never have more than one filesystem on a single physical disk checked on the same pass.
    - this will thrash that disk and slow down the process enormously
  3. Ideally have similarly sized filesystems checked on the same pass. (performance)
    - this is a nicety, points 1 & 2 are far more important.

Adherence to these points will enable your system to complete a full filesystem check in the minimum possible time. On a large fileserver it can make the difference between the server being down for a couple of hours or the whole day.

Notes;
  • The root filesystem will be checked on it's own pass regardless of any pass number you put it in.
  • Setting the pass number to zero will result in fsck never being run on the filesystem at boot time. Unless the filesystem is not mounted at boot time this highly unwise - corrupt filesystems crash systems.
  • Still Confused? Then just find the highest current pass number and add one. Your new disk will get checked out after all the other filesystems.

Final point: Don't forget to add your new filesystem(s) to whatever backup schedule your site uses.....


Feedback

I hope you found this FAQ to be of some use. It would be most helpful if you could rate it below. All fields are optional...
Please do not use this form to seek free technical assistance - Try AllExperts...

Excellent Your Email:
Good Comments or Suggestions
Useful
Slightly useful
Not useful
        
Dont forget those backups






Home Thai Guide   Great Circle Calculator WorldClock AMS Services Contact us