There are two ways to add some swap space to your computer:
1) add another swap slice, the same size, on a different drive.
2) or add a file and dedicate it to swap.
The latter idea is mediocre at best, and the following example will
describe adding a swap slice.
Issues to note:
----------------
* The kernel will distribute the usage of multiple swaps on different
drives in a stripe style, if the swaps are identical size.
* It doesn't fill them sequentially or wait for busy drives.
* So we strive for identical sized swap slices.
* If the slice can't be identical in size, then larger.
* We can always make the swaps identical size in /etc/swaptab (in blocks).
* Adding a slice was discussed in Section (How do I list my partition and
slice layout? Is there a divvy?).
Here we go:
--- Adding a swap slice ---
There are two ways:
A) When you installed the drive with diskadd then prtvtoc/edvtoc.
This is kludgey, becasue the disksetup slice adding program
is not coded to specifcally deal with swap slices.
B) After the disk is installed, add a swap slice just like you would
add any other slice, except swap has a 0x3 tag. I'll describe
this way, so as to augment (How do I list my partition and slice
layout? Is there a divvy?). See that section if you need
to recall how to add a slice, in general.
Given:
A Uw71X system with two scsi hard drives on the same controller,
labeled with id 0, and id 12. Both drives have one Uw7/OSR6 partition
that is active. I know that disk2 slice 180 is free, so I'll use that:
(It's probably better to use the lower numbers and work your way up,
but I'd like to illustrate a slice number above 16 and issues like hex
names and device nodes).
Solution:
1) Determine the exact size and specifications of the swap
slice on disk1 that we'll duplicate on disk2.
prtvtoc -p /dev/rdsk/c0b0t0d0s0
prtvtoc -f /tmp/mytoc /dev/rdsk/c0b0t0d0s0
cat /tmp/mytoc | grep 0x3
I know that the TAG for a swap slice is 0x3. So I can grep
/tmp/mytoc for that TAG which shows, with my added titles, that:
SLICE TAG FLAG START SECSZ
2 0x3 0x201 642600 433755
I see that I'm trying to add a swap slice that's 433755 sectors.
From the prtvtoc -p I see that disk1 has 1115C, 255H, 63S/T, 512B/S.
A bit of math (255 * 63) tells me that the Magic Number for a disk1
cylinder is 16065 sectors. Now (433755 / 16065) = 27 cylinders.
And I can calculate that (433755 * 512) = 222082560 bytes.
So from all this I gather my requirements:
A) My new swap slice SLICE = 180.
B) My new swap slice TAG = 0x3
C) My new swap slice FLAG = 0x201
D) My new swap slice START is yet to be determined.
E) My new swap slice SECSZ would like to be = 433755
F) My new swap slice cylinders would like to be = 27.
2) Examine disk 2 and see if I can create that layout. The big issue
I'll face is my disk geometries may be different. I am trying
to have all swaps the identical size and have all swaps start and
end on cylinder boundaries. Here is a head to head comparison of the
output of the following commands on the two slices:
prtvtoc -p /dev/rdsk/c0b0t0d0s0
prtvtoc -p /dev/rdsk/c0b0t12d0s0
Cyl Heads Sec/Trk Bytes/Sec Magic Number
1115 255 63 512 16065
8748 64 32 512 2048
Check out the different Magic Numbers (sector size of a cylinder).
I can't make both swaps the same number of bytes if the second swap
slice is to end on a cylinder boundary.
I will get around this by making the new swap slice at least as large
as the first swap slice, in sectors that means >= 433755. Then I'll
make them exactly the same number of blocks in /etc/swaptab. In this
area of administration, 1 sector = 1 block = 512 bytes.
(2048 * 212) = 434176 sectors = SECSZ <-- Answer.
3) Now I'll create the second swap slice. This involves the procedure
outlined in Section (How do I list my partition and slice
layout? Is there a divvy?) above. I'll follow that procedure but use
the values I calculated in this Section, instead:
To summarize,
i. prtvtoc -f /tmp/swaptoc /dev/rdsk/c0b0t12d0s0
ii. vi /tmp/swaptoc.
iii. My new swap slice - SLICE = 180
iv. My new swap slice - TAG = 0x3
v. My new swap slice - FLAG = 0x201
vi. I see that I can start on START = 821248
vii. I showed that my - SECSZ = 434176
viii. Add slice 180 to swaptoc using values from iii, iv, v, vi, vii.
ix. Save /tmp/swaptoc and exit vi.
x. edvtoc -f /tmp/swaptoc /dev/rdsk/c0b0t12d0s0
4) The second swap slice is created and now I add it to the list of
devices that swap uses, by adding the block device to the
/etc/swaptab file and making the exact same block size as the original.
I used slice 180 on drive 2, and that looks like:
Raw device /dev/rdsk/c0b0t12d0sb4
Block Device /dev/dsk/c0b0t12d0sb4
so /etc/swaptab looks like:
+----------------------------------------------------------------
| #swapname offset(in blocks) size(in blocks)
| /dev/swap 0 -
| /dev/dsk/c0b0t12d0sb4 0 433755
|
5) Reboot. Here I thought I was done without a reboot if I just entered
swap -c to load the /etc/swaptab file, but I got a Device not found
error. Low and behold, the raw and block devices for the second
disk slice 180 were not created after I did the edvtoc. My first
instinct was to make the device nodes by hand with mknod, so I did....
mknod /dev/rdsk/c0b0t12d0sb4 c 7679 436
mknod /dev/dsk/c0b0t12d0sb4 b 7679 436
Wrong again! The devices were made fine, but swap -c still said
Device not found. A bit more reading of man vtoc told me that
the device nodes for slices 1-15 are created, but 16-183 are not,
unless the slice exists. This is all done at boot time, so I
concluded I needed a reboot :-/. I rm'd the two device nodes I
had created, rebooted, and everything worked perfectly.
swap -l lists the new swap
swap -l lists the new swap
path dev swaplo blocks free
/dev/swap 7679,2 0 433752 433752
/dev/dsk/c0b0t12d0sb4 7679,436 0 433752 433752
From the man 1M swap page (This is not recommended)
It may not always be possible to find an extra slice to solve a swap
problem. In that case, a file can be used. To create the swap space,
you need to create a file as big as the intended swap space. It is not
enough to simply create a zero-length file; it must be as large as the
intended swap space.
To do this, you can use the dd(1M) command, as shown in the following
example (which creates 32MB of swap space):
dd if=/dev/null of=/swapfile oseek=32 bs=1024k
Then add the following line to /etc/swaptab:
/swapfile 0 -
Then issue this command:
swap -c
The system will use the new swap file following the next reboot,
because swap -c is run from /etc/inittab at system start time.
<mschalit@pacbell.net>
gerberb@zenez.com
|