Partitioning drives from a Windows command prompt

I found myself needing to partition a LUN on one of the Windows servers I support, and was curious how to perform this operation from a shell prompt. After a bit of googling, I came across the diskpart utility. This nifty little utility allows you to view devices, create and destroy volumes, and modify partition tables. The syntax for the commands available to diskpart can be viewed by running the “help” subcommand:

C:\Bin>diskpart

DISKPART> help

Microsoft DiskPart version 5.1.3565

ADD         - Add a mirror to a simple volume.
ACTIVE      - Marks the current basic partition as an active boot partition.
ASSIGN      - Assign a drive letter or mount point to the selected volume.
BREAK       - Break a mirror set.
CLEAN       - Clear the configuration information, or all information, off the
              disk.
CONVERT     - Converts between different disk formats.
CREATE      - Create a volume or partition.
DELETE      - Delete an object.
DETAIL      - Provide details about an object.
EXIT        - Exit DiskPart
EXTEND      - Extend a volume.
HELP        - Prints a list of commands.
IMPORT      - Imports a disk group.
LIST        - Prints out a list of objects.
INACTIVE    - Marks the current basic partition as an inactive partition.
ONLINE      - Online a disk that is currently marked as offline.
REM         - Does nothing. Used to comment scripts.
REMOVE      - Remove a drive letter or mount point assignment.
REPAIR      - Repair a RAID-5 volume.
RESCAN      - Rescan the computer looking for disks and volumes.
RETAIN      - Place a retainer partition under a simple volume.
SELECT      - Move the focus to an object.

To view the physical devices connected to a system, you can use the diskpart “list disk” subcommand:

C:\Bin>diskpart

DISKPART> list disk

  Disk ###  Status      Size     Free     Dyn  Gpt
  --------  ----------  -------  -------  ---  ---
  Disk 0    Online        28 GB      0 B

To view a device’s partition table, you can select a disk and run the “list partition” subcommand:

C:\Bin>diskpart

DISKPART> select disk 0

Disk 0 is now the selected disk.

DISKPART> list partition

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    Primary             28 GB    32 KB

You can also list the volumes available to the system with the “list volume” subcommand:

C:\Bin>diskpart

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D                       CD-ROM          0 B
  Volume 1     C                NTFS   Partition     28 GB  Healthy    System

Windows has some awesome utilities buried in the Windows folder, and the new shell should make automating tasks on Windows platforms a TON easier. Shibby!

Viewing Java stack traces with jstack

I wrote yesterday about the jmap utility, which is a great utility for better understanding the arrangement of the JVM’s heap. Each thread that lives inside the JVM also contains an execution stack, which is used to store local variables and state information to allow function calls to work. The Java SDK /JRE comes with the jstack utility, which can be used to print the stack of each thread in human readable form:

$ /usr/java/bin/jstack `pgrep java`

Attaching to process ID 16498, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 1.5.0_06-b05
Thread t@25: (state = BLOCKED)
 - java.lang.Thread.sleep(long) @bci=721371649 (Interpreted frame)
 - java.lang.Thread.sleep(long) @bci=0 (Interpreted frame)
 - com.sun.patchpro.model.PatchProStateMachine$17.synchronize(com.sun.patchpro.util.StateMachine) @bci=30, line=828 (Interpreted frame)
 - com.sun.patchpro.util.State.run() @bci=45, line=261 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=595 (Interpreted frame)


Thread t@23: (state = IN_NATIVE)
 - java.lang.UNIXProcess.waitForProcessExit(int) @bci=0 (Interpreted frame)
 - java.lang.UNIXProcess.waitForProcessExit(int) @bci=0 (Interpreted frame)
 - java.lang.UNIXProcess.access$900(java.lang.UNIXProcess, int) @bci=2, line=17 (Interpreted frame)
 - java.lang.UNIXProcess$2$1.run() @bci=17, line=86 (Interpreted frame)


Thread t@21: (state = BLOCKED)
 - java.lang.Thread.sleep(long) @bci=144113 (Interpreted frame)
 - java.lang.Thread.sleep(long) @bci=0 (Interpreted frame)
 - com.sun.patchpro.plugins.sunos.pkg.SunOSBaseDataExtension.buildDatabase(java.io.InputStream) @bci=54, line=258 (Interpreted frame)
 - com.sun.patchpro.plugins.sunos.pkg.SunOSBaseDataExtension.run() @bci=110, line=112 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=595 (Interpreted frame)


Thread t@17: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=706035048 (Interpreted frame)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.Thread.join(long) @bci=70, line=1103 (Interpreted frame)
 - com.sun.patchpro.analysis.SunOSBaseData$DetectorThread.join(int) @bci=6, line=310 (Interpreted frame)
 - com.sun.patchpro.analysis.SunOSBaseData.run() @bci=310, line=132 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=595 (Interpreted frame)

[ ..... ]

Each stack frame contains the state (e.g., runnable, blocked, etc) of the thread and a stack backtrace with the current stack frame displayed first. Good stuff!

Viewing Solaris patches with patchadd

The Solaris patchadd utility is well known for being able to apply a patch to a system, but few people know that it has a nifty “-p” (print installed patches) option to print the list of installed patches:

$ patchadd -p

