Bootable Linux USB stick: Difference between revisions

Jump to navigation Jump to search
update with complete writeup
No edit summary
(update with complete writeup)
Line 4: Line 4:
# the sticks should be fast USB3 (very good results with SANdisk Extreme 32GB). The computers do ''not'' have to be recent, nor do they have to have USB3 ports. USB2 ports support up to 30MB/s, but only USB3 sticks deliver this!
# the sticks should be fast USB3 (very good results with SANdisk Extreme 32GB). The computers do ''not'' have to be recent, nor do they have to have USB3 ports. USB2 ports support up to 30MB/s, but only USB3 sticks deliver this!
# we use Fedora 23 because its hardware support is very good. We always use the 64bit distro.
# we use Fedora 23 because its hardware support is very good. We always use the 64bit distro.
# we produce >50% BIOS-bootable sticks and the rest are EFI-bootable sticks (we have not yet found out how to combine this into one). The latter can be booted on MacBooks as well; their hardware works well with Fedora 23. For Windows clients, one has to make sure that "fast boot" (or "fast startup") is disabled (or Shift is pressed while shutting Windows down), and sometimes <pre>powercfg -H off</pre> (as Administrator in a console window) is additionally required; otherwise the USB stick may not boot. Occasionally we find a computer that does not boot from any of the sticks because the BIOS screen can not be reached (due to unknown BIOS password; happens with machines belonging to institutions which administer them centrally) or some such, but 19 out of 20 work as they should.
# The stick can be booted on MacBooks as well; their hardware works well with Fedora 23. For Windows clients, one has to make sure that "fast boot" (or "fast startup") is disabled (or Shift is pressed while shutting Windows down), and sometimes <nowiki>powercfg -H off</nowiki> (as Administrator in a console window) is additionally required; otherwise the USB stick may not boot. Occasionally we find a computer that does not boot from any of the sticks because the BIOS screen can not be reached (due to unknown BIOS password; happens with machines belonging to institutions which administer them centrally) or some such, but 19 out of 20 work as they should.
# performance tuning (not strictly required): We use an ext4 filesystem and <pre> data=writeback,nobarrier </pre> in /etc/fstab. To set the writeback option on the / filesystem one needs to use tune2fs on a Linux machine where the stick is just mounted (i.e. not booted from), with the option data_journal_writeback; one should also set nobarrier that way. With this tuning the stick is as fast as a local harddisk.
# performance tuning (not strictly required): We use an ext4 filesystem and <pre> data=writeback,nobarrier </pre> in /etc/fstab. To set the writeback option on the / filesystem one needs to use tune2fs on a Linux machine where the stick is just mounted (i.e. not booted from), with the option data_journal_writeback; one should also set nobarrier that way. With this tuning the stick is as fast as a local harddisk.
# we always create a few-GB FAT32 partition because that makes file exchange with Windows and Macs very simple
# we always create a few-GB FAT32 partition because that makes file exchange with Windows and Macs very simple
Line 12: Line 12:
To make students familiar with the sticks and how to boot them, one needs 30+ minutes and a few tutors.  
To make students familiar with the sticks and how to boot them, one needs 30+ minutes and a few tutors.  


If somebody figures out how to install Fedora23 sticks that boot on ''both'' BIOS- and EFI PC hardware, I'd like to hear about this.
'''Some more details'''


