Adding the Disk

Team-Fly    

Solaris™ Operating Environment Boot Camp
By David Rhodes, Dominic Butler
Table of Contents
Chapter 17.  Adding SCSI Devices


Now we're just about ready to connect the disk. We have decided to use a 4 GB drive that we have lying around and split it into the slices defined in Table 17.2.

Table 17.2. Disk Details

Slice

Size

Mount Point

Logical Device

0

2 GB

/data

/dev/[r]dsk/c1t2d0s0

0

2 GB

/spare

/dev/[r]dsk/c1t2d0s1

2

4 GB

- (backup slice)

/dev/[r]dsk/c1t2d0s2

Before we do, we need to take the machine down to the OK prompt (making sure no one is still using the machine!). After that we can make all the physical connections. We'll add a new SCSI controller to the system and connect the disk to that, which will be allocated SCSI ID 2.

Now we can use some of the OpenBoot PROM commands to check that the device is physically plugged in and functioning correctly. We'll do this by querying the devices connected to the SCSI bus and reading their PROM details. There are two commands to do this: probe-scsi, which only probes the default bus, and probe-scsi-all, which probes all the connected SCSI buses. Because we have connected our device to an auxiliary SCSI controller (in other words, not the main onboard one), we'll need to use the latter:

 helium# init 0 <lines removed for clarity> ok> probe-scsi-all /iommu@f,e0000000/sbus@f,e0001000/espdma@f,400000/esp@f,800000 Target 3   Unit 0    Disk    SEAGATE ST15230W SUN4.2G 0738 Target 6   Unit 0    Removable Read Only device SONY    CD-ROM /iommu@f,e0000000/sbus@f,e0001000/dma@3,81000/esp@3,80000 Target 2   Unit 0    Disk    SEAGATE ST15230W SUN4.2G 0738 ok> 

This shows that we have a disk and a CD-ROM connected to the internal SCSI bus, and our new disk, set to SCSI ID 2, connected to a separate SCSI bus. It's responding, which means the cable connections should be OK. We can also see that we don't have any conflicting IDs, so we can safely boot the machine.

We need to use the "reconfiguration" boot here so that the device nodes will be built and the system files will be updated correctly. We can do this in a few different ways: one is to use the boot -r command at the OK prompt; another is to create a file named /reconfigure while the machine is still up. The next time the system is booted it will see this file and perform the reconfiguration boot itself. A third way is to reboot with reboot -- -r. Whichever way you use, when the system boots we should start to see messages informing us that the device has been seen. The output below shows details of the internal disk (sd0), the internal CD-ROM (sd1), and the newly installed drive (sd2):

 ok> boot -r <lines removed for clarity> sd0 at esp0: target 3 lun 0 sd0 is /iommu@f,e0000000/sbus@f,e0001000/espdma@f,400000/esp@f,800000/sd@0,0        <SUN4.2G cyl 3880 alt 2 hd 16 sec 135> sd1 at esp0: target 6 lun 0 sd1 is /iommu@f,e0000000/sbus@f,e0001000/espdma@f,400000/esp@f,800000/sd@6,0        <Sony CD-ROM> sd2 at esp1: target 2 lun 0 sd2 is /iommu@f,e0000000/sbus@f,e0001000/dma@3,81000/esp@3,80000/sd@2,0        <SUN4.2G cyl 3880 alt 2 hd 16 sec 135> <lines removed for clarity> 

Device Tree

Good. The machine has now started booting, so let's take another look at the output above to see what we can determine about the new disk:

  • The kernel has allocated it an instance name, which is "sd2."

  • The physical device name has being generated and is set to /iommu@f,e0000000/sbus@f,e0001000/dma@3,81000/esp@3,80000/sd@2,0.

  • The logical device name can be determined from the string "esp1: target 2 lun 0" information, which in this case is c1t2d0.

