Design of a Dynamic Boot Loader for Loading an Operating System

: Boot Loader is the crucial program that loads the operating system in memory and initializes the system. In today’s world people are constantly on move and portable system are in demand specially the USB devices due to its portability and accessibility compared to CD/DVD drives. The purpose of this paper is to design a dynamic boot loader which removes the BIOS dependency and allow user to boot from USB without changing CMOS settings. The USB is devised as plug and play portable system with puppy Linux and newly developed dynamic boot loader. The device is experimented on a computer machine with 8 GB RAM, i5 processor, 64-bit Operating system and windows 7 and observed that nearly 50% reduction in booting time i.e., the time spent in changing the boot order is eliminated compared to the static boot loader. The time spent in the BIOS is dependent on the user knowledge in changing the boot priority. The portable system allows the user to work in ease in any environment with minimum requirement of Windows XP and USB 2.0 compatible system.


Introduction
Boot Loader is the first program that starts running after BIOS. Its task is to load the operating system in memory. The boot loader resides in the first sector of primary partition and the size is restricted to 512 bytes. Due to this size limitation, it becomes difficult to load and execute a 32 bit kernel. To accommodate more features the boot loader is divided into 3 stages. The first stage primary boot loader initializes the memory, hardware devices and loads the second stage boot loader. So there is no size restriction for secondary boot loader. Stage 1.5 which is 63 bytes is to interpret the file system. The boot process is as explained in Fig. 1.
The USB can be made bootable with different versions of Linux OS, Windows or Mac OS. Open source Operating systems are customizable, flexible, secure and freely available and so widely gaining popularity. Windows have restriction in installing to a drive other than the hard disk.
To boot from USB, the user needs to change the boot order and choose the USB to start the booting process from USB. The available boot process is static which is dependent on user changing the BIOS settings. In recent times, BIOS is being slowly replaced by Unified Extensible Firmware Interface (UEFI). UEFI secure boot allows only trusted OS to boot while locking out open source OS.  This paper proposes a dynamic boot loader which addresses the static boot. A light weight open source operating system is installed in the USB. This portable system can act as a substitute for personal laptop particularly for users who are constantly on move. It's easier to carry and the user can work on any borrowed system without having to worry about the security of the data transaction.

Related Work
Universal Serial Bus (USB) flash drives are leading portable storage device for storage and easy transfer of data from one computer to another. Due to its significant growth in usage many researchers have experimented with USB as portable device and as installation resources. The boot loaders discussed below are dependent on the user knowledge in changing the boot order to boot from USB. The dynamic boot loader concept removes this dependency as explained in the next section.
With USB gaining popularity as replacement for CD/DVD drives as installation medium to multi boot different ISO images, comparison study has been made using two boot loaders SYSLINUX and GRUB2 for various Linux based operating system (Sivaiah et al., 2014). The success rate of both the boot loaders to boot load the different OS have been graphed and found that SYSLINUX have higher rate compared to GRUB2. For every booting of ISO images from USB, it is needed to change the boot order in the BIOS to USB. The boot loaders are static and dependent on BIOS.
The USB can be utilized as both as installation medium and also as a portable device (Karna, 2010;Karna and Chen, 2014). Different experiments were conducted with Windows OS, Linux distributions, Opensolaris and Fedora and the results are tabulated. Windows OS has limitation in installing to a USB drive.
Security is the major concern for any portable device. Trusted Platform Module (TPM) ensures data security from hardware layer. With the advancement of USB technology, USB is developed as portable TPM (Kushwaha, 2013) and for portability the EFI System Partition (ESP) which contains the boot loader program is installed in USB. For every boot, the hash value is calculated and checked with the previous stored value in USB. Here USB acts as portable TPM. So securing USB becomes highly critical.
To build USB as portable device (Jebarajan and Sankar, 2011;Sankar, 2010;Kanahasabapathy et al., 2015), a customized kernel and boot loader is developed and written into the drive. The lightweight OS reduces the complexity of compressing and loading the kernel image from USB to RAM.

Design of a Dynamic Boot Loader
The dynamic boot loader methodology was proposed in my previous paper (Sebastian and Sankar, 2015). This eliminates BIOS dependency, thus providing a user friendly system and significantly reduces the load on the user.

