NTFS and modular boot for TinyCore Linux

TinyCore Linux is an awesome tiny Linux distribution. Better yet, TinyCore is made to be built on, and that’s just what I decided to do, build on it in order to match my exact needs:

  • I want to be able to install TinyCore Linux on an NTFS partition, and all NTFS partition should open with NTFS-3G by default.
  • I want a more modular startup, with a list of packages to load for firmware, another list for filesystems support, yet another for desktop applications, and so on.

This is actually quite easy to achieve. I wrote a script to automate the process, with help from the official TinyCore forums (it only works if NTFS-3G is installed):

#!/bin/sh

MIR="$(cat /opt/tcemirror)"
BITS=$(uname -m | grep -o 64)
TCZs='ntfs-3g'
INST=/usr/local/tce.installed

if [ ! -d TC.upgrade ]; then
mkdir TC.upgrade
fi
cd TC.upgrade || exit 1

wget "${MIR}/4.x/x86/release/distribution_files/core${BITS}.gz"
wget "${MIR}/4.x/x86/release/distribution_files/vmlinuz${BITS}"

## initrd
sudo mkdir tcz
sudo mkdir "core${BITS}+ntfs"
cd "core${BITS}+ntfs"

# insert NTFS-3G inside the core
gzip -dc ../"core${BITS}.gz" | sudo cpio -i
sudo mkdir -p "${INST:1}"
sudo chown ${USER}:staff "${INST:1}"
for t in $TCZs; do
sudo mount -o loop,ro /etc/sysconfig/tcedir/optional/${t}.tcz ../tcz
(cd ../tcz; find * ! -type d -print0 | xargs -0 tar cf -) | sudo tar xpf -
sudo touch "${INST:1}/$t"
sudo umount ../tcz
done

# make NTFS-3G the default handler for NTFS partitions
sudo sed -i 's/\$(blkid \$1)/$(blkid $1|sed s@TYPE=\\"ntfs\\"@TYPE=\\"ntfs-3g\\"@g)/' usr/sbin/fstype

# introduce a new “mlst” boot option (modular lsts)
sudo sed -i '
/lst=\*)/ a\
mlst=*) MODULAR_LSTS=${i#*=} ;;
/Process regular extensions/ {
a\
for modlst in $(echo $MODULAR_LSTS | tr , " "); do if [ -f "$TCEDIR/$modlst" ]; then
a\
for FILE in $(cat "$TCEDIR/$modlst"); do FILE="$TCEDIR/optional/$FILE" && process; done
a\
fi; done
}
' usr/bin/tce-setup

# package the new core, which is named core+ntfs
sudo chroot . ldconfig
find . | sudo cpio -H newc -o | gzip -9 >../"core${BITS}+ntfs.gz"
cd ..
if [ ! -e "$INST/advcomp" ]; then
tce-load -il /etc/sysconfig/tcedir/optional/advcomp.tcz
fi
advdef -z4 "core${BITS}+ntfs.gz"
sudo rm -rf tcz

This script should be run once in 32 bits mode, and once in 64 bits mode. It will produce a TC.upgrade folder, inside of which are stored the new core and vmlinuz files. These should then be moved to the place where the boot-loader will find them. In my case, this is /mnt/FLASH/.boot/corelnx/.

Then I create the following module files in /etc/sysconfig/tcedir/ (adapt to your needs and configuration):

base.lst:
ntfs-3g.tcz

mod_firm.lst:
firmware-atheros.tcz
… many other firmware*.tcz …
firmware-zd1211.tcz

mod_lang.lst:
kmaps.tcz
mylocale.tcz

mod_sound.lst:
alsa.tcz
alsa-oss.tcz

mod_fs.lst:
e2fsprogs.tcz
reiserfsprogs.tcz
ntfsprogs.tcz
dosfstools.tcz
jfsutils.tcz
xfsprogs.tcz

mod_xbase.lst:
msttcorefonts.tcz
Xprogs.tcz
flwm_topside.tcz
fluxbox.tcz
wbar.tcz

mod_xorg.lst:
xf86-video-all.tcz
Xorg-7.6.tcz

mod_xvesa.lst:
Xorg-7.6-lib.tcz
Xvesa.tcz

The base.lst file is special, as it is also used instead of TinyCore’s standard “base” option from now on. Indeed, for some reason, the fact that NTFS-3G is now included in the core+ntfs.gz file doesn’t seem to be enough to have NTFS-3G enabled.
The onboot.lst file still exists but only contains applications that I want instead of tens of technical packages… Here is mine for example:

onboot.lst:
lvm2.tcz
openssh.tcz
cups.tcz
numlockx.tcz
geany.tcz
rox-filer.tcz
evince.tcz
urxvt.tcz
eog.tcz
file-roller.tcz

The part about TinyCore Linux in my Grub2 config file now looks like this:

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=
set tc_X11=",mod_xorg.lst"
set tc_fs=
set tc_back=1
set tc_bits=

menuentry "Start CoreLinux: a tiny Linux on USB" {
if [ "$tc_bits" == "64" ]; then
set tc_X11=",mod_xorg.lst"
fi
if [ "$tc_back" == "1" ]; then
set tcopt_back="restore=LABEL=FLASH/.boot/corelnx"
else
set tcopt_back="norestore"
fi
if [ "$tc_X11" == ",mod_xvesa.lst" ]; 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.lst mlst=base.lst$tc_firm,mod_lang.lst,mod_sound.lst$tc_fs,mod_xbase.lst$tc_X11 $tcopt_X11
initrd /.boot/corelnx/core$tc_bits+ntfs.gz
}
menuentry "- Load firmware" {
set tc_firm=",mod_firm.lst"
}
menuentry "- 64 bits" {
set tc_bits=64
}
menuentry "- XVesa instead of Xorg" {
set tc_X11=",mod_xvesa.lst"
}
menuentry "- Don't use the backup" {
set tc_back=0
}
menuentry "- With filesystems management" {
set tc_fs=",mod_fs.lst"
}
menuentry "Start CoreLinux with minimal settings" {
linux /.boot/corelnx/vmlinuz$tc_bits $tcopt_base norestore lst=base.lst
initrd /.boot/corelnx/core$tc_bits+ntfs.gz
}

Now I get much more room for customization if I want to. For example, adding a Grub2 entry to disable sound would be a breeze.

As a final note, those who read my post about a bootable flash drive, and intend to install TinyCore on an NTFS partition, may wonder how to proceed: TinyCore needs this customization in order to run with NTFS-3G, and TinyCore must be running to allow the creation of this customization ;-)

Here is the answer:

  1. Boot TinyCore without the customization and without specifying a TCE location at boot; all should happen in memory.
  2. Install applications you need to run the customization, in particular NTFS-3G.
  3. Save the NTFS-3G package and its dependences (if any), as well as the customized vmlinuz and core+ntfs.gz files, to another location, be it a FAT32 flash drive, or another computer using SSH…
  4. Now boot whatever operating system you have, with access to both the TinyCore and Grub2 files, and the files you saved just above. There just remains to change the Grub2 menu as explained above, and move the files where they belong.

Tip : Enabling read+write NTFS support on boot for TinyCore Linux opens the possibility to install this tiny Linux operating system alongside a broad range of Windows operating systems (XP, Vista, 7…), without any need to reformat, repartition, or otherwise change the disk layout!

Ask for help if you need.

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/9

Fil des commentaires de ce billet