How to create large bootable image of DOS for BIOS upgrades

Hello Fellows

Today I will show you quick and neat way to make your own bootable image of DOS 6.22 bigger than 2.88MB. With this you can easily upgrade your motherboards BIOS or some firmware for your hardware, that has a binary file bigger than 2MB, and can not fit in the commonly found images on the internet. Here is the list of things that will be needed before we can proceed:

# Requirements
– I’m doing this on top of Debian Wheezy.
– any kind of virualization software (in my case I will use: VirtualBOX)
– wget http://www.allbootdisks.com/downloads/ISO/AllBootDisks_ISO_Image_Downloads25/DOS6.22_bootdisk.iso (we are using this ISO as a base, because it is a very clean, without any unnecessary software)
– aptitude install kpartx (will be used to set up device mappings for the partitions of our image)
– aptitude install genisoimage (will be used to generate the actual .iso file which can be burned to CD and boot from it)

In this brief how to I will not explain the details about the installation of pre-required software. Now lets begin with few screenshots that will guide you in actual creation of VM. The VM will be needed only for it’s image file, that will serve us later to generate our own iso with included firmwares.

1) Create new virtual machine with the following ‘name’, ‘type’ and ‘version’:
01_begin_create_Vbox_VM

2) Set the memory for this VM, to 32MB. This will be more than enough, after all we are going to boot an OS that is approximately 20 years old :))
02_set_mem_size_for_VM

3) Choose to create new virtual disk image:
03_begin_create_virtual_disk_image

4) We need to use the VDI image type (this is important!):
04_set_virtual_disk_image_type

5) It is important that the size of the image is fixed!:
05_set_virtual_disk_image_fixed_size

6) Set the image size to desired value. For my usage patterns 64MB will be sufficient:
06_set_virtual_disk_image_size

7) After the VM is set up, it is time to start it, and set it up to boot the ‘DOS6.22_bootdisk.iso’. In this screen shot you can see, how it must looks when the boot process is over:
07_start_VM

8) Now we must “Create DOS Partition” for our 64MB image, using our good old friend ‘fdisk’:
08_begin_fdisk

9) Choose the “Create Primary DOS Partition”, we are going to need only one:
09_fdisk_setup

10) Use the hole disk space for this partition:
10_fdisk_setup

11) After the partition is ready, the system will reboot! This is important, so that we can see and format our newly created partition.
11_fdisk_setup

12) Now lets verify that everything is set up correctly. To do this we are starting the ‘fdisk’ tool again:
12_fdisk_setup

13) Choose the option ‘4’, and hit enter:
13_fdisk_setup

14) You must see the following info, from witch you can see that your partition is using 100% of the image size, but still has not have a filesystem:
14_fdisk_setup

15) Exit the tool, and create the file system with our other friend ‘format’:
15_format_disk_and_add_system_files

16) After the procedure is done, you can see that we have a file system, which also make our image a “System Disk” (the old term for bootable DOS 6.22 disk).
16_finish_format_disk_and_add_system_files

17) Ensure that our partition is setup correctly:
17_check_and_done

18) Now you can “power down” the VM, disable the bootable iso image “DOS6.22_bootdisk.iso”, and test if our new 64MB image is booting correctly:
18_disable_boot_iso_and_boot_from_HDD

After we are having good 64MB VDI image, that boot DOS 6.22, you can “power down” the VM and stop the VirtualBox application. When that is done, you can start the ‘Terminal’ and continue the journey:

19) First we will need few directories, so that we can work with them:

root@browseman:~# mkdir -p /mnt/flash/
root@browseman:~# mkdir -p /mnt/ISOs/DOS/SOURCE/BOOTIMG/

20) Now lets lists all virtual hard drive images in VirtualBox with the following command:

root@browseman:~# VBoxManage list hdds
...

...
UUID:        00c97bc7-dd42-457f-bae2-b8317550fe58
Parent UUID: base
Format:      VDI
Location:    /mnt/virt.images/Work/GEN_DOS/GEN_DOS.vdi
State:       created
Type:        normal
Usage:       GEN_DOS (UUID: a86b610c-a0e1-4136-919e-19e45236aee1)

21) Now it is time to convert our image from ‘VDI’ to ‘RAW’ type. Here is the command the you can use to do this (please NOTE the we are using the value of ‘UUID:’ field from above command to instruct the application to use the correct image for conversion). The new image will be stored in “/mnt/ISOs/DOS/own_64MB_dos_hdd.raw”:

root@browseman:~# VBoxManage clonehd 00c97bc7-dd42-457f-bae2-b8317550fe58 /mnt/ISOs/DOS/own_64MB_dos_hdd.raw --format RAW
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'RAW'. UUID: 578a9f96-f1cc-4584-9dd1-c5022fc3028d
root@browseman:~#

22) Lets mount our freshly created RAW image:

