Tiny Core Linux: Difference between revisions

From Leo's Notes
This page was last edited on 21 June 2022, at 23:05.
Created page with "TinyCore is a nifty linux distro that's extremely small. Similar to DamnSmallLinux, but even smaller. == Booting == If you use TinyCore with PXE, all you need to do is to cr..."
 
No edit summary
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
TinyCore is a nifty linux distro that's extremely small. Similar to DamnSmallLinux, but even smaller.
TinyCore is a x86 Linux distribution that's extremely small and runs primarily from memory. The project also has a few spinoffs that runs on x86_64 (amd64), ARM, and ARM64 architectures. Its main appeal is its small size, modularity, and simplicity.


== Booting ==
The project website is at http://tinycorelinux.net.


If you use TinyCore with PXE, all you need to do is to create a menu entry with:
== PXE Boot ==
To PXE boot TinyCore, create a boot menu that loads the kernel and core.gz image:
{{highlight|lang=text|code=
  LABEL Core
  LABEL Core
  MENU LABEL Core
  MENU LABEL Core
         kernel /images/core/vmlinuz
         kernel /images/core/vmlinuz
         INITRD /images/core/core.gz
         INITRD /images/core/core.gz
}}


The standard image will not have any extensions and will drop you into a shell.


== Altering Initrd ==
=== NFS ===
To get a GUI, you will need to load {{code|Xvesa}}, {{code|wbar}}, {{code|flwm_topside}} and their dependencies. The easiest way to get these extensions is to grab it from the TinyCore CD.


=== Extract ===
To get TinyCore to mount a NFS share containing the required extensions, pass {{code|nfsmount}} to the kernel:
To remaster the base image with additional packages, do the following:
{{highlight
| lang = text
| code = LABEL Core
MENU LABEL Core
        kernel /images/core/vmlinuz
        INITRD /images/core/core.gz nfsmount=10.1.1.1:/tftpboot/images/tinycore tce=nfs/cde
}}


mkdir -p /tmp/tinycore/extract
Where {{code|/tftpboot/images/tinycore}} contains a directory containing a <code>onboot.lst</code> file plus all the packages that are needed. In my case, I wanted to PXE boot into Tiny Core Linux with cde, so I copied the 'cde' directory from the Tiny Core Linux iso and dumped it into the NFS export:
mv core.gz /tmp/tinycore  # where core.gz is the initrd file
{{highlight
cd /tmp/tinycore/extract
| lang = text
zcat ../core.gz | cpio -i
| code = $ ls /tftpboot/images/tinycore
cde


The extract directory should now contain the contents of the initrd file system.  
$ ls /tftpboot/images/tinycore/cde
copy2fs.lst  onboot.lst  optional    xbase.lst
}}


=== Adding Additional Packages ===
When TinyCore boots, the NFS share will be mounted as {{code|/mnt/nfs}} and the packages will be loaded by tce based on the <code>onboot.lst</code> file in the <code>nfs/cde</code> directory.
To add additional packages to the system, download the .tcz files you want installed from the repository. Store them in /tmp/tinycore/packages, then run:


  cd /tmp/tinycore/extract
=== HTTP List ===
for i in `ls ../packages/*.tcz` ; do unsquashfs -f -d . $i ; done
Alternatively, if you don't have a NFS server, you can specify a {{code|httplist}} that specifies the web server and the path to a file that contains a list of URIs (on that server) that TinyCore should download and load.
{{highlight|lang=text|code=
  LABEL Core
MENU LABEL Core
        kernel /images/core/vmlinuz
        INITRD /images/core/core.gz httplist=pages.cpsc.ucalgary.ca:80/~leo/boot/pxe/linux/data/tinycore/list.txt
}}


This will extract the squashfs package files and dump them into the root directory of the extracted initrd file system.  
The list file contains:
{{highlight|lang=text|code=
/~leo/boot/pxe/linux/data/tinycore/8.x/libICE.tcz
/~leo/boot/pxe/linux/data/tinycore/8.x/imlib2.tcz
/~leo/boot/pxe/linux/data/tinycore/8.x/libSM.tcz
...
}}


