Hi,
Sorry for the delay.. I've been having a few tech problems for the last couple of days..
Essentially, problems with shingled drives in a NAS and with two laptops.. Ho hum..
Creation of a bootable flashdrive to allow an OS to be run on a machine that doesn't recognise the host controller in BIOS (e.g. SD-card slots or USB 3 controllers.). This write up covers legacy mode only. (minor changes are required for EFI or hybrid EFI/legacy modes.)
Overall process:
1.) Format boot flashdrive as Fat32 legacy (MBR). This is the default with most flashdrive tools.
2.) Install a legacy Master Boot Record to the boot flashdrive.
3.) Install Grub2 to the boot flashdrive.
4.) Copy your target kernel & initrd to the boot flashdrive.
5.) Create a basic grub.cfg and copy it to the boot flashdrive.
Prepare boot flashdrive:
1.) It is required that the flashdrive is formatted fat32 in legacy mode (with a traditional MBR).
Most tools will, by default, produce a legacy fat32 formatted drive but may not have the capability to write a Master Boot Record to a USB flashdrive.
2.) There are a few tools which will handle this task. It's even possible to use "dd" to copy an existing MBR to a file and then write the contents of this file to the flashdrive. Be aware that it's quite easy to make mistakes and cause further problems using "dd" (aka "data destroyer") if you are not careful. Been there.. Done that!!
I personally prefer "testdisk" as I often use it for file and partition recovery purposes. This tool will correctly write an MBR to a USB flashdrive.
Brief usage:
Plug in your flashdrive. Unmount it if your system automounts. (e.g. sudo umount /dev/sdc1 if this is your USB flashdrive partition.)
Run testdisk in a terminal and select a log file for documenting changes (if required.. not really necessary here.).
Choose your USB device and select "Proceed"
Select the hard disk type: "Intel" should be selected for our purposes here (conventional MBR/BIOS). Don't select "EFI GPT" for (U)EFI or GPT systems.
Select "Analyse" and "Quick Search". If you see any drive geometry warnings.. abort the process and reformat the flashdrive.
Your flashdrive partition should be detected. Now use the left & right cursor keys to change the partition type from (P FAT32 LBA) to (* FAT32 LBA)
Press Enter and then cursor right to "Write" and press enter.
Now press 'y' to confirm the write. This will now (re)write the MBR. Press enter for "OK". Cursor down to "Quit" and then cursor right to another "Quit".
Finally remove and then reinsert the flashdrive.
3.) (As Root) Create a directory on the flashdrive and install grub2:
Mount the filesystem located on the USB drive:
Code:
# mount /dev/sdXY /mnt
'X' is your drive designation and 'Y' is the partition number (It will be '1' here.)
Create the directory /boot:
Install GRUB on the USB drive:
Code:
# grub-install --target=i386-pc --recheck --boot-directory=/mnt/boot /dev/sdX
NOTE: If you don't wish to use "grub-install" then it's fine to manually copy the grub files from your target OS (See the directory tree below.).
4.) Copy your kernel and initrd from your target OS to a temp. directory on your main machine.
Create a grub.cfg (using any text editor) in this temp. directory.
This file should contain something like this:
Code:
menuentry 'Flashdrive boot' {
insmod part_msdos
insmod ext2
linux /boot/vmlinuz-4.15.0-54-generic root=UUID=1a4c87b5-bee6-48f4-90cb-5424a7759daa ro quiet $vt_handoff
initrd /boot/initrd.img-4.15.0-54-generic
}
NOTES:
The UUID here must be that of your target system partition filesystem.
The use of the Grub module "ext2" supports ext2, ext3 & ext4 filesystems. I'm assuming that your target OS is on an ext4 partition.
The full filenames of the kernel (vmlinuz*) and initrd (initrd*) must be accurate. Ensure that these names match those in your temp. directory.
5.) Finally, copy your grub.cfg, kernel & initrd from your temp. directory to your boot flashdrive. The directory structure should be as follows:
Code:
./
└── boot
├── grub
│ ├── fonts
│ │ └── unicode.pf2
│ ├── grub.cfg
│ ├── grubenv
│ └── i386-pc
│ ├── acpi.mod
│ ├── adler32.mod
│ ├── affs.mod
│ ........
│ ........{ listing truncated here }
│ ├── uk.mo
│ ├── vi.mo
│ ├── zh_CN.mo
│ └── zh_TW.mo
│
├── initrd.img-4.15.0-54-generic
└── vmlinuz-4.15.0-54-generic
(The kernel & initrd file names are examples here.)
You may find a couple of extra directories here.. as created by your local version of "grub-install". Just ignore these.
Don't forget to unmount your flashdrive:
You are now ready to test your boot flashdrive with your target OS flashdrive.
Any problems or clarifications required.. just ask here.
Bodge99