Saturday 26 January 2013

Using the SHIFT key to modify the behaviour of a grub4dos menu entry

If you have linux in your grub4dos menu.lst, you often need two entries, one for normal mode and one for safe mode so that you can boot on 'difficult' hardware.

This solution allows you to just have one menu entry but you can hold down SHIFT when you hit Enter to use safe mode parameters.

For this you need the bios utility on your drive (in this case in the root of the boot drive).You could also test for Ctrl or Alt and some other keys.

Note some lines are long and run over - use cut and paste!

title Run Linux\nPress SHIFT+ENTER for safe mode 
/bios int=0x16 eax=0x00000200 > (md)0x300+1
cat --skip=12 --length=2 (md)0x300+1 | set /a n=0x > nul 
set /a n=%n% & 0x03 > nul && if %n%>=1 echo SHIFT PRESSED! 
#set /a n=%n% & 0x04 > nul && if %n%>=1 echo CTRL PRESSED! 
set sf=
if %n%>=1 set sf=acpi=off irqpoll noapic noapm nodma nomce nolapic nosmp 
kernel /casper/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper %sf% splash 
initrd /casper/initrd.img

Bios Int 16 ah=2 reference here

NOTE: was...
/bios int=0x16 eax=0x00000200 > (md)0x300+1 && cat --skip=12 --length=2 (md)0x300+1 | set /a n=0x > nul

the 2nd half of the line is only executed if the BIOS returns non-zero. So && should not be used in this case.

Wednesday 23 January 2013

WinContig version updated in RMPrepUSB

RMPrepUSB now uses a later version of WinContig to make all files on a USB drive contiguous. I have had it crash on several occasions when running on my USB FAT32 flash drives. The new version seems much more stable. 

Monday 21 January 2013

Fix 'Error 60 - File not contiguous'!

You have probably come across this error message from grub4dos. It occurs when the file that it is trying to use is not contiguous.

To fix this you can run RMPrepUSB and select the USB drive and press Ctrl+F2 to run WinContig and defragment all files on the drive.

Making all file contiguous on a drive is not the same as defragmenting the drive. Defragmenting a drive shifts all the files to the beginning of the drive but often does not make all the files contiguous. WinContig does not shift the files if they are already contiguous and so WinContig is quicker and more effective than defragging the whole drive using a defrag utility.

Note: WinContig, Defraggler and other similar utilities usually need a contiguous run of free clusters on a drive so that they can copy the file into that contiguous space. Even after you run WinContig/Defraggler, you may not be able to copy over another large file and make it contiguous (even though there is enough free space on the drive) - see this post for details. Defraggler has an option to 'Defrag Free Space' which will fix this problem.

        This Defraggler map shows that the free clusters are not in one contiguous block. See here for more details.

To make a file contiguous,WinContig has to create a new file that is contiguous before it can delete the old non-contiguous file. Thus we need some contiguous free space on the drive that is the same size or larger than the size of the file we are trying to defragment. So for a 3GB file, we will need at least 3GB of contiguous free space on the same drive.

A file in a volume exists as a number of clusters (chunks of data). For example, a typical cluster size on an NTFS volume is 4K or 8 sectors. So a 10K file would occupy 3 clusters:

Cluster 1 = first 4K
Cluster 2 = 2nd 4K
Cluster 3 = 3rd 4K cluster (only first 2K of which has valid data)

These clusters can be anywhere within the volume. So they could be at cluster no 6,7 and 8 or they could be at cluster no. 3234, 44564 and 332!

A utility such as WinContig will rearrange the clusters within a file (if it can). So in the previous example, we might end up with the file consisting of cluster no.s  3234, 3235 and 3236 and so the file is contiguous and has sequential cluster numbers.

Recently, a user on had a problem. He had a 6GB VHD file on an 8GB NTFS-formatted USB drive. He ran WinContig but it would not make the file contiguous. Even copying the file to a freshly formatted 8GB NTFS drive did not work, the file was always non-contiguous.

It turns out that the reason for this is that when you format an NTFS volume, the Master File Table (MFT) is placed at the 3GB position within the volume (if the volume is over about 5GB). So on a freshly formatted 8GB volume, we have

(3GB of free space)
$MFT  (NTFS 'directory')
(4.7GB approx. of free space)

So we can see that there is no way we can store a 6GB sequential file with the MFT placed at the default 3GB position.

As the file is greater than 4GB, we cannot use a FAT32 filesystem (as FAT32 does not support files greater than 4GB).

You can see this if you use a utility such as Auslogics defrag tool which shows a map of the used clusters and what files occupy which areas of the disk.

Piriform's Defraggler is another good tool for displaying fragmented files and analyzing the file layout on a drive. It can also defragment individual files too (right-click in Explorer) and also offers to delete files in the Recycling Bin before defragging.

Alternatively, you can boot to grub4dos from the USB drive, go to the grub4dos shell (press c in the grub4dos menu) and then use the blocklist command to see how many fragments you have and where they are located - e.g.

So how can we make an 8GB USB flash drive containing a 6GB contiguous file?

Well, Wonko the Sane (from came up with the idea of making a small NTFS volume and then re-sizing it (expand it), thus leaving the MFT in the same place (as it is not normally moved when resizing).

Here is how to make a bootable 8GB USB drive containing a 6GB contiguous file using the partitioning tool EaseUS Home Partition Master (EHPM):

1. Erase all ptns on the 8GB flash drive
2. Make a small 20MB NTFS PRIMARY ptn using EHPM - or RMPrepUSB if you want a special bootloader
3. Re-Size the ptn using EHPM to ALMOST the full drive capacity - e.g. 7.8GB
4. Now add a small 2nd FAT PRIMARY partition (this is to improve boot compatibility with some BIOSes - the ptn is not actually used)
5. Copy over your large 6GB file and check it is contiguous using WinContig.

If you have Vista or Win7/8, then you can use Disk Manager instead of EaseUS Home Partition Master.

The whole discussion can be found on here.

Having trouble still? See also my other blog article here.

Recommended: SanDisk Extreme Pro USB 3.1 (#ad)

Monday 14 January 2013

Identify Unknown Devices in Device Manager

Came across a useful utility (UnknownDevices.exe  Dec 2012 version) by HalfDone which is intended to be run on a freshly-installed Windows system.

It looks at Device Manager (registry) entries and attempts to identify all the unknown devices which don't have drivers by using a database. It works on XP or later.
It also shows the Windows Product Key and lists a history of disk devices ever connected (inc. USB devices).
This is a useful addition for your toolbox!

As it relies on a database which needs to be updated as new hardware is released, you will need to get the latest version from the forum here.

Thursday 10 January 2013

fun with grub4dos batch files!

I have written a few new batch files which can be called by grub4dos - see here.

FindFullFileName.g4b - finds the first file matching a full filename
FindFileName.g4b - finds the first file matching a filename (without extension)
FindFileExt.g4b - finds the first file matching a file extension
title FindFileExt on mapped HDD Image
map  (bd)/harddisk.img (hd2)
map --hook
root (hd2,0)
# look for a file with a .com extension - param1=start folder   param2=extension
(bd)/grub/FindFileExt.g4b / .com
if not "%FILEPATH%"=="" echo FILE FOUND AT %FILEPATH%! 
if "%FILEPATH%"==""  echo No file with matching extension found!
(more commands here)
Please download to obtain these batch files.