=== Remastering ===
The only drawback to this feature is that the packages are downloaded from the server hosting that list. This means that you won't be able to make TinyCore download packages from an existing mirror.
{{Info|1=Apache Mod_Rewrite Proxy|Since these extensions can get quite large, you can avoid making a copy of the extensions using mod_rewrite. In the case above, I had this {{code|.htaccess}} file in the 8.x directory that forwards package requests to a mirror.
 
{{highlight|lang=htaccess|code=
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://mirror.cpsc.ucalgary.ca/mirror/tinycorelinux/8.x/x86/tcz/$1 [P,L]
}}
}}
 
== Customization ==
I have made the following changes to {{code|/etc/init.d/tc-config}}
{{highlight|lang=diff|code=
--- ../tc-config 2017-08-20 17:57:00.145946463 -0600
+++ etc/init.d/tc-config 2017-08-20 18:03:52.666609947 -0600
@@ -61,6 +61,7 @@ for i in `cat /proc/cmdline`; do
rsyslog=* ) RSYSLOG=${i#*=}; SYSLOG=1 ;;
blacklist* ) BLACKLIST="$BLACKLIST ${i#*=}" ;;
iso* ) ISOFILE=${i#*=} ;;
+ postexec*) POSTEXEC=${i#*=} ;;
esac
;;
*)
@@ -613,6 +614,19 @@ else
[ -z "$NORTC" ] {{!}}{{!}} /etc/init.d/settime.sh &
fi
+# Post-boot exec command or http script
+if [ -n "$POSTEXEC" ]; then
+ case "$POSTEXEC" in
+ http*)
+ [ -z "$DHCP_RAN" ] && wait4Server $HOST $NOPING
+ wget -O - "$POSTEXEC" {{!}} sh
+ ;;
+ *)
+ echo "$POSTEXEC" {{!}} sh
+ ;;
+ esac
+fi
+
[ -n "$CRON" ] && /etc/init.d/services/crond start
/sbin/loadcpufreq 2>/dev/null &
}}
 
With this modification, you can pass {{code|postexec}} as a kernel argument which then gets executed after all the extensions have loaded, but before the user-side programs start. Eg:
{{highlight|lang=text|code=
kernel http://${base_url}/linux/data/tinycore/8.x/vmlinuz httplist=pages.cpsc.ucalgary.ca:80/~leo/boot/pxe/linux/data/tinycore/list.txt showapps postexec=http://pages.cpsc.ucalgary.ca/~leo/boot/pxe/linux/data/tinycore/post_install.sh
}}
 
== Usage ==
=== Persistence ===
When TinyCore boots, after all extensions are loaded, customized files are then loaded from {{code|/mnt/sdx1/tce/mydata.tgz}}. Afterwards, any changes made to a running system will be lost unless it is saved using the {{code|filetool.sh}} script. This tool will restore and save any files listed in {{code|/opt/.filetool.lst}}
 
== Miscellaneous ==
 
=== Installing to Hard Drive ===
The installer can be used to install TinyCore on a hard drive. Get the {{code|tc-install}} package and run it.
 
=== Mirrors ===
The mirror can be selected by editing {{code|/opt/tcemirror}}.
 
To use CPSC's mirror, edit {{code|/opt/tcemirror}} and replace it with:
{{highlight|lang=text|code=
http://mirror.cpsc.ucalgary.ca/mirror/tinycorelinux/
}}
=== Modifying {{code|mydata.tgz}} ===
If you are running TinyCore on a NFS share, you might not be able to modify the system and then save the changes like you normally would with {{code|filetool.sh -b}} because {{code|/mnt/nfs}} may be read only.
 
To modify {{code|mydata.tgz}} outside of the TinyCore environment:
{{highlight|lang=terminal|code=
# umask 022      # In case you have a weird umask, default to 022.
# mkdir tce      # this dir should be 755 (anything less will kill your tce image)
# cd tce
# tar --numeric-owner -xzpf ../mydata.tgz  # Keep permissions and ownership!
## make your changes
# tar --numeric-owner -czpf ../mydata.tgz *    # Re-create the tarball with permissions
}}
 
Overwrite the old {{code|mydata.tgz}} on the NFS share and then test the changes on TinyCore by running:
 
{{highlight|lang=terminal|code=
# filetoool.sh -r
}}
 
Any changes you've made should be visible immediately.
=== Altering {{code|core.gz}} - Initrd Image ===
Follow the steps below if you wish to have the system include a set of packages out of the box without needing to load it as extensions.
 
==== Extract ====
Extract the {{code|core.gz}} file.
 
{{highlight|lang=terminal|code=
$ mkdir -p /tmp/tinycore/extract
$ mv core.gz /tmp/tinycore  # where core.gz is the initrd file
$ cd /tmp/tinycore/extract
# zcat ../core.gz {{!}} cpio -i  # cpio requires root in order to mknod
}}
 
The extract directory should now contain the contents of the initrd file system.
 
==== Adding Additional Packages ====
Download the .tcz files you want installed from the repository. Store them somewhere (say {{code|/tmp/tinycore/packages}}). Each package is a squashfs filesystem which can be extracted using the {{code|unsquashfs}} utility.
 
{{highlight|lang=terminal|code=
$ cd /tmp/tinycore/extract
$ for i in `ls ../packages/*.tcz` ; do unsquashfs -f -d . $i ; done
}}
 
If you wish to run something on startup, put it in {{code|/opt/bootsync.sh}} or {{code|/opt/bootlocal.sh}}. {{code|/opt/bootsync.sh}} gets called by {{code|/etc/init.d/tc-config}}. Just note that networking might not be up immediately since the dhcp client runs asynchronously. I got around this by running {{code|while true ; do wget -O - http://somewhere.com && break ; done}} just to verify networking is up.
 
==== Remastering ====
With the changes made to the root file system, you will want to package the directory back up to create the initrd image.  To do this, do:
With the changes made to the root file system, you will want to package the directory back up to create the initrd image.  To do this, do:


cd /tmp/tinycore/extract
{{highlight|lang=terminal|code=
find | cpio -o -H newc > ../core
$ cd /tmp/tinycore/extract
cd ..
$ find {{!}} cpio -o -H newc > ../core
gzip core
$ cd ..
advdef -z4 core.gz # this step is optional, but may save you ~2% of space.
$ gzip core
$ advdef -z4 core.gz # this step is optional, but may save you ~2% of space.
}}
 
 
==== Loading Drives ====
To load some graphics drivers on boot, add to {{code|/opt/bootsync.sh}}:
 
{{highlight|lang=bash|code=
<nowiki>
#!/bin/sh
# put other system startup commands here, the boot process will wait until they complete.
# Use bootlocal.sh for system startup commands that can run in the background
# and therefore not slow down the boot process.
/usr/bin/sethostname box
 
Display=`lspci | grep -i vga`
 
if echo "$Display" | grep -qi nvidia  ; then
        sudo -u tc tce-load -i nvidia-340.96-4.2.9-tinycore
        cp /etc/X11/xorg.conf-nvidia /etc/X11/xorg.conf
fi
 
if echo "$Display" | grep -qi intel  ; then
        sudo -u tc tce-load -i xf86-video-intel
fi
 
if echo "$Display" | grep -qi amd ; then
        sudo -u tc tce-load -i xf86-video-ati
fi
 
if echo "$Display" | grep -qi vmware ; then
        sudo -u tc tce-load -i xf86-video-vmware
fi
</nowiki>
}}
 
=== FLWM title bar ===
The Fast Light Window Manager (FLWM) window manager comes in two flavors: The default where the title bars are stacked on the left side of the window, and the 'topside' where the title bars are placed at the top as they are more traditionally placed.


[[Category:Linux]]
By default, Tiny Core Linux uses the version with the title bars placed vertically. If you want to change this, load the flwm_topside.tcz package with tce. If you are using a NFS or HTTP file list, simply download the flwm_topside package and replace the flwm entry with flwm_topside in the file list.{{Navbox Linux}}[[Category:Linux]]
[[Category:Operating_Systems]]

Latest revision as of 23:05, 21 June 2022

TinyCore is a x86 Linux distribution that's extremely small and runs primarily from memory. The project also has a few spinoffs that runs on x86_64 (amd64), ARM, and ARM64 architectures. Its main appeal is its small size, modularity, and simplicity.

The project website is at http://tinycorelinux.net.

PXE Boot

To PXE boot TinyCore, create a boot menu that loads the kernel and core.gz image:

LABEL Core
 	MENU LABEL Core
         kernel /images/core/vmlinuz
         INITRD /images/core/core.gz

The standard image will not have any extensions and will drop you into a shell.

NFS

To get a GUI, you will need to load Xvesa, wbar, flwm_topside and their dependencies. The easiest way to get these extensions is to grab it from the TinyCore CD.

To get TinyCore to mount a NFS share containing the required extensions, pass nfsmount to the kernel:

LABEL Core
 	MENU LABEL Core
         kernel /images/core/vmlinuz
         INITRD /images/core/core.gz nfsmount=10.1.1.1:/tftpboot/images/tinycore tce=nfs/cde

Where /tftpboot/images/tinycore contains a directory containing a onboot.lst file plus all the packages that are needed. In my case, I wanted to PXE boot into Tiny Core Linux with cde, so I copied the 'cde' directory from the Tiny Core Linux iso and dumped it into the NFS export:

$ ls /tftpboot/images/tinycore
cde

$ ls /tftpboot/images/tinycore/cde
copy2fs.lst  onboot.lst   optional     xbase.lst

When TinyCore boots, the NFS share will be mounted as /mnt/nfs and the packages will be loaded by tce based on the onboot.lst file in the nfs/cde directory.

HTTP List

Alternatively, if you don't have a NFS server, you can specify a httplist that specifies the web server and the path to a file that contains a list of URIs (on that server) that TinyCore should download and load.

LABEL Core
 	MENU LABEL Core
         kernel /images/core/vmlinuz
         INITRD /images/core/core.gz httplist=pages.cpsc.ucalgary.ca:80/~leo/boot/pxe/linux/data/tinycore/list.txt

The list file contains:

/~leo/boot/pxe/linux/data/tinycore/8.x/libICE.tcz
/~leo/boot/pxe/linux/data/tinycore/8.x/imlib2.tcz
/~leo/boot/pxe/linux/data/tinycore/8.x/libSM.tcz
...

The only drawback to this feature is that the packages are downloaded from the server hosting that list. This means that you won't be able to make TinyCore download packages from an existing mirror.

Since these extensions can get quite large, you can avoid making a copy of the extensions using mod_rewrite. In the case above, I had this .htaccess file in the 8.x directory that forwards package requests to a mirror.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://mirror.cpsc.ucalgary.ca/mirror/tinycorelinux/8.x/x86/tcz/$1 [P,L]


Customization

I have made the following changes to /etc/init.d/tc-config

--- ../tc-config	2017-08-20 17:57:00.145946463 -0600
+++ etc/init.d/tc-config	2017-08-20 18:03:52.666609947 -0600
@@ -61,6 +61,7 @@ for i in `cat /proc/cmdline`; do
 				rsyslog=* ) RSYSLOG=${i#*=}; SYSLOG=1 ;;
 				blacklist* ) BLACKLIST="$BLACKLIST ${i#*=}" ;;
 				iso* ) ISOFILE=${i#*=} ;;
+				postexec*) POSTEXEC=${i#*=} ;;
 			esac
 		;;
 		*)
@@ -613,6 +614,19 @@ else
 	[ -z "$NORTC" ] || /etc/init.d/settime.sh &
 fi
 
+# Post-boot exec command or http script
+if [ -n "$POSTEXEC" ]; then
+	case "$POSTEXEC" in
+		http*)
+			[ -z "$DHCP_RAN" ] && wait4Server $HOST $NOPING
+			wget -O - "$POSTEXEC" | sh
+			;;
+		*)
+			echo "$POSTEXEC" | sh
+			;;
+	esac
+fi
+
 [ -n "$CRON" ] && /etc/init.d/services/crond start
 
 /sbin/loadcpufreq 2>/dev/null &

With this modification, you can pass postexec as a kernel argument which then gets executed after all the extensions have loaded, but before the user-side programs start. Eg:

kernel http://${base_url}/linux/data/tinycore/8.x/vmlinuz httplist=pages.cpsc.ucalgary.ca:80/~leo/boot/pxe/linux/data/tinycore/list.txt showapps postexec=http://pages.cpsc.ucalgary.ca/~leo/boot/pxe/linux/data/tinycore/post_install.sh

Usage

Persistence

When TinyCore boots, after all extensions are loaded, customized files are then loaded from /mnt/sdx1/tce/mydata.tgz. Afterwards, any changes made to a running system will be lost unless it is saved using the filetool.sh script. This tool will restore and save any files listed in /opt/.filetool.lst