== Some more details ==
# As for normal OS installation it matters if for the installation of the stick your computer is booted in BIOS mode (on newer machines "CSM enabled") --> you obtain a stick which boots BIOS systems, or if for the installation your computer is booted in EFI mode --> you obtain a stick which boots in EFI mode on newer computers and Macs
# the SANdisk Extreme is the best stick we found; physically small sticks look nicer but are slow (even though they are called USB3)
# the SANdisk Extreme is the best stick we found; physically small sticks look nicer but are slow (even though they are called USB3)
# the FAT32 partition should be the first partition on the stick; 2GB is enough for us. Then comes the Linux partition, with 13.9GB, so that the sum of the two partitions is slightly below 16GB. The third partition is then a 16.1GB /data partition. This scheme has the advantage that the image of the stick can just as well be copied (with dd or better ddrescue) to a 16GB stick; the /data partition then does not fit and cannot be used on that stick, but the operating system will then work on the small stick just as well. This requires that the /data partition is not mounted automatically from /etc/fstab (i.e. it should be listed, but with the noauto option), but rather with a command like "mount /data &" from /etc/rc.local - because if the 16GB stick is booted, it will otherwise find a corrupt filesystem and the boot will fail, leaving you with a rudimentary shell prompt which only experts can recover from. Also this means that the image of the stick need only comprise the first 16GB (unless the /data partition already has something on it) - that makes it faster to copy it, and it is quite fast to re-create an empty /data partition after booting the stick.
# the FAT32 partition should be the first partition on the stick; 2GB is enough for us. Then comes the Linux partition, with 13.9GB, so that the sum of the two partitions is slightly below 16GB. The third partition is then a 16.1GB /data partition. This scheme has the advantage that the image of the stick can just as well be copied (with dd or better ddrescue) to a 16GB stick; the /data partition then does not fit and cannot be used on that stick, but the operating system will then work on the small stick just as well. This requires that the /data partition is not mounted automatically from /etc/fstab (i.e. it should be listed, but with the noauto option), but rather with a command like "mount /data &" from /etc/rc.local - because if the 16GB stick is booted, it will otherwise find a corrupt filesystem and the boot will fail, leaving you with a rudimentary shell prompt which only experts can recover from. Also this means that the image of the stick need only comprise the first 16GB (unless the /data partition already has something on it) - that makes it faster to copy it, and it is quite fast to re-create an empty /data partition after booting the stick.
Line 23: Line 19:
# it is a good idea to save an image of the stick whenever you made a successful change; otherwise you might need to start from scratch if you mess something up.
# it is a good idea to save an image of the stick whenever you made a successful change; otherwise you might need to start from scratch if you mess something up.
# (if the installation not already does it for you) '''you should label the partitions and use the labels for mounting the partitions in /etc/fstab; don't use /dev/sda1 or the like because depending on the hardware it is booted on, after booting the stick, and depending on the actual hardware, the stick may be /dev/sdb or /dev/sdc !'''
# (if the installation not already does it for you) '''you should label the partitions and use the labels for mounting the partitions in /etc/fstab; don't use /dev/sda1 or the like because depending on the hardware it is booted on, after booting the stick, and depending on the actual hardware, the stick may be /dev/sdb or /dev/sdc !'''
== Howto create a bootabled GPT-partitioned USB-stick with Fedora 23 ==
This will create a USB stick capable to
* EFI boot on MAC's
* UEFI boot on PC's
* BIOS boot on newer hardware (legacy boot / CSM enabled)
* BIOS boots on medium aged bios hardware
does not boot on old BIOS hardware which doesn't support booting from GPT (see below):
=== GPT partition the stick using gdisk ===
The example shows a 32 GB Sandisk Extreme:
Part 1: +1G VFAT (0700) (Windows needs it to be the first partition)
Part 2: +1M Biosboot (ef02)
Part 3: +250M EFI (ef00)
Part 4: +13500M / (0083)
Part 5: +15000M /mnt/data (0083)
For performance, make sure that the big partitions are aligned to 8192-sector boundaries; default is 2048-sector boundaries - the default can be adjusted. If you use the above sizes and the + sign for specifying them, this happens to work out automatically.
=== Install Fedora23 on an UEFI machine (UEFI enabled; LegacyBoot / CSM disabled) ===
Whenever you see a ?, you must fill in the appropriate drive letter (e.g. c or d).
sd?3: efi       /boot/efi
sd?4: ext4 /
sd?5: ext4 /mnt/data
=== adjust the USB-stick for UEFI/EFI boot (before reboot from chroot environment) ===
chroot:
<pre>chroot /mnt/sysimage</pre>
install updates:
<pre> dnf -y update</pre>
configure grub2 for (U)EFI systems:
disable auto recognition of other installed Operating systems (specific to current computer), and
update grub2-efi.cfg to use uuid's (devices not consistent across different machines)
echo 'GRUB_DISABLE_OS_PROBER=”true”' >> /etc/default/grub
grub2-mkconfig -o /etc/grub2-efi.cfg
(switches from devices to uuid and removes boot entries for other OS's)
tune ext4 filesystems:
tune2fs -o journal_data_writeback,nobarrier /dev/sd?4
tune2fs -o journal_data_writeback,nobarrier /dev/sd?5
(to set the default mount options, the partition has to be mounted, for / it must be done from chroot)
create & label vfat filesystem:
mkfs.vfat /dev/sd?1
dosfslabel /dev/sd?1 VFAT
exit
systemctl poweroff (or reboot for testing)
=== Install grub2 for BIOS boot (from chroot environment) ===
boot Fedora Live DVD on a BIOS machine and chroot to the stick:
mount /dev/sd?4 /mnt
mount -o bind /dev /mnt/dev
mount -t proc /proc /mnt/proc
mount -t sysfs /sys /mnt/sys
chroot /mnt
Install grub2 for BIOS boot and configure it:
<pre> rm /boot/grub2/grubenv</pre>
(symlink to /boot/efi/EFI/fedora/grubenv in grub2-efi.rpm; binary file in grub2.rpm)
<pre> grub2-install /dev/sd?</pre>
(also creates a new /boot/grub2/grubenv
<pre>grub2-mkconfig -o /etc/grub2.cfg</pre>
check /etc/grub2.cfg and if needed, change at all positions
“linuxefi” to “linux16”, and
“intrdefi” to “intrd16”
=== Problems on old BIOS hardware ===
some old computers still might not boot (they don't support booting from GPT).
This can be fixed but the stick afterwards cannot boot on EFI/UEFI systems anymore.
a) set the boot flag (active) on the single 0xEE partition in the protective MBR by using fdisk version <= 2.22 (versions 1.23 and newer  have GPT support and thus doesn't make changes to the protective MBR but to the GPT) (I used fdisk (util-linux-ng 2.17.2) on a SCIENTIFIC LINUX 6.7 machine)
<pre> fdisk /dev/sd? ; a ; part 1 ; w</pre>
b) recompute CHS values using option “h” in gdisk's expert menu:
<pre> gdisk /dev/sd? ; x ; h ; m ; q </pre>
this can be reversed:
- toggle bootflag off in old fdisk
- recompute CHS values in gdisk
(using a sgdisk backup of the GPT should also be fine)
helpful links:
http://www.rodsbooks.com/gdisk/bios.html#bios --> option h of gdisks experts menu did the trick!
https://fedoraproject.org/wiki/GRUB_2?rd=Grub2#Updating_GRUB_2_configuration_on_BIOS_systems
=== generating images and copies of the stick ===
fill empty part of all partitions on the stick with “zeros”: for each partition, do
  dd if=/dev/zero of=/mountpoint/delete.me bs=4096
rm /mountpoint/delete.me
save a compressed disk image:
<pre> dd if=/dev/sd? | pigz -c usbstick.img.gz</pre>
(time: ~180 secs speed: ~175MB/s, size of image: 1.8 GB)
write compressed image back to a stick:
<pre> unpigz -c usbstick.img.gz | dd of=/dev/sd? bs=4096</pre>
(speed should be >100MB/s)
1,328

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu