I’ve recently moved to Ubuntu Linux, and this post describes my attempt to play around with Oracle ASM on Ubuntu. For this demonstration, I used Oracle 220.127.116.11 on Gutsy Gibbon. I hope it will be useful to somebody out there.
Important Notice: What I describe below is among the worst thing you can ever do with ASM. You can use it to play around but never use it with anything other than test data. If you lose something because of me, you’ll be the only one to blame !
Question #1: How do you simulate a disk from a file?
If you have a free partition or disk to be used as an ASM disk, just skip this step. If you don’t, you can create a file with the
dd command and create a device that actually loops to the file with the
Let’s assume you’ve created a directory named
/asmdisks (and you have write access to it). Run the command below to create a file named disk1 that is 3GB in size:
$ dd if=/dev/zero of=/asmdisks/disk1 bs=1024k count=3072 3072+0 records in 3072+0 records out 3221225472 bytes (3.2 GB) copied, 80.9113 seconds, 39.8 MB/s
Once you’ve created the file, map it to a device named loopN in
/dev. You can list the used loop devices with the
losetup -a command.
Once you’ve made sure the one you plan to used is free, e.g.
/dev/loop1, you can map the device to the file with the following commands (you have to be root) :
# losetup /dev/loop1 /asmdisks/disk1 # losetup -a /dev/loop1: :7438407 (/asmdisks/disk1)
Question #2: How do you create an interface to the disk that is usable by ASM?
Actually, the preferred way to access a disk from ASM on Linux is ASMLib. To be fair, I must say I didn’t even give it a try. Of course, I’d be more than interested if anybody could make it work on Ubuntu. You’ll have to recompile the source code and I doubt I’ll be able to do it myself.
So you may think, why not use Raw Devices? Because you don’t need raw devices. You can just map the ASM disks to your disk/partition or loop devices.
So the only thing you need to do to start is change the ownership of the device so that ASM can access it in read/write mode as
# chown oracle:dba /dev/loop1 # ls -l /dev/loop1 brw-rw---- 1 oracle dba 7, 1 2008-02-06 23:32 /dev/loop1
If you have a real disk partition (e.g.
# chown oracle:dba /dev/sdb1 # ls -l /dev/sdb1
I couldn’t manage to demonstrate 11g’s very cool offline ASM without ASMLib or raw devices. Nonetheless, I’ll describe how to set up raw devices on Gutsy later in this post.
If you want
losetup run and ownership set up automatically at boot time, you’ll have to define the correct rules in
Question #3: How do you start up the Cluster Synchronization Service Daemon?
You may not have paid attention to it before, but ASM relies on the CSS Daemon. Who cares? I do, because CSSD relies on
/etc/inittab to startup and there is no such a file in Ubuntu. Nevermind, run the setup script as root :
# /u01/app/oracle/product/11.1.0/db_1/bin/localconfig reset Successfully accumulated necessary OCR keys. Creating OCR keys for user 'root', privgrp 'root'.. Operation successful. Configuration for local CSS has been initialized Adding to inittab Startup will be queued to init within 30 seconds. Checking the status of new Oracle init process... Expecting the CRS daemons to be up within 600 seconds.
Once you get the message about the 600 seconds, hit CRTL+C to stop the script, and then run the command below to actually run the CSS Daemon:
# nohup /etc/init.d/init.cssd run >/dev/null 2>&1 </dev/null &
Note 3: If you want the CSSD daemon to startup automatically, you’ll have to create a service in Ubuntu.
Question #4: How do you create the ASM instance, add a diskgroup, etc?
This is not really the subject of this post, but assuming you’ve already installed Oracle 11g accordingly to Augusto’s Installing Oracle 11g on Ubuntu Linux 7.10 (Gutsy Gibbon) and you’ve setup the
ORACLE_BASE variables, you can do everything in one command:
$ dbca -silent -configureASM \ -asmSysPassword change_on_install \ -diskString "/dev/loop*" \ -diskList /dev/loop1 \ -diskGroupName DG1 \ -redundancy EXTERNAL
Once that is done, you can connect to the ASM instance with SQL*Plus:
$ source oraenv ORACLE_SID = [oracle] ?+ASM The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1 is /u01/app/oracle $ sqlplus / as sysdba SQL> select NAME, TOTAL_MB from v$asm_diskgroup; NAME TOTAL_MB
---- --------DG1 3072
Or you can use ASMCMD as below:
$ source oraenv ORACLE_SID = [oracle] ?+ASM The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1 is /u01/app/oracle $ asmcmd ASMCMD> ls DG1/
Question #5: How do you create a database that uses ASM?
I cannot resist providing the syntax for 11g (
totalMemory will have to be replaced by
memoryPercentage in 10g):
$ dbca -silent -createDatabase \ -templateName General_Purpose.dbc \ -gdbName BLUJ \ -sysPassword change_on_install \ -systemPassword manager \ -emConfiguration NONE \ -storageType ASM \ -asmSysPassword change_on_install \ -diskGroupName DG1 \ -characterSet WE8ISO8859P15 \ -totalMemory 250 ulimit: 1: Illegal option -u ulimit: 1: Illegal option -u ulimit: 1: Illegal option -u ulimit: 1: Illegal option -u Copying database files 1% complete 3% complete 37% complete Creating and starting Oracle instance 40% complete 45% complete 50% complete 55% complete 56% complete 60% complete 62% complete Completing Database Creation 66% complete 70% complete 73% complete 77% complete 88% complete 100% complete Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/BLUJ/BLUJ.log" for further details.
Question #2 (Revisited): How do you create an interface to the disk that is usable by ASM ?
For 11g ASM offline tests, raw devices can actually be useful. And, despite the missing pieces, creating a raw device that maps the loop device (or real disk/partition) is straightforward. The first step consists in filling the holes in Ubuntu, i.e. in creating some character files that are not created by default on Gutsy Gibbon (
raw0 . . .
Run the set of commands below as
# mknod /dev/rawctl c 162 0 # mknod /dev/raw/raw0 c 162 1 # mknod /dev/raw/raw1 c 162 2 # ln -s /dev/rawctl /dev/raw/rawctl
Once the missing pieces rebuilt, mapping a raw devices to your disk or loop interface is as easy as:
# raw /dev/raw/raw1 /dev/loop1
Or if you use a partition named
# raw /dev/raw/raw1 /dev/sdb1
You can display the result of your settings with the command below.
# raw -qa /dev/raw/raw1: bound to major 7, minor 0
The raw devices won’t change anything but the path to the device when you’ll go from Question #3 to Question #5.
Note 4: If you want the raw devices to be setup automatically at boot time, you’ll have to define the correct rules in
What I really like about Oracle is that once you’ve done something, you have ten different ways to go. I hope this post will enable you to explore some 11g’s new features on your favorite operating system.
Interested in working with Grégory? Schedule a tech call.