We should be able to look at /etc/path_to_inst and tie all this information together. Let's look at the entries for both the original and the new disk:

 helium# grep sd /etc/path_to_inst "/iommu@f,e0000000/sbus@f,e0001000/espdma@f,400000/esp@f,800000/sd@3,0" 0 "sd" "/iommu@f,e0000000/sbus@f,e0001000/espdma@f,400000/esp@f,800000/sd@6,0" 1 "sd" "/iommu@f,e0000000/sbus@f,e0001000/espdma@f,400000/esp@f,800000/sd@2,0" 2 "sd" helium# 

First, we can see that the file has been updated and now contains details of the new disk. The first column is the physical device name, the second is the instance number allocated to it, and the last is the name of the device driver used.

We should also find that a number of logical device entries have been created under /dev. This will include entries for both the raw (rdsk) and the block (dsk) devices. Let's check these now:

 helium# cd /dev/dsk helium# ls <lines removed for clarity> c1t2d0s0    c1t2d0s2    c1t2d0s4    c1t2d0s6 c1t2d0s1    c1t2d0s3    c1t2d0s5    c1t2d0s7 helium# cd /dev/rdsk helium# ls <lines removed for clarity> c1t2d0s0    c1t2d0s2    c1t2d0s4    c1t2d0s6 c1t2d0s1    c1t2d0s3    c1t2d0s5    c1t2d0s7 helium# 

We can see that a device has been created for every partition, even though we have only defined sizes for a few of them. If we also take one of the entries at random, say /dev/dsk/c1t2d0s0, and run an ls -l on it, we should see that it is in fact linked back to the corresponding physical name.

 helium# cd /dev/dsk helium# ls -l c1t2d0s0 lrwxrwxrwx   1 root     root       79 Oct 25  2000 c1t2d0s0 -> ../../devices/iommu@f,e0000000/sbus@f,e0001000/dma@3,81000/esp@3,80000/sd@2,0:a helium# 

Lastly, let's run another listing, but this time follow the link and check its settings:

 helium# ls -lL c1t2d0s0 ls -lL c1t2d0s0 brw-r-----   1 root     sys       32,16 Nov 19  2000 c1t2d0s0 helium# 

First, we can see that the device is a block device, because the first character is a "b." The file's permissions and credentials have been applied to the file. These are obtained from a file named /etc/minor_perm. If we look at the entry for our driver, we see the following:

 helium# grep sd /etc/minor_perm sd:* 0640 root sys helium# 

Next, we have two numbers: the major device number and the minor device number. The major one is used to define the "general" type of device, and thus which driver is used for it. This is found in the file /etc/name_to_major. If we search for our major number (32), we can see it specifies the following driver:

 helium# grep sd /etc/minor_perm sd 32 helium# 

Following the major number is the minor number, 16 in this case. This is used to specify exactly which instance of the major device we are dealing with. This number again ties into the /etc/path_to_inst file. The minor devices are allocated sequentially, so the first disk (sd0) has the minor numbers 0 to 7, one for each partition. The next disk (sd1) has the next eight minor numbers, which means our disk sd2 has the next range, which is 16 through 23.

In other words, if we divide the minor device number by eight and drop any remainder, this will give us the instance number of the disk.

Format

At this point, we have successfully added the disk to our system and updated all the relevant files. Now we can go ahead and start to work with it. The first thing we need to do is define the partition map. We'll use the format program to do this. We'll use it interactively here, although it can also run noninteractively if you wish.

So, let's run format and work through creating the slices we require:

 helium# format Searching for disks...done AVAILABLE DISK SELECTIONS: 0) c0t0d0 <SUN4.2G cyl 3880 alt 2 hd 16 sec 135> /iommu@f,e0000000/sbus@f,e0001000/espdma@f,400000/esp@f,800000/sd@0,0 0) c1t2d0 <SUN4.2G cyl 3880 alt 2 hd 16 sec 135> /iommu@f,e0000000/sbus@f,e0001000/dma@3,81000/esp@3,80000/sd@2,0 helium# 