root@browseman:~# loopdev=$(losetup -s -f /mnt/ISOs/DOS/own_64MB_dos_hdd.raw)
root@browseman:~# kpartx -a $loopdev
root@browseman:~# ls /dev/mapper/loop*
/dev/mapper/loop0p1

root@browseman:~# mount /dev/mapper/loop0p1 /mnt/flash/
root@browseman:~#

If everything is correct you must see the following content in the mounted image:

root@browseman:~# ls -la /mnt/flash/
total 218
drwxr-xr-x 2 root      root      16384 Jan  1  1970 .
drwxr-xr-x 7 browseman browseman  4096 Aug  6 15:17 ..
-rwxr-xr-x 1 root      root      54645 May 31  1994 COMMAND.COM
-r-xr-xr-x 1 root      root      66294 May 31  1994 DRVSPACE.BIN
-r-xr-xr-x 1 root      root      40774 May 31  1994 IO.SYS
-r-xr-xr-x 1 root      root      38138 May 31  1994 MSDOS.SYS
root@browseman:~#

23) Now it’s time to copy our BIOS binaries and flash utilities (in my case three images for old MoBo’s):

root@browseman:~# cp -pr /mnt/ISOs/BIOS/* /mnt/flash/

root@browseman:~# ls -la /mnt/flash/
total 224
drwxr-xr-x 5 root      root      16384 Aug  6 19:07 .
drwxr-xr-x 7 browseman browseman  4096 Aug  6 15:17 ..
-rwxr-xr-x 1 root      root      54645 May 31  1994 COMMAND.COM
-r-xr-xr-x 1 root      root      66294 May 31  1994 DRVSPACE.BIN
-r-xr-xr-x 1 root      root      40774 May 31  1994 IO.SYS
-r-xr-xr-x 1 root      root      38138 May 31  1994 MSDOS.SYS
drwxr-xr-x 2 root      root       2048 May 23 13:27 x7dbe
drwxr-xr-x 2 root      root       2048 May 23 13:27 x7dbn
drwxr-xr-x 2 root      root       2048 Aug  5 16:26 x8dti-f

24) You can check that our image got bigger 🙂 :

root@browseman:~# df -H /dev/mapper/loop0p1
Filesystem                                              Size  Used Avail Use% Mounted on
/dev/mapper/loop0p1                                      67M  9.7M   58M  15% /mnt/flash

25) Now after the image has our files it is time to generate the bootable .iso image, which we can burn to CD (for example) and boot from it, to upgrade the BIOS. To do this first we must copy all files from the freshly modified RAW image to our source directory:

root@browseman:~# cp -pr /mnt/flash/* /mnt/ISOs/DOS/SOURCE/
root@browseman:~#

26) ‘Unmount’ the modified image and remove the configuration from dev-mapper:

root@browseman:~# umount /mnt/flash/
root@browseman:~# kpartx -d $loopdev
root@browseman:~# losetup -d $loopdev

27) It very important to copy the modified raw image in to specially created sub-directory of our source directory (the name of the sub-directory is not important, you can change it):

root@browseman:~# cp /mnt/ISOs/DOS/own_64MB_dos_hdd.raw /mnt/ISOs/DOS/SOURCE/BOOTIMG/own_64MB_dos_hdd.raw

28) Finally we are ready to create our .iso with this “simple” command:

root@browseman:~# genisoimage -hard-disk-boot -o /mnt/ISOs/DOS/own_boot_dos.iso -V DOSBIOS -b BOOTIMG/own_64MB_dos_hdd.raw /mnt/ISOs/DOS/SOURCE
I: -input-charset not specified, using utf-8 (detected in locale settings)
Size of boot image is 132096 sectors -> Emulating a hard disk
Warning: image size does not match geometry (131040)
 13.21% done, estimate finish Tue Aug  6 19:19:00 2013
 26.43% done, estimate finish Tue Aug  6 19:19:00 2013
 39.61% done, estimate finish Tue Aug  6 19:19:00 2013
 52.82% done, estimate finish Tue Aug  6 19:19:00 2013
 66.00% done, estimate finish Tue Aug  6 19:19:00 2013
 79.22% done, estimate finish Tue Aug  6 19:19:00 2013
 92.39% done, estimate finish Tue Aug  6 19:19:00 2013
Total translation table size: 2048
Total rockridge attributes bytes: 0
Total directory bytes: 8192
Path table size(bytes): 70
Max brk space used 1a000
37889 extents written (74 MB)
root@browseman:~#

Now you can burn the ISO image to CD and flash BIOS-es and firmwares like a boss :))

VERY IMPORTANT WARNING: BE VERY CAREFUL WHEN YOU FLASH DEVICES, IF YOU DON’T KNOW WHAT YOU ARE DOING YOUR DEVICE WILL BE DESTROYED PERMANENTLY!!!!!