Miscellaneous

Installing to Hard Drive

The installer can be used to install TinyCore on a hard drive. Get the tc-install package and run it.

Mirrors

The mirror can be selected by editing /opt/tcemirror.

To use CPSC's mirror, edit /opt/tcemirror and replace it with:

http://mirror.cpsc.ucalgary.ca/mirror/tinycorelinux/

Modifying mydata.tgz

If you are running TinyCore on a NFS share, you might not be able to modify the system and then save the changes like you normally would with filetool.sh -b because /mnt/nfs may be read only.

To modify mydata.tgz outside of the TinyCore environment:

# umask 022       # In case you have a weird umask, default to 022.
# mkdir tce       # this dir should be 755 (anything less will kill your tce image)
# cd tce
# tar --numeric-owner -xzpf ../mydata.tgz   # Keep permissions and ownership!
## make your changes
# tar --numeric-owner -czpf ../mydata.tgz *     # Re-create the tarball with permissions

Overwrite the old mydata.tgz on the NFS share and then test the changes on TinyCore by running:

# filetoool.sh -r

Any changes you've made should be visible immediately.

Altering core.gz - Initrd Image

Follow the steps below if you wish to have the system include a set of packages out of the box without needing to load it as extensions.

Extract

Extract the core.gz file.

$ mkdir -p /tmp/tinycore/extract
$ mv core.gz /tmp/tinycore  # where core.gz is the initrd file
$ cd /tmp/tinycore/extract
# zcat ../core.gz | cpio -i  # cpio requires root in order to mknod

The extract directory should now contain the contents of the initrd file system.

Adding Additional Packages

Download the .tcz files you want installed from the repository. Store them somewhere (say /tmp/tinycore/packages). Each package is a squashfs filesystem which can be extracted using the unsquashfs utility.

$ cd /tmp/tinycore/extract
$ for i in `ls ../packages/*.tcz` ; do unsquashfs -f -d . $i ; done

If you wish to run something on startup, put it in /opt/bootsync.sh or /opt/bootlocal.sh. /opt/bootsync.sh gets called by /etc/init.d/tc-config. Just note that networking might not be up immediately since the dhcp client runs asynchronously. I got around this by running while true ; do wget -O - http://somewhere.com && break ; done just to verify networking is up.

Remastering

With the changes made to the root file system, you will want to package the directory back up to create the initrd image. To do this, do:

$ cd /tmp/tinycore/extract
$ find | cpio -o -H newc > ../core
$ cd ..
$ gzip core
$ advdef -z4 core.gz # this step is optional, but may save you ~2% of space.


Loading Drives

To load some graphics drivers on boot, add to /opt/bootsync.sh:

#!/bin/sh
# put other system startup commands here, the boot process will wait until they complete.
# Use bootlocal.sh for system startup commands that can run in the background
# and therefore not slow down the boot process.
/usr/bin/sethostname box

Display=`lspci | grep -i vga`

if echo "$Display" | grep -qi nvidia  ; then
        sudo -u tc tce-load -i nvidia-340.96-4.2.9-tinycore
        cp /etc/X11/xorg.conf-nvidia /etc/X11/xorg.conf
fi

if echo "$Display" | grep -qi intel  ; then
        sudo -u tc tce-load -i xf86-video-intel
fi

if echo "$Display" | grep -qi amd ; then
        sudo -u tc tce-load -i xf86-video-ati
fi

if echo "$Display" | grep -qi vmware ; then
        sudo -u tc tce-load -i xf86-video-vmware
fi

FLWM title bar

The Fast Light Window Manager (FLWM) window manager comes in two flavors: The default where the title bars are stacked on the left side of the window, and the 'topside' where the title bars are placed at the top as they are more traditionally placed.

By default, Tiny Core Linux uses the version with the title bars placed vertically. If you want to change this, load the flwm_topside.tcz package with tce. If you are using a NFS or HTTP file list, simply download the flwm_topside package and replace the flwm entry with flwm_topside in the file list.