Sunday, June 4, 2017

Solaris 10 - Adding swap device ufs partition, zfs volume and ufs file as swap device

A. Adding UFS partition as a Swap device

1. Create partitions

# format c1t0d0

# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344

2. Add partition as a swap device

# swap -a /dev/dsk/c1t0d0s1
# swap -a /dev/dsk/c1t0d0s3
# swap -a /dev/dsk/c1t0d0s4
# swap -a /dev/dsk/c1t0d0s5

3. List swap device
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344
/dev/dsk/c1t0d0s1   33,65      8 409592 409592
/dev/dsk/c1t0d0s3   33,67      8 409592 409592
/dev/dsk/c1t0d0s4   33,68      8 204792 204792
/dev/dsk/c1t0d0s5   33,69      8 204792 204792

4. Remove swap device
# for i in /dev/dsk/c1t0d0s1 /dev/dsk/c1t0d0s3 /dev/dsk/c1t0d0s4 /dev/dsk/c1t0d0s5
> do
> swap -d $i
> done
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344


B. Adding zfs volume as a swap volume


Create zfs mirror and create swap device using zfs filesystem

1. Remove the sub mirror from the pool
# zpool detach datapool c1t2d0
# zpool status datapool
  pool: datapool
 state: ONLINE
 scan: resilvered 454M in 0h0m with 0 errors on Sun Jun  4 09:00:42 2017
config:

        NAME        STATE     READ WRITE CKSUM
        datapool    ONLINE       0     0     0
          c1t0d0    ONLINE       0     0     0

errors: No known data errors

2. Mirror the disk
# zpool help attach
usage:
        attach [-f] <pool> <device> <new-device>
#  zpool attach datapool c1t0d0 c1t2d0


3. Create a swap volume
# zfs help
The following commands are supported:
allow       clone       create      destroy     diff        get
groupspace  help        hold        holds       inherit     list
mount       promote     receive     release     rename      rollback
send        set         share       snapshot    unallow     unmount
unshare     upgrade     userspace
For more info, run: zfs help <command>
# zfs help create
usage:
        create [-p] [-o property=value] ... <filesystem>
        create [-ps] [-b blocksize] [-o property=value] ... -V <size> <volume>
# zfs create -V 100m datapool/myswap

4. Locate your swap volume
# ls -l /dev/zvol/dsk/datapool/myswap
lrwxrwxrwx   1 root     root          35 Jun  4 09:09 /dev/zvol/dsk/datapool/myswap -> ../../../../devices/pseudo/zfs@0:1c
# zfs list
NAME                      USED  AVAIL  REFER  MOUNTPOINT
datapool                  557M   419M    32K  none
datapool/mydb             454M   419M   453M  /data/mydb
datapool/mydb/test         31K   419M    31K  /data/mydb/test
datapool/myswap           103M   522M    16K  -
mypool                    142K  1.95G    31K  none
mypool/opt_os              31K  1.95G    31K  /opt/os
yourpool                  189K  19.6G    31K  none
yourpool/FS_opt-OS_Image   31K  19.6G    31K  /opt/OS_Image
yourpool/fs-opt-os         31K  19.6G    31K  /opt/os


5. Add swap
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344
# swap -s
total: 273784k bytes allocated + 91588k reserved = 365372k used, 1264948k available
# swap -a /dev/zvol/dsk/datapool/myswap
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344
/dev/zvol/dsk/datapool/myswap 181,1       8 204792 204792
# swap -s
total: 273868k bytes allocated + 91572k reserved = 365440k used, 1366508k available
#

c. Adding file as a swap device

1. Create 100 MB of swap device
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344
/dev/zvol/dsk/datapool/myswap 181,1       8 204792 204792

# mkfile 100m /data/mydb/myswap

2. List current swap devices that are on use
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344
/dev/zvol/dsk/datapool/myswap 181,1       8 204792 204792

# swap -s
total: 273868k bytes allocated + 91572k reserved = 365440k used, 1267308k available

3. Add swap file as swap device
# swap -a /data/mydb/myswap
"/data/mydb/myswap" may contain holes - can't swap on it.

Since this is zfs filesystem, you can create number of swap volume.


lets try ufs filesystem

1. Create 100MB of file
# df -h /
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0d1s0        8.1G   4.0G   4.0G    51%    /

# mkfile 100m /myswapfile

2. List currently used swap devices
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344
/dev/zvol/dsk/datapool/myswap 181,1       8 204792 204792
# swap -s
total: 273868k bytes allocated + 91572k reserved = 365440k used, 1263380k available

3. Add swap device
# swap -a /myswapfile
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344
/dev/zvol/dsk/datapool/myswap 181,1       8 204792 204792
/myswapfile           -        8 204792 204792
# swap -s
total: 273868k bytes allocated + 91572k reserved = 365440k used, 1365776k available
#





No comments:

Post a Comment