Bulk ASM disks’ creation with Linux
10/03/2018 Leave a comment
Maybe sometime, you’ll have the need to add a quantity of disks to the Automatic Storage Management (ASM) to be used in the disk groups and so, have enough space for the tablespaces’ data files. Here you’ll find how to do this in a dynamic and fast way with the help of Linux tools.
Probably this procedure can work in Unix, however, this test is not made it yet.
Then lets begin with the main subject, you require the root user to make the tasks, or the user used for the installation and configuration of the ASM tools; in /dev, you have some disks (sdb, sdc, …) and its partitions (sdb1, sdc1, …):
# ls /dev/sd* /dev/sda /dev/sda2 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1 /dev/sdk1 /dev/sdl1 /dev/sdm1 /dev/sdn1 /dev/sda1 /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi /dev/sdj /dev/sdk /dev/sdl /dev/sdm /dev/sdn
The sda* does not count because it is the main disk of the server or computer where you have te operating system installation, or at least, its partitions.
So we’ll work just with the disks from sdb through sdm and in fact, with its partitions, I mean that ones with a 1 at the end:
# ls -1 /dev/sd[b-m]1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1 /dev/sdk1 /dev/sdl1 /dev/sdm1
Now, to create the sequence disk01, disk02, … for each one of the partitions when we’ll use the oracleasm command, we need to use an autoincrement based on the Linux awk command.
One initial and simple command to print something from 1 through the partitions number would be like:
# ls -1 /dev/sd[b-m]1 | awk '{ i++ } { print i }' 1 2 3 4 5 6 7 8 9 10 11 12
As you can see, I’m already using the partitions that will be part of the exercise, I mean, 12. Based on these, it generates the same quantity of consecutive numbers.
With this, now and easily with a printf the same sequence of numbers but using the %02d modifier to print two digits with leading zeroes (0):
# ls /dev/sd[b-m]1 | awk '{ i++ } { printf ("%02d\n", i) }' 01 02 03 04 05 06 07 08 09 10 11 12
And then with all of this pre-tasks, you just have to add the complete command text of the oracleasm:
# ls -1 /dev/sd[b-m]1 | awk '{ i++ } { printf ("oracleasm createdisk disk%02d %s\n", i, $1)}' oracleasm createdisk disk01 /dev/sdb1 oracleasm createdisk disk02 /dev/sdc1 oracleasm createdisk disk03 /dev/sdd1 oracleasm createdisk disk04 /dev/sde1 oracleasm createdisk disk05 /dev/sdf1 oracleasm createdisk disk06 /dev/sdg1 oracleasm createdisk disk07 /dev/sdh1 oracleasm createdisk disk08 /dev/sdi1 oracleasm createdisk disk09 /dev/sdj1 oracleasm createdisk disk10 /dev/sdk1 oracleasm createdisk disk11 /dev/sdl1 oracleasm createdisk disk12 /dev/sdm1
With this you just have to add the sh at the end in order to execute the commands:
# ls -1 /dev/sd[b-m]1 | awk '{ i++ } { printf ("oracleasm createdisk disk%02d %s\n", i, $1)}' | sh Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done Writing disk header: done Instantiating disk: done
After that, you can list the disks from with the oracleasm tool:
# oracleasm scandisks Reloading disk partitions: done Cleaning any stale ASM disks... Scanning system for ASM disks... # oracleasm listdisks DISK01 DISK02 DISK03 DISK04 DISK05 DISK06 DISK07 DISK08 DISK09 DISK10 DISK11 DISK12
Please, leave a comment if this post was useful for you or if you have any doubt about the contents, I will OrAnswer you as soon as possible.