Blog hébergé par Yves et Iris :-)

Aller au contenu | Aller au menu | Aller à la recherche

Bootable flash drive for both Linux and Windows: BIOS and EFI

This is a new take on my 3-year-old series on the same subject, with the aim of having a portable toolbox for anything PC, from booting Linux, to having my favourite productivity tools at all time, to being able to rescue a broken disk or OS, and so on. This toolbox takes the form of a standard USB flash drive, made bootable and filled with all that I need, yet still uncluttered, and usable as any USB flash drive for transferring data.

This first article is about the “bootable” part.

Here are my goals:

  • There should be only one partition.
  • This partition should be bootable from both old-style BIOS-based systems and new-generation EFI systems.
  • The boot-loader should use the French keyboard, and provide access to some diagnosis and recovery tools.
  • The Linux OS should be hidden from Windows.
  • The Windows applications should be hidden from Linux.
  • All non-data folders should be hidden from both Linux and Windows, including the boot-loader folder.
  • However, the folder for the Windows applications must of course be visible from Windows (but not Linux).
  • No closed-source nor paid software.

First the boot-loader. A search among the boot-loaders let me see that the preferred boot-loader for my purpose is Grub2; it will accept to be installed inside any folder, and it proves to be a nice bridge between BIOS and EFI systems. For Grub2 to work on BIOS systems though, I will have to make sure there are at least 63 sectors of unused space before the partition on the flash drive.

Now the partitions. There is no choice here. An EFI system will boot a disk only if its EFI system partition (“ESP”) has a FAT filesystem and is of type EFI (read on, there’s an exception…). But if I partition my drive this way, Windows simply considers the ESP to be hidden :-( Thankfully, at least for USB drives, plain FAT32 partitions (with type FAT32 in a DOS-style partition table) are accepted too, as long as the EFI folder is present; and Windows does not hide the partition in this case :-) So FAT32 it is. This also means that I will not be allowed bigger-than-4GB files, which does not matter that much…

Conclusion: the flash drive will be ready after a single FAT32 partition is created in a DOS-style partition table, starting at least 63 sectors from the start of the drive, and set with the “bootable” flag.

For the partitioning, use whatever tools you like. I usually use fdisk or gparted. When creating the FAT32 partition, be sure to select a label! Let us say the label is “FLASH” for the remainder of this series. For example (you obviously have to adapt the following to your actual flash drive’s path; also, be advised that the following commands will wipe the flash drive):

# fdisk /dev/sdb
create a new empty DOS partition table: o
add a new partition : n
primary partition : p
partition number one : 1
start from the default (start+1MB) : ⏎
end at the default (end of drive) : ⏎
toggle a bootable flag : a
change a partition type : t
partition type (W95 FAT32) : b
write table to disk and exit : w
# mkfs.vfat -n FLASH /dev/sdb1

Next blog post will deal with the installation of Grub2.

Ajouter un commentaire

Le code HTML est affiché comme du texte et les adresses web sont automatiquement transformées.

La discussion continue ailleurs

URL de rétrolien :

Fil des commentaires de ce billet