WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: After booting USB to console can I finish in /mnt/sd# instead of /home/tc?  (Read 3295 times)

Offline Rudock1

  • Jr. Member
  • **
  • Posts: 62
I use bootable USB flash drives in simple text console mode. Rather than finishing the boot in my home folder (~ or /home/tc), I would like to exit with my pwd located at the boot device /mnt/sd? directory.  I am trying to make a change to /opt/bootlocal.sh but I am not succeeding.

I am using tc-functions find_mountpoint and $MOUNTPOINT. I think I understand my problem exists because scripts run a sub-shell and all newly exported system environment variables are lost after the sub-shell is terminated.  The child process does not control the parent process. 

I tried a few different ways which are commented out below... any suggestions how to finish booting and landing at the boot device /mnt/sd? directory?
Code: [Select]
#!/bin/bash

source /etc/init.d/tc-functions
readonly MYLABEL="SEABOOT"; # my USB flash drives always have this label
declare MNTPATH="";

#------------------------------------------------------
function _bootguess () {
  local default_blkid="";

  default_blkid=$(blkid -L "${MYLABEL}");
  BOOTFROM=${default_blkid};
  BOOTFROM=$(echo ${BOOTFROM/\/dev\//}); #string substitution delete
  #echo ${BOOTFROM};
  find_mountpoint ${BOOTFROM}; # one of the tc-functions
  #echo ${MOUNTPOINT}; # one of the tc-functions globals
  MNTPATH=${MOUNTPOINT};
}

_bootguess
echo ${MNTPATH}

# try #1
#cd ${MNTPATH}

# try #2
#export PWD=${MNTPATH}

# try 3
#shopt -s expand_aliases
#alias cm='cd ${MNTPATH}';
#cm

pwd

Thanks in advance, as always, I appreciate your good advice.

thx
Billy

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11703
Hi Rudock1
There is no variable that records the boot device. The best you can hope for is to derive the boot device by ensuring it contains
your  tce  directory and including the boot code:
Code: [Select]
tce=UUID="Place your devices UUID here"
Knowing the  tce  directory you are using is on the boot device allows you to find it like this:
Code: [Select]
tc@E310:~$ readlink /etc/sysconfig/tcedir | cut -d '/' -f 2,3
mnt/sda1
tc@E310:~$

Offline Rudock1

  • Jr. Member
  • **
  • Posts: 62
Thanks, Rich,
I like your method of determining /mnt/sda1 (in your example, and my system too).  I added that to my bootlocal.sh but I am still finishing the boot sequence at ~ (/home/tc) rather than at the /mnt/sda1 prompt.  Wondering how to make that last 'cd /mnt/sda1' stick.

thx
Billy

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11703
Hi Rudock1
I think you could add it to your  .profile  file in your home directory. Something like this:
Code: [Select]
TERMTYPE=`/usr/bin/tty`
[ ${TERMTYPE:5:3} == "tty" ] && (
[ ! -f /etc/sysconfig/Xserver ] ||
[ -f /etc/sysconfig/text ] ||
[ -e /tmp/.X11-unix/X0 ] ||
startx
)
cd /`readlink /etc/sysconfig/tcedir | cut -d '/' -f 2,3`

If that doesn't work, try adding it just above the  TERMTYPE=`/usr/bin/tty`  line.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11703
Hi Rudock1
Quote
cd /`readlink /etc/sysconfig/tcedir | cut -d '/' -f 2,3`
In case you didn't realize it, the green punctuation marks are single quotes (on the " key). The red punctuation marks are back ticks
(on the ~ key).

Offline Rudock1

  • Jr. Member
  • **
  • Posts: 62
Thanks, Rich. 
It takes a keen eye to spot the punctuation difference, thank you for pointing it out.  Otherwise, I added the cd command to the /mnt/sd? folder in ~/.profile as you suggested and it works great!  I don't think /opt/bootlocal.sh was going to work.
thanks again
Billy

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11703
Hi Rudock1
Thanks, Rich. 
It takes a keen eye to spot the punctuation difference, thank you for pointing it out. ...
It occurred to me later on that this might be a source of confusion, so I thought it best to highlight those differences. Their tiny size
and possibly certain fonts make it easier to miss that back ticks were used. It's happened to me on a few occasions.

Quote
I don't think /opt/bootlocal.sh was going to work.
Not likely since it doesn't provide the users shell.