Friday 26 March 2010

I have bought 160GB USB Drive, but why I only get a disk size of 149 GB, where is the remaining 11 GB gone ?

Well, the answer lies in how the bytes are interpreted. Disk Manufacturers use "Decimal" as a base for calculation (i.e Base 10).


10^3 = 1000 bytes = 1 KiloByte , 10^6 = 1000 KB = 1 MegaByte , 10^9 = 1000 MB = 1 GigaByte

Whereas, the actual utilization is calculated using "Binary" as a base for calculation (i.e Base 2).

2^10 = 1024 bytes = 1 KiloByte , 2^20 = 1024 KB = 1 MegaByte, 2^30 = 1024 MB = 1 GigaByte

Note: Hard Disk Manufacturers will use 1000, not 1024 as base.


In this case, my USB drive has total bytes equal to = 160,039,239,690 Bytes. And we know 1 KB = 1024 Bytes, 1MB = 1024 Kilobytes, 1GB = 1024 Megabytes.

Hence, the total actual capacity comes to = 160,039,239,690 / 1024 x 1024 x 1024 = 149 GB.

In general, the capacity of a hard disk can be calculated using this formula:

Total Size of the Disk (Bytes) = (Cylinders) X (Heads) X (Sectors) X (Bytes per Sector)

Tuesday 9 March 2010

Virtual Floppy in a Virtual World!!

Until a few years back (probably a decade), as far as I remember there were not many known options but to test on the bare metal physical box and re-image every-time its screwed due to some stupid work of experimentation. With the advancement of virtualization everything seems possible now, I am glad that i got exposed to 'VMware' few years back, i am really impressed with their long range of vmware products, i think what they have provisioned is truly revolutionary.

Today one can play, emulate , crash , rebuild and learn as and when you want it without actually entering the IT hardware labs or a desktop machine at your home. One can install vmware products on the laptop (of course you need to ensure the minumum system requirements that each vmware products demands) and turn your laptop into a mobile testing lab.

There are no worries about re-imaging in case something going wrong and your system comes down crashing . In other words, without changing the physical state of your box (PC) you can now setup your own test environments. There is loads of information on the net about virtualization, you may also visit the vmware website to obtain more information about virtualization and vmware products. I chose 'vmware workstaion' product for my testing environment, and have been using it for past 2 years and i am really happy with its usage.



However, my objective here is to show one of the useful feature in vmware called "virtual floppy" drive. If you are thinking that floppy disks are "dead", right ? Well, you are absolutely correct that the physical floppy 3.5" disks (or physical floppy disks of any size) are not used anymore. In fact none of the PC vendors are providing this provision anymore but they are replaced with what is called "virtual floppy drives".

They provide many advantages over traditional floppy drives. Some of the advantages of using virtual floppies are:
  • Ability to boot OS and applications.
  • Ability to transfer files between systems .
  • Does not get damaged, as there is no physical state.
  • Can even be sent as attachment over the internet.

In this article, i will show you how to use virtual floppy drives with VMware Workstation product.


Whether you are a system admin, student, or from Quality Assurance department , you would be presented with scenarios wherein you will be required to test certain application, applicaiton feature(s) or at the least you want to try out few experimental stuff for learning purpose. One of the most important learning steps in System Admin's life is to learn to recover system from crash. More often than not, floppies comes handy in such rescue operations, especially if the system's MBR is currupted and you are unable to boot the system.


You must be wondering even if i have a virtucal floppy drive on my vmware workstation, how do i actually get the virtual floppies to work with. To do this , all you need is a vmware workstaiton runing any flavour of Unix or Windows OS as a gues operating system and a 'notepad' in the as we know in Windows.

Steps to create and mount 'virtual floppy' on your vmware workstaion:


1. Right click on the desktop and create a 'notepad'
2. Rename the "notepad" to any name, in this example i have named it "virtual-floppy", and ofcourse we need to change the extension of the notepad to "*.flp", this is the standard image format that vmware understands.
3. Go to your vmware workstaion, click on edit settings, click on the floppy drive, if it's not there then add it using "add" option under Hardware. Click 'browse to select the image we just created, in this case "virtual-floppy.flp".
4. Start the vmware workstaion, and wait untl it boots up to desktop screen (FYI: I am running Redhat linux as gues OS on vmware workstaion 5).
5. Now, we need to format the floppy with a filesystem and mount it.

The most commonly used tool is : mkfs
mkfs ("make a filesystem") is the standard Unix command for formatting a disk partition with a specific filesystem.

The basic syntax is:
mkfs -t type device , where type is the type of the filesystem and device is the device the filesystem will reside on.
The most commonly used option is -t, which is followed by the type of filesystem to be created. If this option is not used, the default is ext2 (second extended filesystem). Among the other types of filesystems that can be created are ext3, minix, msdos, vfat and xfs.


As an example, the following would create an ext2 filesystem on a formatted floppy disk that has been inserted into the first floppy drive:
mkfs /dev/fd0

The following would be used to create a vfat (i.e., Microsoft Windows-compatible) filesystem on the floppy disk.

mkfs -t vfat /dev/fd0
We will go for the "-vfat" option as this is both Unix and Windows compatible.

Now that our floppy is formatted and ready, we can copy files to it as if, it is physical floppy drive. The most importnat need of of floppy that i can think of is during emergency or when your system is crahsed and you need to get it back somehow. The fastest way to get your system back is to have a 'bootable floppy' handy with you.


When it comes to bootable floppy, there are lot of boot loaders, but GRUB stands out, perhaps the best bootloader among all. Let's install the GRUB on the floppy that we formatted in the last steps. For that, we need to mount the floppy, create a folder by name 'boot' and 'grub' and then copy grub files (stage 1 & 2) from the local disk to floppy disk grub folder.

mkdir -p /floppy/boot/grub
cp /usr/local/share/grub/i386-pc/stage* /floppy/boot/grub
Or
cp /boot/grub/stage* /floppy/boot/grub

Note: Always ensure the correct path to the grub folder, it may be differnt on your system.

Finally, we need to install the grub on the Floppy disk.
Start the executable at the Linux command prompt by typing :
grubenter the following series of commands at the grub prompt:
grub> root (fd0)
grub> setup (fd0)
grub> quit
We are done, we have now created a bootable virtual-floppy to work with virtual machines on the vmware application.