Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Iso - remaster script trying to start chroot run commands then exit but host system gets messed up Post 303039753 by paulhoffusa on Monday 14th of October 2019 04:12:10 PM
Old 10-14-2019
Code:
# Begin chroot 
chrootbeg() {
  echo "chrootbeg - beg funct ..."
  sudo mount --bind /dev/ unsquash/dev
  sudo chroot unsquash

  mount -t proc none /proc/
  mount -t sysfs none /sys/
  mount -t devpts none /dev/pts
  export HOME=/root
  export LC_ALL=C
  dbus-uuidgen > /var/lib/dbus/machine-id
  dpkg-divert --local --rename --add /sbin/initctl   //not sure what this does...
  ln -s /bin/true /sbin/initctl
}

# End chroot
chrootend(){
  echo "chrootend - beg funct ..."
  ap_clean
  rm -rf /tmp/* ~/.bash_history
  rm /var/lib/dbus/machine-id
  rm /etc/resolv.conf
  rm /sbin/initctl
  dpkg-divert --rename --remove /sbin/initctl
  #### Clean older/non-used kernels...
  dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
  umount /proc || umount -lf /proc
  umount /sys || umount -lf /sys
  umount /dev/pts  || umount -lf /dev/pts
  #HELP - Uncomment or comment out lines below?
  #HELP - will exit exit function early and not execute unmount command below?
  # Move 2 lines outside of function to be executed after function
  #exit
  #sudo umount unsquash/dev || umount -lf unsquash/dev
  #HELP - END
}


#HELP - after this script ends run with 'm' option -
  # my system is messed up. Not sure if never chrooted correct or 
  # never exited correctly. I have a 30 GB VB image i have backed up
  # that  I have to restore from every time after this script runs
  # when trying to run all code inbetween the chrootbeg and chrootend
  # functions. Can some expert please give me something specific to try
  # I think my chroot code is flawed but not sure why. I can't even run 
  # the sudo command on main system after this script run after chroot.
  echo "Chrooting into the system ..."
  chrootbeg
  fn="/etc/apt/sources.list"
  cat $fn | grep "non-free" 2>/dev/null >/dev/null
  if [ "$?" != "0" ]; then
    if [ ! -f $fn.org ]; then
      cp $fn $fn.org
    fi
    echo "Modifying file '"$fn"' adding contrib and non-free repos ..."
    sed -i 's/main/main contrib non-free/g' $fn
    cp $fn $fn.mod
    echo; ls -la $fn*; echo
  fi
  echo "apt-get update ..."
  apt-get update
  echo "Deleting libreoffice ..."
  apt-get remove --purge libreoffice-*
  echo "Deleting all non English language packs ..." 
  apt-get remove --purge `dpkg-query -W --showformat='${Package}\n' | grep language-pack | egrep -v '\-en'`
  echo "apt-get upgrade ..."
  apt-get upgrade
  echo "Installing various packages that I need ..."
  apt install curl wget apt-transport-https dirmngr
  echo "Chrooting the system  is ending ..."
  chrootend 
  echo "WARN WARN WARN - Make sure line below is executed because occurs after an exit ..."
  echo "sudo umount unsquash/dev || umount -lf unsquash/dev"
  echo "Run 'mount | grep \"unsquash/dev\"' to check after this script exits!"
  exit
  sudo umount unsquash/dev || umount -lf unsquash/dev
  #HELP - END

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

2. UNIX for Dummies Questions & Answers

How to start a chroot jail?

I was reading an article on how it is very important to setup a chroot jail to run bind. I can follow what the article says but one thing I am unclear about is now on system boot the BIND process in the chroot jail will start since it the owner will no longer be root but some other user. Can... (1 Reply)
Discussion started by: mojoman
1 Replies

3. Shell Programming and Scripting

running commands to remote host from centralized host

Gurus/Experts We have a centralized UNIX/Solaris server from where we can actually ssh to all other UNIX/Solaris servers...I need to write a script that reside on this centerlized server and do FileSystem monitoring (basically run df -h or -k) of other remote servers and then send an email to me... (6 Replies)
Discussion started by: anjum.suri
6 Replies

4. Shell Programming and Scripting

fuser exit code different when script is run from cron

Hi, I am writing a bash script (running on Centos 5.4) to process video (.MTS) files which may have appeared in a certain directory. The files will be dragged and dropped there from a Windows box using Samba, and the script is to check periodically (i.e. run from cron) whether any new .MTS... (0 Replies)
Discussion started by: Palamedes
0 Replies

5. UNIX for Dummies Questions & Answers

Run a script on remote host

Hi, I wish to run a script located on a remote host machineB from machineA. I am using ssh and running the below on machineA. However, the ssh does not seem to work and freezes at ssh -l wlsadmin machineB -v Sun_SSH_1.1.2, SSH protocols 1.5/2.0, OpenSSL 0x0090704f debug1: Reading... (9 Replies)
Discussion started by: shifahim
9 Replies

6. Shell Programming and Scripting

HTML Code to Run a Script from Remote Unix Host

Hi All, Noticed few posts around this but coudnt get exatcly what i wanted. Thanks for your help again. I have a script running on a remote machine and i normally ssh from putty and run the script manually. Is there anyway that i can write an HTML Code with a button so taht when I Click... (1 Reply)
Discussion started by: robinbannis
1 Replies

7. Shell Programming and Scripting

How to run a shell script on a remote host using ftp

Hi, is there a way I can run a shell script through ftp on a remote host? The remote host doesn't have ssh running so I can't use ssh. (7 Replies)
Discussion started by: mrskittles99
7 Replies

8. UNIX for Dummies Questions & Answers

Creating chroot environment with an ISO file.

I decided to try creating a chroot environment with a BT5r2 iso file. I'm just wanting to run Backtrack from inside Debian without having to reboot into my other partition or use vmware. I found some documentation on how to do this with BT4 at this link: ... (0 Replies)
Discussion started by: Azrael
0 Replies

9. Shell Programming and Scripting

Run script on remote host

Hi friends, I have two servers. Server A and B. I want to run one script on server A by logging in to server B. Can anyone provide me code for this.? I tried it by using following ssh username@serverA ./script Then it prompt me the password. I give correct password of the server A. but it... (7 Replies)
Discussion started by: Nakul_sh
7 Replies

10. Shell Programming and Scripting

Inner script run and its exit status

Main Script #!/bin/ksh echo "Maimn script" ./clocal/www/web-data/WAS/WebSphere7/scripts/DealerLocator/Scripts/secondscript.ksh echo "$? = status" Sdecond Script #!/bin/ksh echo "In second SCript" exit 1 Output: Maimn script ./testmain.ksh:... (4 Replies)
Discussion started by: dineshaila
4 Replies
fd(4)							     Kernel Interfaces Manual							     fd(4)

NAME
fd - file descriptor files DESCRIPTION
The /dev/fd file system is a pseudo-file system layered beneath the Virtual File System (VFS). The file descriptor files (fd*) are those files that are accessible through file descriptors. The file descriptors use the naming convention /dev/fd/0, /dev/fd/1, /dev/fd/2 and so on up to any number. To make the /dev/fd file system known to the operating system, you must create the directory with the correct privileges, then you must mount the file system. The following steps describe how to create the directory, mount the file system both manually and automatically, and how to dismount the file system: Create the directory using the mkdir and chmod commands: mkdir /dev/fd; chmod 777 /dev/fd Mount the file system manually using the mount command: mount -t fdfs /dev/fd /dev/fd Mount the file system automatically by editing either the /etc/fstab file or the /sbin/bcheckrc file. Add the following entry to the /etc/fstab file: /dev/fd /dev/fd fdfs rw 0 0 This entry mounts the pseudodevice /dev/fd on the /dev/fd directory with read/write privileges. The file system type is fdfs and the zeros (0) in the remaining fields specify that the file system is not to be backed up nor can file system checks be performed by the fsck command as this is a virtual file system. Add the following entry to the /sbin/bcheckrc file: # # mount fdfs # echo 'Mounting /dev/fd filesystem' /sbin/mount -a -v -t fdfs Again, the /dev/fd file system should not be mounted in this manner if an entire system is to be backed up starting from the root directory. Dismount the file system using the umount command: umount /dev/fd For correct truncate() behavior on fd files, you must load your program using the -lsys5 flag. RESTRICTIONS
The /dev/fd file descriptors should not be exported. EXAMPLES
The following example show how the open and dup functions have the same effect if file descriptor n is opened: fd = open("/dev/fd/n", mode); fd = dup(n); In the above example, the open function is equal to the creat function and mode is ignored. Using the dup function, subsequent reads or writes on the fd file descriptor files fail unless the original file descriptor enables the operation. ERRORS
The following error condition exists: The file descriptor is not valid. RELATED INFORMATION
Commands: chmod(1), mkdir(1), mount(8). Functions: creat(2), dup(2), open(2). delim off fd(4)
All times are GMT -4. The time now is 10:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy