Thursday, November 19, 2009

How to install Windows 7 from a USB Flash Drive

Requirement
  • 4GB USB Drive (minimum)
  • Windows 7 ISO (32-bit or 64-bit)
  • Windows Vista
  • MBRwiz (Windows XP diskpart utility does not detect USB pen drives so this free utility will make the USB drive bootable)
  • MagicDisc (freeware utility to mount ISO as virtual drive)

Note:
My running OS during this setup (which worked) was Vista (32-bit for the 32-bit Win7). When I tried using XP, the process resulted in a bad boot sector so I could not use the USB Flash drive to load Windows 7. I've seen other blogs where the likely suspect is the 'bootsec.exe' command does not work properly when on XP (I've no idea why). Also, in Vista, you actually don't need the separate 'MBRwiz' program, as 'diskpart' will work just fine. The steps to use that process can be easily googled, or you can leave me a comment and I'll add those in this blog.

Steps
1. Connect your USB flash drive to your computer for formatting, and make note of the drive letter assigned. For the purposes of this tutotial we will use E:.

2. In Windows Explorer or other file management utility, right click on the USB drive and select 'Format…' from the context menu.



3. Click the 'Start' button to begin formatting your USB drive. This ensure there is nothing on the drive (starting from scratch if you will).



4. Open a command prompt window ('Start' menu -> 'Run…' -> cmd -> press 'ENTER') and type:

convert E: /fs:ntfs (remember E: is my drive letter so substitute with yours as appropriate).


5. Extract your download of MBRwiz (if not already done) to a location of your choice, and open a command window in the same location. Run the commands:

MBRWiz.exe /list (this gets a listing of all disks, so note down the disk number assigned to your USB drive which will be used in the next command)


MBRWiz.exe /disk=2 /active=1 (my disk was detected as '2', so replace this with whatever yours was detected as)



6. Install the MagicDisc software (if not already done) and mount your Windows 7 ISO as a virtual drive (mine was mounted as G:). You can of course use any other type of such software such as CD Anywhere, it does not matter. Alternatively, if you have a Windows 7 disk, or the full installation files otherwise you can use this, you do not need the ISO (I just happened to download it as such).



7. Open a command prompt window to the virtual drive, navigate below the 'boot' subdirectory and run the command:

bootsect /nt60 E: (E: was my drive letter substitute with yours as appropriate).



Note: This command will only work if the architectures match, i.e. I was using 32-bit Windows XP, and had a 32-bit Windows 7 media (and hence 'bootsect' file). When I tried using the same 'bootsect' command from the Windows 7 64-bit media it failed. I've not tested it yet, but it is likely that you can just run the 32-bit version of the 'bootsect /nt60 E:' command, and then continue with the steps for copying the 64-bit Winows 7 media to the USB drive and it should still allow installation from the USB (after all this command is only saying make the USB bootable to Windows 7, right?).

8. Copy all the files from your Windows 7 media (in my case ISO mounted virtual drive G:) to your USB drive. You should be able to use any file manager such as Windows Explorer (in my case I used Xplorer2 Lite which has dual pane views).



9. Before using your new USB drive with Windows 7 to boot and install Windows 7, ensure your BIOS is setup to boot from a USB drive. This is configured when rebooting by entering your BIOS, or just pressing F9 for a boot option screen in some cases. If all goes well Windows 7 installation should start from your USB drive.

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.