A usb drive with only 1 partition to load grub2 on usb-bootable machines with Legacy BIOS
, 64bit UEFI
or 32bit UEFI
.
Warning: the usb drive will be formatted, save your data before proceeding!
First of all, on you current installation, check if the folder /usr/lib/grub/
exists and is not empty.
If it is empty or does not exist, make sure the package grub-common (or equivalent for your distribution) version 2 or higher is installed.
Depending on the system, /usr/lib/grub/
will contain one or more of the following folders: x86_64-efi
, x86_64-efi-signed
, i386-pc
, i386-efi
, ...
The x86_64-efi
, i386-pc
and i386-efi
folders need to be present in order to install the corresponding bootloader on the usb drive.
sudo apt install grub-pc-bin grub-efi-ia32-bin grub-efi-amd64-bin
Now, find the device file for your usb drive. Here, the file is /dev/sdX
. Replace X
with the appropriate lower case letter(s) in the commands.
sudo fdisk -l /dev/sdX
sudo fdisk /dev/sdX
o
<enter>
n
<enter>
p
<enter>
1
<enter>
<enter>
<enter>
t
<enter>
e
f
<enter>
a
<enter>
w
<enter>
... in order to :
- Create a new empty DOS partition table
- Create a new partition
- Select primary partition type
- Set partition number to 1
- Start partition at the first possible sector
- Set partition end to the last possible sector
- Change partition type
- Set partition type to
EFI (FAT-12/16/32)
- Enable the bootable flag on partition 1
- Write the partition table
sudo mkfs.fat -F32 /dev/sdX1
sudo mount -o umask=000 /dev/sdX1 /mnt
sudo grub-install --no-floppy --boot-directory=/mnt/boot --target=i386-pc /dev/sdX
Install /EFI/BOOT/BOOTX64.EFI
and other grub files required to load grub from a 64-bit UEFI firmware :
sudo grub-install --removable --boot-directory=/mnt/boot --efi-directory=/mnt --target=x86_64-efi /dev/sdX
sudo grub-install --removable --boot-directory=/mnt/boot --efi-directory=/mnt --target=i386-efi /dev/sdX
mkdir /mnt/.disk
touch /mnt/.disk/info
touch /mnt/boot/grub/grub.cfg
(skip this if you already have a working grub.cfg for the usb drive)
mkdir /mnt/isos
mkdir /mnt/isos/xubuntu17_10-i386
Download an Ubuntu cd image (for example: Xubuntu 17.10 32-bit) :
Note: make sure there is enough space on the usb drive.
wget --directory-prefix=/mnt/isos/xubuntu17_10-i386 http://cdimages.ubuntu.com/xubuntu/releases/17.10/release/xubuntu-17.10.1-desktop-i386.iso
isoinfo -i /mnt/isos/xubuntu17_10-i386/*.iso -x /CASPER/VMLINUZ. > /mnt/isos/xubuntu17_10-i386/vmlinuz
isoinfo -i /mnt/isos/xubuntu17_10-i386/*.iso -x /CASPER/INITRD.LZ > /mnt/isos/xubuntu17_10-i386/initrd.lz
nano /mnt/boot/grub/grub.cfg
menuentry 'Xubuntu 17.10 i386'{
search --set=root --file /isos/xubuntu17_10-i386/vmlinuz
linux /isos/xubuntu17_10-i386/vmlinuz locale=fr_FR console-setup/layoutcode=fr boot=casper iso-scan/filename=/isos/xubuntu17_10-i386/xubuntu-17.10.1-desktop-i386.iso quiet --
initrd /isos/xubuntu17_10-i386/initrd.lz
}
Notes :
- The search command on the second line is only useful if you install the bootloader and the OS files on different partitions.
- Remove or change the value of the
locale
parameter to set the language of the live system. - Remove or change the value of the
console-setup/layoutcode
parameter to change the keyboard layout.
CTRL+O
<enter>
CTRL+X
sudo umount /mnt
...