Tiny Core Linux Customization


Brief notes for the Tiny Core Linux rescue Kernel; customized and minimized to a 25MB; containing many useful administrative utilities; very useful for rescue, offline cold backups, restores, troubleshooting boot problems, disaster recovery. It can launch from a local Linux boot loader, an external USB hard disk, or a USB stick, or a virtual/physical CDROM ISO. The distro is very well maintained with the latest kernels. The Tiny Core Linux Team did a great job with this mini distro and the Linux community celebrates their work.

Main site: http://tinycorelinux.net/

The utilities that I most used: LVM, mount, sshd, rsync, scp, netcat, netstat, tar, chroot.


http://tinycorelinux … yCorePure64-11.0.iso [28MB]

GRUB2 Boot

Add to an existing GRUB2 system, to enable rescue boot from a regular local hard disk. Copy the Tiny Core kernel and ramdisk:

# mount -o loop TinyCorePure64-11.0.iso /mnt
# mkdir -p /boot/tce/optional
# cp /mnt/boot/vmlinuz64 /boot/tcvmlinuz64
# cp /mnt/boot/corepure64.gz /boot/tccorepure64.gz
# cp -r /mnt/boot/cde/* /boot/tce/
# chmod 0444 /boot/tcvmlinuz64
# chmod 0444 tccorepure64.gz
# chmod 0750 /boot/tce

Add the GRUB2 entry:

# cat /etc/grub.d/40_custom
menuentry "Tiny Core 11.1 Rescue" {
linux /tcvmlinuz64 noswap nozswap nohdcp superuser vga=791 tz=GM-5 host=foo
initrd /tccorepure64.gz

Rebuild the GRUB2 configuration, then test it:

# grub2-mkconfig -o /boot/grub2/grub.cfg

# reboot

Legacy GRUB Boot

For older Legacy GRUB copy the /boot files as above, then create the boot stanza as follows. NOTE: The EFI path can be /boot/efi/EFI/grub.conf.

# cat /boot/grub/menu.lst
title TC Rescue 
  root (hd0,0)
  kernel /tcvmlinuz64 vga=791 noswap nozswap tz=GM-5 superuser
  initrd /tccorepure64.gz 

Prefered Extensions

Copy the extensions suitable for your own rescue scenario. For my needs I select SSHD, LVM, rsync, squashfs-tools., Follow the logic.

# cd /boot/tce/optional/

# LIST="
# cd /boot/tce/optional

# for a in $LIST ; do wget http://tinycorelinux.net/11.x/x86_64/tcz/$a ; done

Add the extensions to the onboot file and initialize the data file. Reboot and test.

# ls -l *.tcz | awk '{print $NF}' > ../onboot.lst
# touch /mnt/tmp/tce/mydata.tgz
# reboot

Configure SSHD

# cd /usr/local/etc/ssh/

# echo "
Port 22
HostKey /usr/local/etc/ssh/ssh_host_rsa_key
PermitRootLogin yes
AuthorizedKeysFile	.ssh/authorized_keys
Subsystem	sftp	/usr/local/lib/openssh/sftp-server
" >> sshd_config

Create the new system keys and start sshd.

# ssh-keygen -f ssh_host_rsa_key -N '' -t rsa
# /usr/local/sbin/sshd -p 22

Copy the files for later use:

# blkid
# mount /dev/sdX1 /mnt/sdX1
# cp /usr/local/etc/ssh/ssh* /mnt/sdX1/tce/optional/

Configure Startup

Set the configuration files on every boot. Follow the logic

# echo "
#pkill udhcpc
#ifconfig eth0 netmask
#route add default gw
HD=`mount | grep mnt | awk '{print $3}'`        
cp $HD/tce/optional/sshd_config /usr/local/etc/ssh/sshd_config         
cp $HD/tce/optional/ssh_host_rsa* /usr/local/etc/ssh/               
chmod 0600 /usr/local/etc/ssh/ssh_*
echo "root:welcome" | chpasswd
#vgchange -ay
" >> /opt/bootlocal.sh

Save the settings:

# filetool.sh -b

NOTE: Another alternative about persistent configuration files is to add to /opt/.filetool.lst the files or directories to backup; then run `filetool.sh -b`. Make sure that the leading “/” is left out. Other similar files: etc/shadow, usr/local/etc/ssh.

Dynamic Extensions

To install more extensions run tce-ab and select Install, the tcz packages will be automatically placed in tce/optional subdirectory. Make sure to load it automatically by adding it to tce/onboot.lst. You need to be use “tc” in order to install extensions.

# su - tc
$ tce-ab

Basic Bootable USB Stick Install

Identify the device name for the USB stick then write the ISO into it.

# lsblk
# dd if=TinyCore64.iso /dev/sdX bs=4M

NOTE: This USB stick will only operate read-only mode.

Custom Bootable USB Stick Install

This method allows the installation of more packages dynamically. NOTE: With the 64bit version of TinyCore64 there is no GUI custom installer as with the 32bit GUI version. You’ll have to install to USB stick manually. There are several ways to do this, but below is what worked for me.

Using Debian 10 as your workstation, install the required packages for preparing the USB stick:

# apt-get install mbr dosfstools syslinux syslinux-common isolinux extlinux mtools

Modify the USB stick with a bootable FAT32 partition:

# lsblk
# printf "dnnnpn1nnntnbnanwn" | fdisk /dev/sdX
# mkdosfs /dev/sdX1

Copy the ISO to the USB stick. Also copy extra Syslinux/Extlinux boot loader files.

# mkdir -p /mnt/{iso|usb}
# mount -o loop TinyCorePure64-11.0.iso /mnt/iso/
# mount /dev/sdX1 /mnt/usb/
# cp -R /mnt/iso/* /mnt/usb/
# sync

Rename and modify necessary files and directories, and install the Syslinux boot loader on the USB stick:

# cd /mnt/usb
# mv cde tce
# cd boot
# mv isolinux syslinux
# cd syslinux
# mv isolinux.cfg syslinux.cfg
# mv isolinux.bin syslinux.bin
# echo "
KERNEL /boot/vmlinuz64
APPEND initrd=/boot/corepure64.gz waitusb=5 vga=791 noswap nozswap tz=GM-5 superuser
" > syslinux.cfg

# chmod 0666 syslinux.cfg
# chmod 0444 syslinux.bin
# rm -rf boot.msg f1 f2 f3 f4 menu.c32
# syslinux -d /boot/syslinux -isf /dev/sdX1

NOTE: TinyCorePure64-11.1.iso comes with GUI extensions. If you don’t need the GUI or if you want to make the USB stick minimal, then delete them:

# rm -rf /mnt/usb/tce/optional/*

Else include them all in the onboot.lst, and then to open the GUI environment run `startx`:

# cd /mnt/usb/tce/optional
# ls -l *.tcz | awk '{print $NF}' > ../onboot.lst

Copy the desired extensions and configuration files to /mnt/usb/tce/optional/, and modify /boot/tce/onboot.lst. Follow the logic to also modify bootlocal.sh

Dismount, label and try it.

# cd
# umount /mnt/usb
# fatlabel /dev/sdc1 USB-TC
# sync

Custom External Bootable USB Disk Install

For best results:

  • Use a low voltage self- powered external disk.
  • Use a solid state drive external disk SSD.
  • Use two partitions: 1) ext4 for boot 100MB 2) NTFS for shareable data.

