Friday, November 13, 2009

How to use files for ASM disks

One of the issues I've seen is that many people do not have an environment in which they can learn ASM, i.e. they don't have numerous disk to support an ASM setup. For example, if you have a single disk which already has a file system and would like to play around or learn ASM, how do you accomplish this? Turns out this is quite simple in UNIX/Linux using the 'dd' command to create a set of files, which are then associated with loop devices using 'losetup', and associated with raw devices using the 'raw' command.

The steps below are in no way unique so I can not take credit, I also do know the actual originator. I came across the method maybe in 2007 when I was seeking just such a method, and have recently found an article I thought I'd publish in my own words with a bit more detail. I have heard there is a similar method for Windows (makes sense), but as that is not my preferred platform I did not seek to either verify or test out that method.

Note that this setup should not be used in a production environment. It is strictly for testing or training purposes.

1. Create a directory under your file system(s) to store the ASM files.

$> mkdir /u02/asm
$> cd /u02/asm

2. Create files full of zeros using 'dd' command. I've used a block size of 32KB (bs=32K) to improve the build performance, and a count of 983040 to get files of 32GB. The files are named 'asmdiskX' (of=asmdisk1) where X is 1 to 4. I ran the four commands in parallel in the background, which took a really long time (almost 3 hours). No doubt this was due to the fact I was using a shared USB attached 500GB drive (with other things happening) so the operations could have probably gone quicker in serial, with less happening on the drive.

$> dd if=/dev/zero of=asmdisk1 bs=32K count=983040 &
$> dd if=/dev/zero of=asmdisk2 bs=32K count=983040 &
$> dd if=/dev/zero of=asmdisk3 bs=32K count=983040 &
$> dd if=/dev/zero of=asmdisk4 bs=32K count=983040 &

Note that I have run the commands as 'oracle', so I did not need to change ownership. If you have run as root then run the command below on the files to change their ownership to 'oracle':

$> chown oracle:dba /u02/asm/asmdisk*

3. Use 'losetup' to associate loop devices with the regular files (or block devices).

$> losetup /dev/loop1 /u02/asm/asmdisk1
$> losetup /dev/loop2 /u02/asm/asmdisk2
$> losetup /dev/loop3 /u02/asm/asmdisk3
$> losetup /dev/loop4 /u02/asm/asmdisk4

I believe there is a limit on the number of loop devices so you should check before running the commands if you have them available. On my system it was all clear, I've not tested but I believe the command below would create loop devices:

# create a new loop device
$> mknod /dev/loop/300 b 7 300

4. Use the raw command to associate the character block device with a raw device.

$> raw /dev/raw/raw1 /dev/loop1
/dev/raw/raw1: bound to major 7, minor 1

$> raw /dev/raw/raw2 /dev/loop2
/dev/raw/raw2: bound to major 7, minor 2

$> raw /dev/raw/raw3 /dev/loop3
/dev/raw/raw3: bound to major 7, minor 3

$> raw /dev/raw/raw4 /dev/loop4
/dev/raw/raw4: bound to major 7, minor 4

5. Change the ownership of the raw devices to 'oracle' and group to 'dba'.

$> chown oracle.dba /dev/raw/raw[1-4]

6. Setup a startup file to enable the setup to survive a reboot. Place commands from steps 3 to 5 into a script (/etc/init.d/asmsetup) which will run during system startup. An example script and steps are setup is below:

#!/bin/bash
#
# chkconfig: 2345 15 99
# description: Setup files to be used as ASM disks.

# Source function library.
. /etc/init.d/functions

disklocation=/u02/asm

prog=$"ASM file disk setup"

start()
{
echo -n $"Starting $prog: "
/sbin/losetup /dev/loop1 ${disklocation}/asmdisk1
/sbin/losetup /dev/loop2 ${disklocation}/asmdisk2
/sbin/losetup /dev/loop3 ${disklocation}/asmdisk3
/sbin/losetup /dev/loop4 ${disklocation}/asmdisk4
/bin/raw /dev/raw/raw1 /dev/loop1
/bin/raw /dev/raw/raw2 /dev/loop2
/bin/raw /dev/raw/raw3 /dev/loop3
/bin/raw /dev/raw/raw4 /dev/loop4
/bin/chown oracle.dba /dev/raw/raw[1-4]
}

# See how we were called.
case "$1" in
start)
start
;;
*)
echo $"Usage: $0 {start}"
exit 1
esac

$> chkconfig --add asmsetup

This creates the following files:

/etc/rc2.d/S15asmsetup
/etc/rc3.d/S15asmsetup
/etc/rc4.d/S15asmsetup
/etc/rc5.d/S15asmsetup

/etc/rc0.d/K99asmsetup
/etc/rc1.d/K99asmsetup
/etc/rc6.d/K99asmsetup

chkconfig refers the " # chkconfig: 2345 15 99" from asmsetup. This signifies that the service has start run level set to 2, 3, 4 and 5. Stop run level set to 0, 1 and 6 (the stop does nothing in this case). And the start priority should be 15 and stop priority be 99.

ASM now has disks which can be used. I'll write a follow-up on using these disks for an ASM installation. I'll be doing both version 11.1 and 11.2 for ASM but not sure which I'll write about yet (maybe both, maybe one). 11.2 is definately more interesting since I've done 11.1 already so that has the edge right now.

No comments:

Post a Comment