Folder encryption with EncFS

Sometimes we have private information, here I am using EncFS tool to protect my data.I am describing in a few minutes installation steps.

ibekyarov@machine:~$ sudo aptitude install encfs

We have to activate fuse module in the kernel, because EncFS use it.By adding “fuse” without quotes in /etc/modules,kernel will load this module on every boot.Here we are loading fuse`s module in the kernel.

ibekyarov@machine:~$ sudo modprobe fuse

Because of using fusermount we need add our user to fuse group.

ibekyarov@machine:~$ sudo adduser ibekyarov fuse
Adding user `ibekyarov' to group `fuse' ...
Adding user ibekyarov to group fuse
Done.

Here we create directory which will be encrypted.

ibekyarov@machine:~$ mkdir ~/encfs_encrypted

Here we create our mounting point of encrypted directory.

ibekyarov@machine:~$ mkdir ~/encfs_decrypted

Let`s encrypt our target.

ibekyarov@machine:~$ encfs ~/encfs_encrypted/ ~/encfs_decrypted/
Creating new encrypted volume.
Please choose from one of the following options:
enter "x" for expert configuration mode,
enter "p" for pre-configured paranoia mode,
anything else, or an empty line will select standard mode.
?> p

Paranoia configuration selected.

Configuration finished. The filesystem to be created has
the following properties:
Filesystem cipher: "ssl/aes", version 3:0:2
Filename encoding: "nameio/block", version 3:0:1
Key Size: 256 bits
Block Size: 1024 bytes, including 8 byte MAC header
Each file contains 8 byte header with unique IV data.
Filenames encoded using IV chaining mode.
File data IV is chained to filename IV.
File holes passed through to ciphertext.

-------------------------- WARNING --------------------------
The external initialization-vector chaining option has been
enabled. This option disables the use of hard links on the
filesystem. Without hard links, some programs may not work.
The programs 'mutt' and 'procmail' are known to fail. For
more information, please see the encfs mailing list.
If you would like to choose another configuration setting,
please press CTRL-C now to abort and start over.

Now you will need to enter a password for your filesystem.
You will need to remember this password, as there is absolutely
no recovery mechanism. However, the password can be changed
later using encfsctl.

New Encfs Password:
Verify Encfs Password:
fuse: failed to open /dev/fuse: Permission denied
fuse failed. Common problems:
- fuse kernel module not installed (modprobe fuse)
- invalid options -- see usage message

We have the following errors:

fuse: failed to open /dev/fuse: Permission denied
fuse failed. Common problems:
- fuse kernel module not installed (modprobe fuse)
- invalid options -- see usage message

The solution is:

ibekyarov@machine:~$ sudo /etc/init.d/udev restart
Stopping the hotplug events dispatcher: udevd.
Starting the hotplug events dispatcher: udevd.
ibekyarov@machine:~$ sudo /etc/init.d/fuse restart
Restarting filesystem in userspace: fuse.

Mount the encrypted directory.

ibekyarov@machine:~$ encfs ~/encfs_encrypted/ ~/encfs_decrypted/

EncFS Password:

ibekyarov@machine:~$ df -h | grep encfs
encfs 5.7G 4.3G 1.2G 79% /home/ibekyarov/encfs_decrypted
ibekyarov@machine:~$ cd /home/ibekyarov/encfs_decrypted/
ibekyarov@machine:~/encfs_decrypted$ touch test_encryption
ibekyarov@machine:~/encfs_decrypted$ cd ..

This unmount our encrypted directory from the mountpoint.

ibekyarov@machine:~$ fusermount -u /home/ibekyarov/encfs_decrypted/
ibekyarov@machine:~$ ls /home/ibekyarov/encfs_encrypted/

If we  want to  change our EncFS password.

ibekyarov@machine:~$ encfsctl passwd ~/encfs_encrypted/
Enter current Encfs password
EncFS Password:
Enter new Encfs password
New Encfs Password:
Verify Encfs Password:
Volume Key successfully updated.

Enjoy 🙂

Show progress while copying with dd

Let me show you a little trick with the pv tool.
What is pv ? Pv is tool which can monitor the progress of data through a pipe.

apt-get install pv

Here is a simple example

dd if=/dev/zero bs=1M count=512 | pv -s 512M | dd of=/tmp/512M
512+0 records in60.5MB/s] [==========================================================================>    ] 96% ETA 0:00:00
512+0 records out
536870912 bytes (537 MB) copied, 6.27769 s, 85.5 MB/s
 512MB 0:00:06 [81.6MB/s] [=============================================================================>] 100%            
1048576+0 records in
1048576+0 records out
536870912 bytes (537 MB) copied, 6.27816 s, 85.5 MB/s

If we make hard disk clonning, we can use

pv -tpreb /dev/sda | dd of=/dev/sdb