NOTE: I tried exFAT but did not like it and instead I prefer NTFS. exFAT is unstable, works only on SSD drives, has no journal, and requires special partition parameters. NTFS is much better, older and mature, journaled, more stable, shared easily in hybrid environments, although a little slower.

Format the disk and create the file systems:

# fdisk /dev/sdX
# mkdosfs /dev/sdX1
# mkfs.ntfs -Q /dev/sdX2

Create with Extlinux variant of Syslinux.

#apt-get install extlinux

Follow the same Syslinux logic above, then;

# vi extlinux.conf

 SAY Tiny Core Linux 11.1 64bit...
  KERNEL vmlinuz64
  APPEND initrd=corepure64.gz waitusb=5 vga=791 noswap nozswap tz=GM-5 superuser

Install the MBR:

# cat /usr/lib/EXTLINUX/mbr.bin > /dev/sdX

Label the partitions:

# e2label /dev/sdc1 USB-ext4
# ntfslabel /dev/sdc2 USB-NTFS

Custom ISO File

Remaster the ISO file and burn it or use it to boot physical or virtual guests.

# apt-get install isolinux xorriso

As above, copy the kernel and ramdisk of the regular ISO onto a temporary directory. As an alternative we can extract the extension, and then the tce extensions directory is not needed. Follow the logic.

# mkdir -p /tmp/mysiso
# cp -a /mnt/iso/ /tmp/myiso/
# cd /tmp/myiso/boot/isolinux
# cp /usr/lib/ISOLINUX/isolinux.bin .
# cp /usr/lib/ISOLINUX/isohdpfx.bin .
# chmod 744 *.bin 

Create a simple isolinux config file:

# vi isolinux.cfg 
default 1
label 1
kernel /boot/vmlinuz64
append initrd=/boot/corepure64.gz tce waitusb=5 vga=791 noswap nozswap tz=GM-5 superuser

Extract the extensions into the ramdisk. Make any modifications necessary.

# mkdir -p /tmp/myiso && cd /tmp/myiso
# zcat /boot/tcorepure64.gz | cpio -i -H newc -d
# for a in `ls /boot/tce/optional/*.tcz ; do unsquashfs -f -d /tmp/myiso/ $a ; done 

Recreate the ramdisk and the custom ISO file:

# cd /tmp/myiso
# find | sudo cpio -o -H newc | gzip -2 > /boot/tmycorepure64.gz

# xorriso -as mkisofs -o /tmp/mytc.iso -isohybrid-mbr /boot/isolinux/isohdpfx.bin -c boot.cat -b /boot/isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table .

Remove the tce directory (no longer needed). Now everything is included in the ramdisk.

# rm -rf /boot/tce

Persistent Files

After booting specify persistent files or directories to extract after after boot, then backup the mydata.tgz tarball. Notice the missing foot slash.

$ vi /opt/.filetool.lst

$ filetool.sh -b

Transfering Files with Netcat

With netcat files can be transfered on a listening port without authentication; great for quick rescue backups.

From the target workstation, listen on a netcat port 8000, ready to extract the received compressed tarball:

# mkdir -p /data/backup
# cd /data/backup
# nc -l -p 8000 | tar zvx

From soruce Tinycore rescue session, send the tarball of the files to be trasfered.

# cd /mnt/root
# tar zvcf - . | nc targethost 8000

== Weaknesses ==

Lack of hardware support. Booting some production servers I noticed that some disk arrays are not detected.

== Summary ==

Tiny Core Linux is a good distro for disaster recovery. However, make sure you prepare and test it with your hardware, ahead of time, and not be taken by surprises. It’s not a one size fits all recovery distro. However, what’s great about it is that, if you are clever enough, you can always add to it whatever you need.

The End.