Live USB
A USB drive of 16 GB is used. Lesser size USB can also be used as it requires less space to make USB bootable. USB is formatted with FAT32 file system which is the compatible file system for a USB. The USB is made bootable with kernel puppy slacko 6.3.2 and SysLinux boot loader using Unetbootin tool. It is a simple and small Linux OS distribution of size around 240 MB.
To make USB portable, in the first boot, the Live USB session is saved as 'slackosave-s1.2fs'. This allows booting to the saved session on next reboot. More sessions can be saved with different customizations. If session not saved any changes made will not be saved and on reboot it starts from the scratch. The session s1.2fs is saved in the sdb1 i.e., USB with extension ext2 and file size of 512 MB. The USB can be made bootable with persistent storage of max size 4GB and the session can be saved in the persistent storage partition. The OS writes only once to the flash drive on session close thereby reducing the number of writes to the flash drive.
The file 'slackosave-s1.2fs' is password protected for security. Every time on shutdown the session is automatically saved to the file. Now the USB is portable and the same data is available for booting from different machines. Still USB boot is dependent on boot order priority. The next section shows how to remove the dependency.

Booting Process
The Fig. 2 depicts the functional design of the booting process of the proposed design.

Dynamic Boot Loader
The dynamic boot loader consists of stage1, stage2 and w32grub and runs from USB on reboot.

W32Grub
W32grub is a windows version of grub boot loader to boot Linux based OS from windows. On yes to reboot from USB, the w32grub installs the grub in the windows boot sector, calculates the stage2 address and stores sector address in the stage 1 at address 0044-0047. Stage 1 loads stage 2 using this sector number. W32grub displays the below information: The stage 2 sector absolute address is stored as 0×7bb0c74f in stage 1 at address 0044-0047. The following commands display the 512 bytes of the USB MBR.

Stage 1
The windows boot loader stage 1 is in the Master Boot Record (MBR) which is the first sector of hard disk. The MBR is of size 512 bytes of which 446 bytes is the stage 1 boot loader, 64 bytes is the partition table which is 4 primary partitions of 16 bytes entries each and remaining 2 bytes which is 0xAA55 is boot record signature.
The above hexdump shows the stage 1 with relocatable address code which during the boot process gets loaded at address 0×7C00. On selecting the GRUB boot loader, the stage 2 is loaded in memory at address 0×8000.

Stage 2
Stage2 initializes the grub shell and loads the configuration file menu.lst from the directory boot/grub. The configuration file must contain the directory path and filename of the active partition where the kernel is stored and partition containing intird. Below are the configuration files where menu.lst is used for grub and grub.cfg file for grub2 for booting from USB.

Adding Boot Entries
The Boot Configuration Data (BCD) is the data store that represents windows boot manager, boot loader and other boot applications as objects (GUIDs) (https://docs.microsoft.com/en-us/previousversions/windows/it-pro/windows-server-2008-R2-and-2008/ee221031(v=ws.10)). Using BCD WMI (Windows Management Instrumentation) or bcdedit, the menu is edited to add GRUB as new entry.
The below bcdedit commands creates a GRUB entry in the boot menu as shown in Fig. 4, assigns the first 512 bytes, Stage 1 which is the linux.bin to GRUB.

Fig. 4: Windows boot menu
The above commands creates an entry with GRUB and when selected provides options for both windows and Puppy Linux booting.

Kernel
Kernel is a self extracting compressed image. The kernel vmlinz gets loaded from /dev/sdb1 which is the compressed bzImage at address 0x3a00 and loads the temporary root file system initrd at address 0x37eaa000. The bzImage is then decompressed to ramdisk and kernel is booted.

Init
The init in/sbin/init is the first process to run. The last step is the user space initialization function. The initrd is unmounted and real file system is loaded and system starts working as per the system runlevel under/etc/inittab.

Windows Management Instrumentation (WMI) is
Microsoft technology to retrieve information about disk drive, network configurations, Operating system and other internal state of computer systems. It uses query language to query and update any section of the WMI repository (https://msdn.microsoft.com/enus/library/aa384642(v=vs.85).aspx).
WMI query along with VB script is written to access information regarding USB drive number, host system details, BCD store edit and also to reboot the system. Below are few queries which retrieve the required windows information: • "SELECT * FROM Win32_OperatingSystem where Primary = true"-To reboot the system using Reboot () method under the win32_operating system class. • "SELECT * FROM Win32_LogicalDisk where DriveType = 3" -To get the properties of device drive. • "SELECT * FROM Win32_ComputerSystemProduct" -To get the properties about the computer system like Name, Version, UUID, etc.

Results
The dynamic boot loader designed completely eliminates the dependency on boot loader and the need for user knowledge on boot order change. The dynamic boot loader is implemented using VC++, VB script and WMI and the experimental result shows the dynamic boot loader takes less booting time when compared with the static boot loader. The minimum requirement for USB is 2.0 with size of 8GB with 4 GB as persistent storage to make it portable.
The booting time is measured using a stopwatch from the time the host system is rebooted to boot from USB. The experiment was conducted on computer machine with 8 GB RAM, i5 processor, 64-bit Operating system and windows 7.
The booting time for both existing and dynamic boot loader is tabulated as shown in Fig. 5. The time in seconds is measured and the result shows that more than 50% booting time improvement is attained when using the dynamic boot loader to boot from USB. Maximum time is spent in entering the CMOS settings and changing the boot order. This time is dependent on the user knowledge of changing the boot priority. The dependency time can be eliminated using the dynamic boot loader. The booting time measured may differ depending on the processor speed and specification but in all cases the dynamic boot loader eliminates the time spent in boot order change. Win XP x √ Win Vista x √ Win 7 x √ Win 8 x √ Win 10 x The above graph shows that the Live USB along with dynamic boot loader greatly reduces the booting time and makes it an excellent replacement as a portable device.
The designed boot loader works with any version of Windows Operating system. The user needs to plug in and reboot the system. The advantage of dynamic boot loader is that it supports USB both as a portable system and as an installation media for different type of OS.
Several experiments were conducted to test the working of the dynamic boot loader both as a portable medium and as an installation resource. The dynamic boot loader works efficiently with open source OS both for portable OS and installation medium whereas Windows OS only for installation medium. Both 32-bit and 64-bit OS's are supported. The results are tabulated as shown in Table 1.
The experiment conducted on few distributions of Linux OS as shown in the table and its scope is not limited to only the listed OS.

Conclusion
The Live USB increases the lifetimes of the USB to a great extent, since all writes are done in ram and saved only once in the USB on shutdown. The user can easily carry the portable USB anywhere and plug in and start running the customized session in less boot time. Implementing the dynamic boot loader concept allows any novice to use the portable USB system to run smoothly on any machine without worry about the knowledge of the BIOS settings. The designed system along with the fingerprint authentication will provide a highly secure and portable system.

Future Enhancements
The Live USB is vulnerable to attacks when used with other system. Biometric authentication is on high demand particularly for portable device. The Live USB with dynamic boot loader being portable can be integrated with fingerprint authentication to make the system a highly secure portable system. The USB is divided into 2 partitions with the first partition made read only and second partition the secure one protected with fingerprint. The read only partition contains the dynamic boot loader and fingerprint program. The private partition contains the kernel file and storage space for storing secured data. On reboot, it prompts the user to scan the fingerprint. The authorization process matches the fingerprint pattern against each of the stored pattern. On successful authorization the secured partition opens and kernel starts loading into RAM of the host machine.
The USB drive when used in a host environment, the transfer of data between host system and USB makes the data vulnerable for attacks. Since the OS runs from the USB and not dependent on the operating system of the machine, the proposed design achieves the security for the data stored as well as make the environment secure. The kernel image can be customized as per the requirement of the user. This will greatly improve the loading time of the OS to the host machine. Acknowledgment I sincerely thank my guide Dr. K. Siva Sankar for his continuous guidance and support for the successful completion of this work.

Author's Contributions
Alycia Sebastian: Design, conduct experiments, data analysis and manuscript writing.
Dr. K. Siva Sankar: Design analysis, interpretation of data and review manuscript writing.

Ethics
As corresponding author, I assure whole or any part of the manuscript is not under consideration for publication in any journal.