Installation of FreeDOS 1.4 on a USB stick using 'QEMU'
Practical use of a bootable USB stick with FreeDOS 1.4 operating system
Most firmware-updating software requires a DOS-like operating system. For example Lenovo. The idea is to have a bootable USB stick which can be used to update firmware and which can also be used as a regular USB stick for storing and transfering files. For 64 GiB USB stick there will be 4 partitions: 1st is 2 GiB FreeDOS 1.4 partition (FreeDOS 1.4 only consumes around 500 MiB of disk space, the rest of free space can be used for additional software when needed), 3 other sectors will be around 19 GiB (FAT32 file system does not like huge partitions and will perform worse with partition size close to 32 GiB; it is better for USB stick's performance and life span to have 3 smaller FAT32 partitions, rather than 1 huge FAT32 partition).
Requirements
- Computer where UEFI firmware is able to use 'Legacy mode' (CSM mode) with installed Debian-based operating system.
- USB stick.
Warning: all data on the USB stick will be destroyed during the installation!
In this guide the installation is performed on 64 GiB USB stick. Change the size of your partitions accordingly to your USB stick's maximum capacity.
Preparation
Turn on the computer, quickly press 'Delete' key, or 'F1' key
multiple times to launch the settings menu.
Enable 'Legacy mode' (CSM mode) in UEFI/BIOS setting of the computer.
Save changes and quit (usually 'F10' key).
Connect an USB stick to a computer.
Find the device name.
sudo dmesg
Read through the last entries of 'dmesg' output. In my case, the lines 'usb 2-5: New USB device found', 'usb 2-5: Product: Flash Drive' and '[sdb] 125313038 512-byte logical blocks: (64.1 GB/57.7 GiB)' indicate that the USB stick is identified as /dev/sdb.
Warning: if you select the wrong device during installation, all the data on that device will be destroyed.
Run 'lsblk' to list all avaliable devices.
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 953.9G 0 disk
├─sda1 8:1 0 560M 0 part /boot/efi
├─sda2 8:2 0 4G 0 part [SWAP]
├─sda3 8:3 0 120G 0 part /
└─sda4 8:4 0 829.3G 0 part /home
sdb 8:16 1 57.7G 0 disk
└─sdb1 8:17 1 57.7G 0 part
My USB stick has single partition formatted as exFAT by manufacturer. The USB stick will be repartitioned and all data on the partition along with partition table will be lost.
Warning: if you select the wrong device during the partitioning, all the data on that device will be destroyed.
Partitioning the USB stick
Make sure you are working with the correct device!
Check your $PATH variable.
echo "$PATH" | tr ':' '\n'
If it lacks '/sbin' and '/usr/sbin', add them (bash syntax).
declare -x PATH="$PATH:/sbin:/usr/sbin"
Use 'fdisk' to partition the USB stick.
sudo fdisk /dev/sdb
Type 'o' to create an empty partition table.
First partition:
Type 'n' to create a new partition.
Type 'p' to make partition primary.
Type '1' as partition number.
Press 'Enter' to set the default first sector.
Type '+2G' to set the last sector.
Type 'a' to make partition bootable.
Type '1' as partition number.
Type 't' to change partition's type.
Type '1' as partition number.
Type 'c' to set 'W95 FAT32 LBA'.
Second partition:
Type 'n' to create a new partition.
Type 'p' to make partition primary.
Type '2' as partition number.
Press 'Enter' to set the default first sector.
Type '+19G' to set the last sector.
Type 't' to change partition's type.
Type '2' as partition number.
Type 'c' to set 'W95 FAT32 LBA'.
Third partition:
Type 'n' to create a new partition.
Type 'p' to make partition primary.
Type '3' as partition number.
Press 'Enter' to set the default first sector.
Type '+19G' to set the last sector.
Type 't' to change partition's type.
Type '3' as partition number.
Type 'c' to set 'W95 FAT32 LBA'.
Fourth partition:
Type 'n' to create a new partition.
Type 'p' to make partition primary.
Type '4' as partition number.
Press 'Enter' to set the default first sector.
Press 'Enter' to set the default last sector.
Type 't' to change partition's type.
Type '4' as partition number.
Type 'c' to set 'W95 FAT32 LBA'.
Type 'w' to write changes to the USB stick.
Run 'lsblk' to ensure that everything is done correctly.
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 953.9G 0 disk
├─sda1 8:1 0 560M 0 part /boot/efi
├─sda2 8:2 0 4G 0 part [SWAP]
├─sda3 8:3 0 120G 0 part /
└─sda4 8:4 0 829.3G 0 part /home
sdb 8:16 1 57.7G 0 disk
├─sdb1 8:17 1 2G 0 part
├─sdb2 8:18 1 19G 0 part
├─sdb3 8:19 1 19G 0 part
└─sdb4 8:20 1 18.9G 0 part
Formatting the USB stick
Format the partitions as FAT32 filesystem. Make sure to specity '-F 32' parameter to 'mkfs.vfat' or it may automatically choose FAT16 filesystem. Use '-n' to set the volume name (label) to be able to easily identify it later. For FAT32 partition labels must be no longer than 11 characters and contain only uppercase letters.
sudo mkfs.vfat -F 32 -n 'FREEDOS14' /dev/sdb1
sudo mkfs.vfat -F 32 -n 'USBSTORE2' /dev/sdb2
sudo mkfs.vfat -F 32 -n 'USBSTORE3' /dev/sdb3
sudo mkfs.vfat -F 32 -n 'USBSTORE4' /dev/sdb4
Run 'blkid' with 'grep' to check newly created and formatted partitions.
blkid | grep 'sdb'
Installing 'QEMU':
sudo apt update
sudo apt upgrade -y
sudo apt autoremove
sudo apt install qemu-system-x86
Downloading FreeDOS 1.4
Download 'FreeDOS 1.4 FullUSB' from it's official web site.
Verify the dowloaded file:
sha256sum FD14-FullUSB.zip
Unpack the archive in a directory and 'cd' into that directory.
Installation of FreeDOS 1.4
Plug formatted USB stick (if if's not plugged already) into the computer and run:
sudo qemu-system-i386 -drive file=FD14FULL.img,format=raw -drive file=/dev/sdb,format=raw
After booting into FreeDOS 1.4 live image (FD14FULL.img) the installation prompt will be automatically launched.
Follow the instructions and install FreeDOS 1.4 on a first partition of a USB stick.
Quit 'QEMU', then use 'QEMU' again to test the result:
sudo qemu-system-i386 -drive -drive file=/dev/sdb,format=raw
If everything is correct, the USB stick is ready to use. Quit 'QEMU'.
Backing up the MBR
Display the information:
sudo fdisk -l /dev/sdb
MBR is stored on the first sector of the disk, and can be backed up with 'dd':
sudo dd if=/dev/sdb of=backup.mbr bs=512 count=1
To restore the MBR using 'dd':
sudo dd if=backup.mbr of=/dev/sdb bs=512 count=1
To restore just the bootloader and keep the partition table untouched:
sudo dd if=backup.mbr of=/dev/sdb bs=446 count=1
'sfdisk' can back up the partition table to a text file:
>| backup.txt sudo sfdisk -d /dev/sdb
This backup may be restored by passing it to 'sfdisk':
< backup.txt sudo sfdisk -f /dev/sdb
After restoring the MBR run 'partprobe':
sudo partprobe /dev/sdb
Installation of Lenovo firmware
Download the BIOS Update (USB Drive Package).
Unpack the archive and rename 'AUTOEXEC.BAT' to 'LENOVO.BAT'.
Plug the USB stick (if if's not plugged already) and copy everything to it's FreeDOS 1.4 partition.
Reboot the computer, quickly press F8, or F12 during startup to launch the
boot menu.
Boot from the USB stick into FreeDOS 1.4, run 'LENOVO.BAT' and follow instructions.