First, we need to make sure we select the correct disk. We don't want to start altering slices on the wrong one!

 Specify disk (enter its number): 1 [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         !<cmd>     - execute <cmd>, then return         quit 

Now we need to edit the partition map, which we can do using 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         !<cmd> - execute <cmd>, then return         quit 

Before we start to make any changes, let's print the current map to see what has already been defined:

 partition> print Current partition table (original): Total disk cylinders available: 3880 + 2 (reserved cylinders) Part    Tag    Flag  Cylinders     Size         Blocks   0       root wm    0 -   71   75.94MB  (72/0/0)    155520   1       swap wu   72 -  557  512.58MB  (486/0/0)  1049760   2     backup wu    0 - 3879    4.00GB  (3880/0/0) 8380800   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 alternates wm  558 - 3879    3.42GB  (3322/0/0) 7175520   7 unassigned wm    0           0       (0/0/0)          0 

We can see there are already some partitions defined. They are not the size we need (and there is also one too many), so we'll recreate them using the sizes we want. It doesn't really matter which slice we use, so we'll use the first two0 and 1. Let's make the changes to them both now:

 partition> 0 Part    Tag  Flag   Cylinders      Size            Blocks  0      root wm     0 -   71     75.94MB  (72/0/0)    155520 Enter partition id tag[root]: alt Enter partition permission flags[wm]: Enter new starting cyl[0]: Enter partition size[155520b, 72c, 75.94mb, 0.07gb]: 1940c 

Why use "1940c"? This means we would like to use 1,940 cylinders. We can specify the size of the partition in a number of ways including blocks (b), cylinders (c), MB (m), GB (g), or to the end of the disk ($). We have used this value because we know the full disk (slice 2) consists of 3,880 cylinders and we simply want to split the disk in half.

 partition> 1 Part     Tag  Flag   Cylinders      Size           Blocks  1       swap wu     72 -  557    512.58MB  (486/0/0)  1049760 Enter partition id tag[swap]: alt Enter partition permission flags[wu]: wm Enter new starting cyl[72]: 1940 Enter partition size[1049760b, 486c, 512.58mb, 0.50gb]:$ 

This time, we've also had to make the partition writeable and mountable (wm). It was previously unmountable as it was defined as a swap partition. We also know that this partition runs to the end of the disk, so when it prompts us for the size we can simply enter "$." If we print the map again, we can see that we now have the sizes we require, but we still have the remaining extra slice:

 partition> print Current partition table (original): Total disk cylinders available: 3880 + 2 (reserved cylinders) Part    Tag    Flag  Cylinders     Size         Blocks   0 alternates wm    0 - 1939    2.00GB (1940/0/0)  4190400   1 alternates wm 1940 - 3879    2.00GB (1940/0/0)  4190400   2     backup wu    0 - 3879    4.00GB (3880/0/0)  8380800   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 alternates wm  558 - 3879    3.42GB  (3322/0/0) 7175520   7 unassigned wm    0           0       (0/0/0)          0 

For neatness, we'll quickly run through setting it to zero. This is also useful because when we run commands such as prtvtoc later it won't confuse us. Don't forget that we leave partition 2 as the whole disk, so we just need to alter slice 6:

 partition> 6 Part     Tag  Flag   Cylinders    Size         Blocks   6 alternates wm    558 - 3879  3.42GB (3322/0/0) 7175520 Enter partition id tag[alternates]: Enter partition permission flags[wm]: Enter new starting cyl[558]: 0 Enter partition size[7175520b, 3322c, 3503.67mb, 3.42gb]: 0 

The map should now be up-to-date and only contain a definition for slice 2 (as we mentioned earlier), and the slices we are interested in. We'll print the map one final time to make sure we are happy with the new layout. It also gives us a chance to make sure we don't have any incorrect values or overlapping partitions:

 partition> print Current partition table (original): Total disk cylinders available: 2105 + 3 (reserved cylinders) Part     Tag  Flag   Cylinders    Size         Blocks   0 alternates wm    0 - 1939    2.00GB (1940/0/0)  4190400   1 alternates wm 1940 - 3879    2.00GB (1940/0/0)  4190400   2     backup wu    0 - 3879    4.00GB (3880/0/0)  8380800   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 

That's better! Now we can safely exit from format and the original partition map will be kept. To use the new map, we need to tell the disk to store the information, which we do by writing it to the disk using the label command. When we do this, the new partition map will become the current one. This means that the filesystem layout won't match the partition boundaries and will cause fsck and mount to fail if we tried to work with the original partitions:

 partition> label Ready to label disk, continue? Y 

All complete. We now have a disk that has our slices defined, so we can quit from the format program and continue working on the disk setup:

 partition> quit <lines removed for clarity> format> quit 
Format.dat

Prior to Solaris 2.3, the disk information needed to be specified with a data file, named /etc/format.dat by default. When format started it would search for any disks that were connected and try to match them to one of the entries in /etc/format.dat. This file is no longer required, as format will detect this information from the drive itself. It is, however, still a useful place to store any custom partition maps you would like to apply to any disks.

For example, we could generate the entry below for the partition map we have just created. This can be assigned to any other disk by using the "select" option within the Partition Menu:

 partition = "DAD_SUN4.2G" \     : disk = "SUN2.9G" : ctlr = SCSI \     : 0 = 0, 4190400: 1 = 1940, 4190400 : 2 = 0, 8380800 

Prtvtoc

We can display the volume table of contents (i.e., the partition map) from outside of format by using the prtvtoc command, as shown below:

 helium# prtvtoc /dev/rdsk/c1t2d0s2 * /dev/rdsk/c1t2d0s2 partition map * * Dimensions: *     512 bytes/sector *     135 sectors/track *      16 tracks/cylinder *    2160 sectors/cylinder *    4392 cylinders *    3880 accessible cylinders * * Flags: *   1: unmountable *  10: read-only * *                      First Sector  Last * Partition Tag Flags Sector Count   Sector Mount Directory        0     9   00        0 4190400 4190399        1     9   00  4190400 4190400 8380799        2     5   01        0 8380800 8380799 helium# 

This shows that we have our two slices and the backup slice on the disk. If we do a quick calculation, we can check that the sizes are correct too:

  • 1 sector = 512 bytes

  • 4,190,400 x 512 = 2145484800 bytes

  • 2,145,484,800 / 1,024 / 1,024 / 1,024 = 1.99 GB

Formatting Multiple Disks

Both format and prtvtoc are extremely useful and are often used for setting up multiple disks. For example, let's assume we have two disks that have the same geometry (number of heads, cylinders, and so forth). To copy the partition map of one (c0t0d0) to the other (c2t2d0), we could use the following command:

 helium# prtvtoc /dev/dsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c2t2d0s2 

This will only update an existing map though, which means the disk must have previously been labeled. If we wanted to apply a known map to a group of new (unlabeled) disks we could do this with format, following the steps below.

First we need to create a file that contains the responses that format would expect, one per line (but don't include any "yes" or "no" confirmations). The example below simply selects the Partition Menu, then selects slice 7 and sets it to 0 size by entering the correct responses to the following questions:

 Enter partition id tag[alternates]: <just hit return> Enter partition permission flags[wm]: <just hit return> Enter new starting cyl[100]: <0> Enter partition size[206010b, 126c, 100.59mb, 0.10gb]: <0> 

The file containing these responses is shown below:

 helium# cat /tmp/part_map partition 7 0 0 label quit quit helium# 

Once we have the data file, we can apply it to the group of disks as required. To apply it to all the disks connected to controller two (c2), we could use the following commands:

 helium# sh helium# cd /dev/dsk helium# for disk in $(ls c2*s2); do format -f /tmp/part_map -s $disk done helium# 

Add a Filesystem

Now that we have defined the two slices and labeled the disk, we need to lay a filesystem on each of them. Again, we've explained this before in Chapter 6, "The Filesystem and Its Contents," so we'll quickly run through the commands here. We're using newfs to do the job here and letting it run mkfs for us, which means the default options to mkfs will be used:

 helium# newfs /dev/rdsk/c1t2d0s0 /dev/rdsk/c1t2d0s0:     4190400 sectors in 1940 cylinders of 16 tracks, 135 sectors     2046.0MB in 80 cyl groups (46 c/g, 48.52MB/g, 6080 i/g) super-block backups (for fsck -F ufs -o b=#) at:  32, 99536, 199040, 298544, 398048, 497552, <lines removed for clarity> 4132567, 4160862 helium# 

We can see that the locations of the superblock backups are given. Often it's useful to have a log of these for times when fsck fails and needs us to specify an alternative superblock. We can often retrieve this information using the "-N" option to newfs, although we have to be aware of some caveats when doing this. First, the "-N" option simply runs newfs nondestructively. This means that if called with the same options, as when the original filesystem was created, it will output the same superblock locations. However, if newfs (or mkfs) was called with any nonstandard flags, then the output will be different. Obviously, this means the best time to get a copy of the superblock list is immediately after creating the filesystem, while we can remember which options were used!

With this in mind, let's create a log file now so that we have a copy of the information within our hierarchy:

 helium# newfs -N /dev/rdsk/c1t2d0s0 > /usr/local/utils/data/ vtoc/c1t2d0s0 helium# 

We also need to perform the same task for the second slice:

 helium# newfs /dev/rdsk/c1t2d0s1 <lines removed for clarity> helium# newfs -N /dev/rdsk/c1t2d0s1 > /usr/local/utils/data/ vtoc/c1t2d0s1 helium# 

Mount the Filesystem

Now the slices contain a valid filesystem and are ready to be mounted. First, we'll create the mount point for the device, then we'll run the filesystem checker (fsck) to make sure the filesystems are clean. They should be clean now, but you should always fsck the device before mounting it, unless you are using some type of journal/logging filesystem:

 helium# mkdir /data /spare helium# fsck /dev/rdsk/c1t2d0s0 ** /dev/rdsk/c1t2d0s0 ** 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, 2956350 free (12 frags, 115171 blocks,  0.1% fragmentation) helium# helium# fsck /dev/rdsk/c1t2d1s1 ** /dev/rdsk/c1t2d0s1 ** 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, 2956350 free (12 frags, 115171 blocks,  0.1% fragmentation) helium# helium# mount /dev/dsk/c1t2d0s0 /data helium# mount /dev/dsk/c1t2d0s1 /spare helium# 

Good. The partitions have mounted without any errors, so let's make sure we can see them:

 helium# df -k Filesystem         kbytes  used  avail capacity  Mounted on /proc                   0      0      0    0%  /proc /dev/dsk/c0t2d0s0   48349  16889  26626   39%  / /dev/dsk/c0t2d0s6  770543 522712 193893   73%  /usr fd                      0      0      0    0%  /dev/fd /dev/dsk/c0t2d0s1   61463   5592  49725   11%  /var /dev/dsk/c0t2d0s7  519718  82791 384956   18%  /export/home /dev/dsk/c0t2d0s5   38539   5928  28758   18%  /opt swap               130064     28 130036   1%   /tmp /dev/dsk/c1t2d0s0 1798534    100 1536260  1%   /data /dev/dsk/c1t2d0s1 1798534    100 1536260  1%   /spare helium# 

Lastly, we need to update /etc/vfstab to make sure the device is checked and mounted at boot-time. The new entries are shown below:

 helium# cat /etc/vfstab # #device    device   mount  FS    fsck  mount    mount #to mount  to fsck  point  type  pass  at boot  options # <lines remove for clarity> /dev/dsk/c1t2d0s0 /dev/rdsk/c1t2d0s0 /data  ufs 2 yes - /dev/dsk/c1t2d0s1 /dev/rdsk/c1t2d0s1 /spare ufs 2 yes  helium# 

    Team-Fly    
    Top
     



    Solaris Operating Environment Boot Camp
    Solaris Operating Environment Boot Camp
    ISBN: 0130342874
    EAN: 2147483647
    Year: 2002
    Pages: 301

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net