Bootable flash drive for both Linux and Windows: part 5

This blog post is part of a small series, with the aim of configuring a bootable USB flash drive for portable use on any PC. The main target is a full portable Linux OS, but I also addressed the Windows OS, for those times when you have no choice ;-)

This last part suggests a better Grub2 menu allowing you to boot according to the present need, and a useful tip…

In the third part of this series, I explained how to install TinyCore Linux. Following the Wiki, it is easy to install firmwares, XOrg, the necessary locales, any tools you want…

But up to now, you only had one choice of a set of packages to load at boot, even though you may want to boot your flash drive on different computers with different needs: rescuing a filesystem, checking mail, with or without weird hardware… I propose to have several sets of packages to boot, and be able to choose between:

  • 32 bits or 64 bits (already possible),
  • XOrg or XVesa,
  • with or without firmwares,
  • using, or not, the backup of personal files.

I’ll assume that TinyCore is booted, and that the flash drive’s partition is mounted on /mnt/sdb1.

First, I ensure that the file /etc/sysconfig/tcedir/onboot.lst contains the maximum list of wanted packages (not the dependences, though; those are loaded automatically), which means all firmware, and XOrg as a default choice (you can use TinyCore’s graphical tools for this purpose).

Then, I ensure (in the /opt/.filetool.lst file) that /opt/shutdown.sh is saved by TinyCore across reboots, and I edit this file to add the following text just after the first line:

## Automatically manage LST files
T=/etc/sysconfig/tcedir
LST=$(grep -o 'lst=[^ ]*' /proc/cmdline | cut -d= -f2 | grep -vFx onboot.lst)

# update onboot.lst to be the reference file
if [ -n "$LST" ] && [ "$T/$LST" -nt "$T/onboot.lst" ]; then
diffs="$(diff -U0 "$T/onboot.lst" "$T/$LST" | grep '^[-+][^-+]' | grep -v '^.xf86-video-all.tcz$\|^.Xorg-7.6-lib.tcz$\|^.Xorg-7.6.tcz$\|^.Xvesa.tcz$\|^.firmware')"
echo "$diffs" \
| while read d; do case "$d" in
-*)
sed -i "/^${d:1}\$/d" "$T/onboot.lst" ;;
+*)
echo "${d:1}" >>"$T/onboot.lst" ;;
esac; done
fi

# if onboot.lst changed, change the other files accordingly
if [ $T/onboot.lst -nt $T/onboot_xvesa.lst ]; then
sed '
s/xf86-video-all.tcz/Xorg-7.6-lib.tcz/
s/Xorg-7.6.tcz/Xvesa.tcz/
' <$T/onboot.lst >$T/onboot_xvesa.lst
sed '/^firmware/d' <$T/onboot.lst >$T/onboot_nofirm.lst
sed '/^firmware/d' <$T/onboot_xvesa.lst >$T/onboot_nofirm_xvesa.lst
fi

Then I have to run the following commands to ensure the script will take effect on next reboot (the order is important):

touch /etc/sysconfig/tcedir/onboot_xvesa.lst
touch /etc/sysconfig/tcedir/onboot.lst

Finally, I change the part about TinyCore in Grub2’s menu file (/mnt/sdb1/.boot/grub/grub.cfg) in the following way (note: XVesa is only possible in 32 bits mode):

set tcopt_base="waitusb=5 tce=LABEL=FLASH/.boot/corelnx/tce"
set tcopt_common="lang=fr_FR.utf8 kmap=azerty/fr-latin1 showapps"
set tc_firm="_nofirm"
set tc_X11=
set tc_back=1
set tc_bits=

menuentry "Start CoreLinux: a tiny Linux on USB" {
if [ "$tc_bits" == "64" ]; then
set tc_X11=
fi
if [ "$tc_back" == "1" ]; then
set tcopt_back="restore=LABEL=FLASH/.boot/corelnx"
else
set tcopt_back="norestore"
fi
if [ "$tc_X11" == "_xvesa" ]; then
set tcopt_X11="xvesa=1400x1050x24 desktop=fluxbox"
else
set tcopt_X11="desktop=fluxbox"
fi
linux /.boot/corelnx/vmlinuz$tc_bits $tcopt_base $tcopt_common $tcopt_back lst=onboot$tc_firm$tc_X11.lst $tcopt_X11
initrd /.boot/corelnx/core$tc_bits.gz
}
menuentry "- Load firmware" {
set tc_firm=
}
menuentry "- 64 bits" {
set tc_bits=64
}
menuentry "- XVesa instead of Xorg" {
set tc_X11="_xvesa"
}
menuentry "- Don't use the backup" {
set tc_back=0
}
menuentry "Start CoreLinux with minimal settings" {
linux /.boot/corelnx/vmlinuz$tc_bits $tcopt_base norestore base
initrd /.boot/corelnx/core$tc_bits.gz
}

Notes:

  • Of course, you can change the default desktop above. Besides, with some changes, you could even make it another thing to choose at boot.
  • As you can see, in 64 bits mode, X11 is forced to XOrg, because XVesa does not work in 64 bits mode.

Last but not least, let me give you a small tip so that your flash drive can easily be located whatever computer you are currently working on ;-)
In the /opt/bootlocal.sh file, append this line:

ln -s $(ls -l /etc/sysconfig/tcedir | grep -o '/mnt/[^/]*') /mnt/FLASH

Here ends my small series regarding this bootable Linux+Windows flash drive. I hoped it was of some use to some people. Enjoy!

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 : http://yalis.fr/cms/index.php/trackback/8

Fil des commentaires de ce billet