WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: TinyCore: My Way 2 (ttyx4 + login)  (Read 8292 times)

Offline hjkl

  • Newbie
  • *
  • Posts: 23
TinyCore: My Way 2 (ttyx4 + login)
« on: December 21, 2008, 01:44:50 PM »
TinyCore starts X automatically.  However, I would like my TinyCore to
leave me with 4 Linux consoles and their login prompts when it starts.
Then, I can start X manually.
So, I modify my 'tinycore.gz' to change TinyCore's behavior.

** Warning: This could break your TinyCore. **

4c8c4fe2a48c90393bf29528aa6ce7ee  tinycore_1.0rc7.iso

'tinycore.gz' dir = /mnt/sda1/tc/

First, I open 'tinycore.gz' in a new directory, tcfs.
 root@box:/home/tc# mkdir tcfs
 root@box:/home/tc# cd tcfs
 root@box:/home/tc/tcfs# gunzip -c /mnt/sda1/tc/tinycore.gz | cpio -idm

Now, I change the passwords for User 'tc' and User 'root'.
In this case, 'whatever' is the password for both.
 root@box:/home/tc/tcfs# chpasswd << EOF
> tc:whatever
> root:whatever
> EOF

Then, I modify these files:
1): /home/tc/tcfs/etc/shadow
2): /home/tc/tcfs/etc/inittab
3): /home/tc/tcfs/etc/profile
4): /home/tc/tcfs/etc/skel/.profile
5): /home/tc/tcfs/root/.profile

1): /home/tc/tcfs/etc/shadow
This saves the passwords.
 root@box:/home/tc/tcfs# cp /etc/shadow etc/shadow

2): /home/tc/tcfs/etc/inittab
Editing this creates 4 Linux consoles.  I use 'askfirst', but
'respawn' is fine too.
 root@box:/home/tc/tcfs# vi etc/inittab
Code: [Select]
# /etc/inittab: init configuration for busybox init.
# Boot-time system configuration/initialization script.
::sysinit:/etc/init.d/rcS

tty1::askfirst:/sbin/getty 38400 tty1
tty2::askfirst:/sbin/getty 38400 tty2
tty3::askfirst:/sbin/getty 38400 tty3
tty4::askfirst:/sbin/getty 38400 tty4

# Stuff to do when restarting the init
# process, or before rebooting.
::restart:/etc/init.d/rc.shutdown
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/etc/init.d/rc.shutdown

3): /home/tc/tcfs/etc/profile
This file is for my PS1 prompt.
 root@box:/home/tc/tcfs# vi etc/profile
Code: [Select]
# /etc/profile: system-wide .profile file for the Bourne shells

PATH="/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin"

# set a fancy prompt
if [ "`id -u`" -eq 0 ]; then
  PS1="\[\033[0;31m\]\u\[\033[0;39m\]@\h\[\033[0;36m\][\w]\[\033[0;39m\]\\$ "
else
  PS1="\[\033[1;33m\]\u\[\033[0;39m\]@\h\[\033[0;36m\][\w]\[\033[0;39m\]\\$ "
fi

# Screen display for X and encoding for GTK+ apps.
#
DISPLAY=:0.0
G_FILENAME_ENCODING=iso8859-1

# ldd fake
#
which ldd > /dev/null || alias ldd=LD_TRACE_LOADED_OBJECTS=1

# Export all variables definied above and set mask.
#
export PATH LD_LIBRARY_PATH PS1 DISPLAY G_FILENAME_ENCODING ignoreeof
umask 022

if [ -f /etc/sysconfig/language ]; then
. /etc/sysconfig/language
export LANG LC_ALL
fi

if [ -f /etc/sysconfig/timezone ]; then
. /etc/sysconfig/timezone
export TZ
fi

4): /home/tc/tcfs/etc/skel/.profile
PS1 prompt is deleted here.  Also, it stops TineCore from starting X automatically.
 root@box:/home/tc/tcfs# vi etc/skel/.profile