Patch: 118996-02 Obsoletes: Requires: Incompatibles: Packages: SUNWcsu SUNWhea
Patch: 118868-01 Obsoletes: Requires: Incompatibles: Packages: SUNWcsu
Patch: 119687-01 Obsoletes: Requires: Incompatibles: Packages: SUNWcsu
Patch: 119042-02 Obsoletes: Requires: Incompatibles: Packages: SUNWcsu
Patch: 117461-04 Obsoletes: Requires: Incompatibles: Packages: SUNWcsu SUNWcsl SUNWtoo SUNWcslr SUNWhea
[ ...... ]

I recon ‘showrev -p’ is used a bit more frequently, since this is what the official patch documentation uses to list installed patches. It’s the little things in life that make you the happiest. :)

Creating a Veritas Volume Manager volume from a plex

While cleaning up my Veritas VxVM notes this week, I came across one of my cheat sheets for creating volumes from plexes. This can be useful when you want to perform an offline backup of the data on an alternate server, or when you want to grab a spare copy of data prior to performing a major change. To create a new volume from a plex, you will first want to stash a copy of the vxprint output somewhere:

$ /usr/sbin/vxprint -hmQq > $HOME/vxprint.restore

Once you make a backup, you will want to run the human consumable form of vxprint to see which devices are available:

$ /usr/sbin/vxprint -hft

Disk group: oradg

DG NAME         NCONFIG      NLOG     MINORS   GROUP-I
ST NAME         STATE        DM_CNT   SPARE_CNT         APPVOL_CNT
DM NAME         DEVICE       TYPE     PRIVLEN  PUBLEN   STATE
RV NAME         RLINK_CNT    KSTATE   STATE    PRIMARY  DATAVOLS  SRL
RL NAME         RVG          KSTATE   STATE    REM_HOST REM_DG    REM_RLNK
CO NAME         CACHEVOL     KSTATE   STATE
VT NAME         NVOLUME      KSTATE   STATE
V  NAME         RVG/VSET/CO  KSTATE   STATE    LENGTH   READPOL   PREFPLEX UTYPE
PL NAME         VOLUME       KSTATE   STATE    LENGTH   LAYOUT    NCOL/WID MODE
SD NAME         PLEX         DISK     DISKOFFS LENGTH   [COL/]OFF DEVICE   MODE
SV NAME         PLEX         VOLNAME  NVOLLAYR LENGTH   [COL/]OFF AM/NM    MODE
SC NAME         PLEX         CACHE    DISKOFFS LENGTH   [COL/]OFF DEVICE   MODE
DC NAME         PARENTVOL    LOGVOL
SP NAME         SNAPVOL      DCO

dg oradg        default      default  10000    1127240283.19.winnie

dm c1t1d0       c1t1d0s2     auto     2048     35521408 -
dm c1t2d0       c1t2d0s2     auto     2048     35521408 -
dm c1t3d0       c1t3d0s2     auto     2048     35521408 -
dm c1t4d0       c1t4d0s2     auto     2048     35365968 -
dm c1t5d0       c1t5d0s2     auto     2048     35521408 -
dm c1t6d0       c1t6d0s2     auto     2048     35521408 -

v  oravol01     -            ENABLED  ACTIVE   20971520 SELECT    -        fsgen
pl oravol01-01  oravol01     ENABLED  ACTIVE   20971776 STRIPE    3/128    RW
sd c1t1d0-01    oravol01-01  c1t1d0   0        6990592  0/0       c1t1d0   ENA
sd c1t2d0-01    oravol01-01  c1t2d0   0        6990592  1/0       c1t2d0   ENA
sd c1t3d0-01    oravol01-01  c1t3d0   0        6990592  2/0       c1t3d0   ENA
pl oravol01-02  oravol01     ENABLED  ACTIVE   20971776 STRIPE    3/128    RW
sd c1t4d0-01    oravol01-02  c1t4d0   0        6990592  0/0       c1t4d0   ENA
sd c1t5d0-01    oravol01-02  c1t5d0   0        6990592  1/0       c1t5d0   ENA
sd c1t6d0-01    oravol01-02  c1t6d0   0        6990592  2/0       c1t6d0   ENA

After you locate the plex you want to turn intoa volume, you will need to disassociate it from the volume with the vxplex utility:

$ vxplex dis oravol01-02

Once the plex has been disassociated, you can then turn it into a volume with the vxmake utility:

$ vxmake -U gen vol oravol02 plex=oravol01-02

After the volume is created, you can start it and mount it just like all of the other volumes on your server:

$ vxvol start oravol02

$ mount -F vxfs /dev/vx/dsk/oradg/oravol02 /mnt

$ ls -la /mnt

total 8388690
drwxr-xr-x   3 root     root        8192 Oct 30 21:01 .
drwxr-xr-x  37 root     root        1024 Oct 27 12:27 ..
drwxr-xr-x   2 root     root          96 Oct 27 12:25 lost+found
-rw------T   1 root     root     1073741824 Oct 30 20:59 oradata01.dbf
-rw------T   1 root     root     1073741824 Oct 30 21:00 oradata02.dbf
-rw------T   1 root     root     1073741824 Oct 30 21:01 oradata03.dbf
-rw------T   1 root     root     1073741824 Oct 30 21:03 oradata04.dbf

This is a nifty feature, and now that Veritas Volume Manager and File System are free (thanks for the link CW!), you can test it out in your favorite lab!