Code: [Select]
# ~/.profile: Executed by Bourne-compatible login SHells.
#
. /etc/init.d/tc-functions
if [ -f /etc/sysconfig/language ]; then
. /etc/sysconfig/language
export LANG LC_ALL
fi

if [ -f /etc/sysconfig/timezone ]; then
. /etc/sysconfig/timezone
export TZ
fi

# Path to personal scripts and executables (~/.local/bin).
#
if [ -d "$HOME/.local/bin" ] ; then
PATH=$HOME/.local/bin:$PATH
export PATH
fi

PAGER='less -EM'

export EDITOR PAGER

umask 022
# if ! checkbootparam "text" && [ !  -e /tmp/.X11-unix/X0 ]; then startx; fi

5): /home/tc/tcfs/root/.profile
This breaks TinyCore's function.  Without changing this file, I cannot log in
as a root user.  However, I don't log in as 'root', therefore, this change
is optional.
 root@box:/home/tc/tcfs# vi root/.profile
Code: [Select]
#!/bin/sh
#. /etc/init.d/tc-functions
#if ! checkbootparam "superuser"; then
#TCUSER="$(cat /etc/sysconfig/tcuser)"
#export HOME=/home/"$TCUSER"
#cd $HOME
#while [ 1 ]; do
#   exec su - "$TCUSER"
#done
#fi

Finally, I create new 'tinycore.gz' and save it.
 root@box:/home/tc/tcfs# find . | cpio -o -H newc | gzip -9 > ../tinycore.gz
 root@box:/home/tc/tcfs# cd -
 root@box:/home/tc# cp tinycore.gz /mnt/sda1/tc
 root@box:/home/tc# exit

Perhaps, you know a better way to do the same thing.
Please let me know.  Thank you.

Offline philip

  • Full Member
  • ***
  • Posts: 125
Re: TinyCore: My Way 2 (ttyx4 + login)
« Reply #1 on: March 20, 2009, 12:02:28 AM »
Thank you for this writeup. I was happy to learn how to open up the initrd, replace some system files, and then repackage everything. It was my first time ever to knowingly issue a "cpio" command! In case another newcomer visits this thread, let me share two of the things I learned.

(1) Run as Root.
When I tried following these steps as an unprivileged user (tc), I got messages that worried me: cpio could not create the device nodes built into /dev. I guessed that repacking something broken would be a bad idea, so I started over, running as root. That worked.

(2) When Things Start.
I had already changed the passwords for users "root" and "tc" before trying this HOWTO. Adding the files /etc/passwd and /etc/shadow to the backup list in /opt/.filetool.lst was enough to make this work. The point is to have the backup versions restored before they get used. By contrast, editing the files /etc/inittab and /etc/hostname and naming them in the backup list does not have the desired effect. These files are needed at the very earliest stages of booting, before the system uses the backup copies to overwrite the originals in the initramfs. When the modified files are finally put into place they have missed the opportunity to have any effect. (It can be confusing to look into /etc/inittab and see something that is actually different from what the system is running, but this is what I had before following your helpful instructions.)

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: TinyCore: My Way 2 (ttyx4 + login)
« Reply #2 on: March 20, 2009, 10:45:47 AM »
hjkl: That's pretty close to what I did. I use Bash for user tcl, though, so the only profile I changed was root's.  You say it "breaks TinyCore's function", what do you mean?  I haven't seen any problems so far.

Quote from: philip
Run as Root.
Any time you do work like that on system files, you must be root.  It's the only way to retain file ownership, which is vital to some files, such as devices.
Quote
By contrast, editing the files /etc/inittab and /etc/hostname and naming them in the backup list does not have the desired effect.
In some systems (apparently not TC) you can use "telinit q" to reread inittab before login.  Even if TC had telinit, though, there's a chance it wouldn't work properly in TC because bootlocal.sh is backgrounded.  It's possible that the command would not run in time, but I'm just guessing.
You can set the hostname with the boot option "host=something", so it shouldn't be necessary to deal with the file directly.