Advertisement
plirof2

linuxrc_mod01linksfs1-3 ver001

Aug 24th, 2021
1,716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 26.02 KB | None | 0 0
  1. Bulleye Link SFS1 files to live (with smaller names) to avoid overlay limit
  2. https://forum.puppylinux.com/viewtopic.php?f=46&t=1857&start=250
  3. DOESN'T get parameter
  4.  
  5. #!/bin/sh
  6. ### linuxrc script by brokenman <http://www.porteus.org>
  7. ### modified for Debiandog by fredx181
  8.  
  9. export PATH=/bin:/usr/bin:./
  10.  
  11. # Source functions
  12. . ./finit
  13.  
  14. # Enable pivot_root in initramfs to let it behave like initrd:
  15. if [ -d /m ]; then
  16.    mount -nt tmpfs tmpfs -o mode=0755 /m
  17.    cp -a ??* /m 2>/dev/null
  18.    exec switch_root /m linuxrc "$@"
  19. fi
  20.  
  21. mount -nt proc proc /proc
  22. mount -nt sysfs sysfs /sys
  23. echo 0 >/proc/sys/kernel/printk
  24.  
  25. echo "`cat /proc/cmdline|sed -e 's/^/ /'`" > /etc/cmdline
  26. param() { egrep -qo " $1( |\$)" /etc/cmdline; }
  27. value() { egrep -o " $1=[^ ]+" /etc/cmdline | cut -d= -f2; }
  28. debug() { param debug && { echo -e "\n=====\n: Debugging started. Here is the shell for you.\n: Type your desired commands, hit Ctrl+D to continue booting\n: or press Ctrl+Alt+Del to reboot."; sh; echo -e "\n\n"; }; }
  29.  
  30. ## Check for debug
  31. if [ `grep -q debug /proc/cmdline` ]; then DBUG=0; fi
  32.  
  33. clear
  34. echo -e "${BOLD}Starting init script.${RST}"
  35.  
  36. # Variables:
  37. i=`echo """^ """`
  38. m=`echo """->"""`
  39. arch=`uname -m`; [ $arch = x86_64 ] || arch=i586
  40. CFG=`value cfgfile`; [ $CFG ] || CFG=initrd1.xz
  41. FROM=`value from`; ISO=`echo $FROM | egrep ".*\.iso( |\$)"`
  42. IP=`value ip | cut -d: -f2`
  43. MOPT=`value mopt`; [ $MOPT ] || MOPT="noatime,nodiratime,suid,dev,exec,async"
  44. CHANGES=`value changes`
  45. RAMSIZE=`value ramsize`; [ $RAMSIZE ] || RAMSIZE=60%
  46. LOAD=`value load | sed 's/;/|/g'`; [ $LOAD ] || LOAD=._null
  47. NOLOAD=`value noload | sed 's/;/|/g'`; [ $NOLOAD ] || NOLOAD=._null
  48. EXTRAMOD=`value extramod | sed 's/;/ /g'`
  49. RAMMOD=`value rammod | sed 's/;/|/g'`
  50. ROOTCOPY=`value rootcopy`
  51. FOLDER=live
  52. livedbg=/var/log/livedbg
  53. LOGFILE=/var/log/boot.log
  54.  
  55. ## Let's start!
  56. echo $i"loading kernel modules..."
  57.  
  58. for MODULE in $(cat modlist)
  59. do
  60. modprobe $MODULE 2> /dev/null
  61. done
  62.  
  63.  
  64. mount -nt devtmpfs none /dev
  65.  
  66. # Perform filesystem check:
  67. if param fsck; then
  68.     echo $i"performing linux filesystem check on all available devices:"
  69.     draw
  70.     for x in `blkid | grep 'TYPE="ext' | cut -d: -f1`; do e2fsck -C 0 -p $x; wait; done
  71.     for x in `blkid | grep 'TYPE="reiserfs"' | cut -d: -f1`; do reiserfsck -p $x; wait; done
  72.     draw
  73. fi
  74.  
  75. # Create /etc/fstab and mount devices:
  76. fstab
  77.  
  78.  
  79. #JON v210824 START+++++++++++++++++++++++++++
  80. #remove linked from folder sfs1
  81. if param linkremovesfs1; then
  82.     echo $i"remove linked from folder sfs1, this may take some time..."
  83.     for i in *_sfs1.squashfs; do
  84.         rm "${i}"
  85.     done
  86. fi
  87. # remove linked from folder sfs2
  88. if param linkremovesfs2; then
  89.     echo $i"remove linked files from folder sfs2, this may take some time..."
  90.     for i in *_sfs2.squashfs; do
  91.         rm "${i}"
  92.     done
  93. fi
  94. # remove linked from folder sfs3
  95. if param linkremovesfs3; then
  96.     echo $i"remove linked files from folder sfs3, this may take some time..."
  97.     for i in *_sfs3.squashfs; do
  98.         rm "${i}"
  99.     done
  100. fi
  101.  
  102. # link SFS1
  103. if param linksfs1; then
  104.     echo $i"linking files from folder sfs1, this may take some time..."
  105.     a=1
  106.     for i in sfs1/*.squashfs; do
  107.         new=$(printf "%03d_sfs1.squashfs" "$a")
  108.         ln -s "${i}" "$new"
  109.         let a=a+1
  110.     done
  111. fi
  112. # link SFS2
  113. if param linksfs2; then
  114.     echo $i"linking files from folder sfs1, this may take some time..."
  115.     a=1
  116.     for i in sfs2/*.squashfs; do
  117.         new=$(printf "%03d_sfs2.squashfs" "$a")
  118.         ln -s "${i}" "$new"
  119.         let a=a+1
  120.     done
  121. fi
  122.  
  123. # link SFS3
  124. if param linksfs3; then
  125.     echo $i"linking files from folder sfs3, this may take some time..."
  126.     a=1
  127.     for i in sfs3/*.squashfs; do
  128.         new=$(printf "%03d_sfs3.squashfs" "$a")
  129.         ln -s "${i}" "$new"
  130.         let a=a+1
  131.     done
  132. fi
  133.  
  134. #rm *_sfs2.aaa
  135.  
  136. #JON END -----------------------------
  137.  
  138.  
  139.  
  140. debug
  141. # Find *.cfg file:
  142. echo $i"searching for $CFG file"
  143. if [ $IP ]; then BOOTDEV=network; CFGDEV=/mnt/nfs
  144. #   softdep for r8169 https://bugzilla.kernel.org/show_bug.cgi?id=204343
  145.     modprobe realtek 2>/dev/null
  146.     for x in `lspci | grep 0200: | cut -d: -f3-4 | sed s/:/.*/g | tr a-z A-Z`; do modprobe `grep $x /lib/modules/$(uname -r)/modules.alias | tail -n1 | rev | cut -d" " -f1 | rev` 2>/dev/null; done
  147.     ls /sys/class/net | grep -q eth || { for x in `find /lib/modules/$(uname -r)/kernel/drivers/net -name "*.ko" | sed 's/.ko//g'`; do modprobe `basename $x` 2>/dev/null; ls /sys/class/net | grep -q eth && break || modprobe -r `basename $x` 2>/dev/null; done; }
  148.     mkdir -p /mnt/nfs/storage; udhcpc; modprobe nfsv4; mount -t nfs4 $IP:/srv/pxe /mnt/nfs -o ro,nolock 2>/dev/null || { modprobe nfsv3; mount -t nfs $IP:/srv/pxe /mnt/nfs -o ro,nolock 2>/dev/null; }
  149.     MAC=`ifconfig | grep eth0 | cut -d: -f5-7 | sed s/://g | cut -d" " -f1`
  150.     if [ "$CHANGES" = /srv/pxe/storage ]; then
  151.     if lsmod | grep -q nfsv3; then
  152.         mount -t nfs $IP:/srv/pxe/storage /mnt/nfs/storage -o rw,nolock 2>/dev/null && { mkdir -p /mnt/nfs/storage/client-$MAC/changes/home; CHANGES="/storage/client-$MAC"; }
  153.     else
  154.         mount -t nfs4 $IP:/srv/pxe/storage /mnt/nfs/storage -o rw,nolock 2>/dev/null && { mkdir -p /mnt/nfs/storage/client-$MAC/changes/home; CHANGES="/storage/client-$MAC"; }
  155.     fi
  156.     fi
  157.     if [ $FROM ]; then
  158.         FOLDER=$FROM/live
  159.     fi
  160. elif [ $ISO ]; then CFGDEV=/mnt/isoloop
  161.     locate -e $FROM && { BOOTDEV=/mnt/$DEV; mkdir /mnt/isoloop; mount -o loop /mnt/$DEV/$LPTH /mnt/isoloop; ISOSRC=/mnt/$DEV/$LPTH; }
  162. else
  163.     if [ $FROM ]; then
  164.     locate -e $FROM/live/$CFG
  165.     if [ $? -eq 0 ]; then
  166.         DIR=`echo $LPTH | rev | cut -d/ -f3- | rev`; [ $DIR ] && FOLDER=$DIR/live
  167.     else
  168.         echo -e "${YELLOW}from= cheatcode is incorrect, press enter to search through all devices${RST}"
  169.         read -s; search -e live/$CFG
  170.     fi
  171.     else
  172.     search -e live/$CFG || lazy -e live/$CFG
  173.     fi
  174.     CFGDEV=/mnt/$DEV
  175. fi
  176.  
  177. [ -e $CFGDEV/$FOLDER/$CFG ] && PTH=$CFGDEV/$FOLDER || . fatal
  178.  
  179. # Set some variables to export as environment variables
  180. DELAY=`value delay`; [ $DELAY ] && { echo $i"delaying $DELAY sec (waiting for slow devices to settle)"; sleep $DELAY; }
  181. BOOTDEV=$CFGDEV
  182. MODDIR=$PTH/modules
  183. BASEDIR=${PTH%/*}
  184. PORTDIR=$PTH
  185. PORTCFG=$CFGDEV/$FOLDER/$CFG
  186. echo $i"using data from $PTH"
  187. echo  $PTH > /etc/homedrv
  188. # Make all drivers available:
  189. #mount -o loop $PTH/base/000-kernel.xzm /opt/000-kernel 2>/dev/null
  190. #mount -o bind /opt/000-kernel/lib/modules /lib/modules 2>/dev/null
  191.  
  192. # Create symlinks used often by porteus scripts:
  193. if [ $CFGDEV = /mnt/nfs -o $CFGDEV = /mnt/isoloop ];then
  194.     ln -sf /mnt/live$PTH/modules  /porteus/modules
  195.     ln -sf /mnt/live$PTH/optional /porteus/optional
  196. else
  197.     ln -sf $PTH/modules  /porteus/modules
  198.     ln -sf $PTH/optional /porteus/optional
  199. fi
  200.  
  201. debug
  202. pos_fail () {
  203.         rm -f /memory/changes/._test1 /memory/changes/._test2; umount /memory/changes
  204.         echo && echo -e """A Windows filesystem (FAT, NTFS) or other non-posix compatible filesystem\nhas been detected on $CHANGES or $(echo $CHANGES |sed 's|\(.*\)/.*|\1|') .\nYour changes cannot be saved directly to the specified storage media with this\nsetup."""
  205.         echo "press enter to continue in 'Always Fresh' mode for this session"
  206.         read; rmdir /mnt/$DEV/$LPTH/changes 2>/dev/null; fail_chn
  207. }
  208.  
  209. pos_fail1 () {
  210.         rm -f /memory/changes/._test1 /memory/changes/._test2; umount /memory/changes
  211. echo && echo -e """A Windows filesystem (FAT, NTFS) or other non-posix compatible filesystem\nhas been detected on $(echo $CHANGES |sed 's|\(.*\)/.*|\1|').\nYour changes cannot be saved directly to the specified storage media with this\nsetup."""
  212.         echo "press enter to continue in 'Always Fresh' mode for this session"
  213.         read; rmdir /mnt/$DEV/$LPTH/changes 2>/dev/null; fail_chn
  214.  
  215. }
  216.  
  217. # Setup changes:
  218. if [ $CHANGES ]; then
  219.     echo $i"setting up directory for changes"
  220.     CHNEXIT=`echo $CHANGES | cut -d: -f1`;
  221.     [ $CHNEXIT = EXIT ] && CHANGES=`echo $CHANGES | cut -d: -f2-`
  222.     [ $CHNEXIT = +EXIT ] && CHANGES=`echo $CHANGES | cut -d: -f2-`  
  223.    
  224.     [ -r $CFGDEV/$CHANGES ] && { DEV=`echo $CFGDEV | sed s@/mnt/@@`; LPTH=$CHANGES; } || locate -r $CHANGES
  225.     if [ $? -eq 0 ]; then
  226.     if [ -d /mnt/$DEV/$LPTH ]; then
  227.         mkdir -p /mnt/$DEV/$LPTH/changes 2>/dev/null && \
  228.         mount -o bind /mnt/$DEV/$LPTH/changes /memory/changes && touch /memory/changes/._test1 2>/dev/null
  229.     else
  230.         if blkid /mnt/$DEV/$LPTH 2>/dev/null | cut -d" " -f3- | grep -q _LUKS; then
  231.         for x in dm_crypt cryptd cbc sha256_generic aes_generic aes_x86_64; do modprobe $x 2>/dev/null; done
  232.         losetup /dev/loop2 /mnt/$DEV/$LPTH
  233.         echo $i"found encrypted .dat container"
  234.         cryptsetup luksOpen /dev/loop2 crypt
  235.         fsck_dat /dev/mapper/crypt
  236.         mount /dev/mapper/crypt /memory/changes 2>/dev/null && touch /memory/changes/._test1 2>/dev/null
  237.         else
  238.         fsck_dat /mnt/$DEV/$LPTH
  239.         mount -o loop /mnt/$DEV/$LPTH /memory/changes 2>/dev/null && touch /memory/changes/._test1 2>/dev/null
  240.         fi
  241.     fi
  242.     if [ $? -eq 0 ]; then
  243.         echo $i"testing filesystem on "$CHANGES" for posix compatibility"
  244.         ln -s /memory/changes/._test1 /memory/changes/._test2 2>/dev/null && chmod +x /memory/changes/._test1 2>/dev/null && [ -x /memory/changes/._test1 ] && chmod -x /memory/changes/._test1 2>/dev/null && [ ! -x /memory/changes/._test1 ] && rm -f /memory/changes/._test1 /memory/changes/._test2
  245. ret=$?
  246.         if [ $ret -ne 0 ]; then
  247.             posfail=yes
  248.             fi
  249. if [ $CHNEXIT = +EXIT ];then
  250.   if [ ! -d /mnt/$DEV/$LPTH ]; then
  251.   APTH=$(echo /mnt/$DEV/$LPTH |sed 's|\(.*\)/.*|\1|')
  252.     rm -f /memory/changes/._test1 /memory/changes/._test2; umount /memory/changes
  253.         mkdir -p $APTH/changes 2>/dev/null && \
  254.         mount -o bind $APTH/changes /memory/changes && touch /memory/changes/._test1 2>/dev/null
  255.   else
  256.     rm -f /memory/changes/._test1 /memory/changes/._test2; umount /memory/changes
  257.         mkdir -p /mnt/$DEV/$LPTH/changes 2>/dev/null && \
  258.         mount -o bind /mnt/$DEV/$LPTH/changes /memory/changes && touch /memory/changes/._test1 2>/dev/null
  259.   fi
  260.         ln -s /memory/changes/._test1 /memory/changes/._test2 2>/dev/null && chmod +x /memory/changes/._test1 2>/dev/null && [ -x /memory/changes/._test1 ] && chmod -x /memory/changes/._test1 2>/dev/null && [ ! -x /memory/changes/._test1 ] && rm -f /memory/changes/._test1 /memory/changes/._test2
  261. fi
  262. ret1=$?
  263.  
  264.             if [ $ret -ne 0 ] && [ "$posfail" = "yes" ]; then
  265.         rm -f /memory/changes/._test1 /memory/changes/._test2; umount /memory/changes
  266.         echo && echo -e """A Windows filesystem (FAT, NTFS) or other non-posix compatible filesystem\nhas been detected on $CHANGES or $(echo $CHANGES |sed 's|\(.*\)/.*|\1|') .\nYour changes cannot be saved directly to the specified storage media with this\nsetup. Please use the ' Save file manager' to create a .dat container\nand use it for saving your changes after your next reboot."""
  267.         echo "boot will continue in 'Always Fresh' mode for this session"
  268.         sleep 10; rmdir /mnt/$DEV/$LPTH/changes; fail_chn
  269.  
  270.             elif [ $ret1 -ne 0 ] && [ -z "$posfail" ]; then
  271.         rm -f /memory/changes/._test1 /memory/changes/._test2; umount /memory/changes
  272. echo && echo -e """A Windows filesystem (FAT, NTFS) or other non-posix compatible filesystem\nhas been detected on $(echo $CHANGES |sed 's|\(.*\)/.*|\1|').\nYour changes cannot be saved directly to the specified storage media with this\nsetup."""
  273.         echo "press enter to continue in 'Always Fresh' mode for this session"
  274.         read; rmdir /mnt/$DEV/$LPTH/changes 2>/dev/null; fail_chn
  275.  
  276.         else
  277.         echo $i"filesystem is posix compatible"; CHNDEV=/mnt/$DEV
  278.  
  279.             if [ -f /memory/changes/clear-changes-on-reboot ]; then
  280.                       echo $i"""changes content signalled to be cleared"""
  281.                       rm -rf /memory/changes/*
  282.         fi
  283.                        
  284.         if [ "$CHNEXIT" = EXIT -o "`egrep -o " changes-ro( |\$)" /proc/cmdline`" ]; then
  285.             CHNEXIT=$CHNDEV/$LPTH; echo $CHNEXIT >/tmp/changes-exit
  286.             param changes-ro && echo $i"""changes will not be saved for this session""" || echo $i"""changes will be saved only during reboot/shutdown"""
  287.  
  288.             setClean
  289.             mkdir -p /memory/images/changes-exit
  290.             mount -n --move /memory/changes /memory/images/changes-exit
  291.             umount /memory/changes 2>/dev/null;
  292.             mount -nt tmpfs -o size=$RAMSIZE tmpfs /memory/changes;
  293.             CHANGES=memory
  294.         fi
  295.  
  296.          if [ $CHNEXIT = +EXIT ]; then
  297.             CHNEXIT=$CHNDEV/$LPTH; echo $CHNEXIT >/tmp/changes-exit
  298.             echo $i"""changes will be saved only during reboot/shutdown"""
  299.  
  300.           if [ ! -d /mnt/$DEV/$LPTH ]; then
  301.               APTH=$(echo /mnt/$DEV/$LPTH |sed 's|\(.*\)/.*|\1|')
  302.           echo $i"""option +EXIT is being used, changes are NOT written in memory"""
  303.           echo $i"""temporary changes will be in $APTH/tmp-changes """
  304. umount /memory/changes 2>/dev/null; rmdir $APTH/changes 2>/dev/null
  305. mount -o loop /mnt/$DEV/$LPTH /memory/changes 2>/dev/null
  306.             setClean
  307.  
  308.             mkdir -p /memory/images/changes-exit
  309.             mount -n --move /memory/changes /memory/images/changes-exit
  310.             #umount /memory/changes 2>/dev/null;
  311.             #mount -nt tmpfs -o size=$RAMSIZE tmpfs /memory/changes;
  312.             #CHANGES=memory
  313.           rm -rf $APTH/tmp-changes 2> /dev/null
  314.           mkdir -p $APTH/tmp-changes
  315.           mount -o bind $APTH/tmp-changes /memory/changes
  316.           else
  317.           echo $i"""option +EXIT is being used, changes are NOT written in memory"""
  318.           echo $i"""temporary changes will be in /mnt/$DEV/$LPTH/tmp-changes"""
  319.             #umount /memory/changes;
  320.             setClean
  321.             mkdir -p /memory/images/changes-exit
  322.             mount -n --move /memory/changes /memory/images/changes-exit
  323.             umount /memory/changes 2>/dev/null;
  324.             #mount -nt tmpfs -o size=$RAMSIZE tmpfs /memory/changes;
  325.             #CHANGES=memory
  326.           rm -rf /mnt/$DEV/$LPTH/tmp-changes 2> /dev/null
  327.           mkdir -p /mnt/$DEV/$LPTH/tmp-changes
  328.           mount -o bind /mnt/$DEV/$LPTH/tmp-changes /memory/changes
  329.  
  330.  
  331.           fi
  332.         fi
  333.         fi
  334.     else
  335.         echo $i"changes not writable, using memory instead"; CHGERR=2; umount /memory/changes 2>/dev/null; fail_chn
  336.     fi
  337.     else
  338.     fail $CHANGES; fail_chn
  339.     fi
  340. else
  341.      echo $i"changes cheatcode not found, using memory only"; fail_chn
  342. fi
  343.  
  344. mkdir -p /memory/changes/upperdir/mnt/live
  345.  
  346. debug
  347. # Setup aufs:
  348. #echo $i"creating live filesystem and inserting modules"
  349. #mount -t aufs -o nowarn_perm,xino=/memory/xino/.aufs.xino,br:/memory/changes=rw aufs /union
  350. #if [ $? -ne 0 ]; then echo -e """cant setup union (aufs) - read only filesystem?\nWhen you finish debugging press Ctrl+Alt+Del to reboot."""; sh; fi
  351.  
  352. # Check for base modules update
  353. if [ -d $CFGDEV/$FOLDER/updates ]; then
  354.     echo $i"""Base updates detected ..."""
  355.     # Check if user has booted over network or from ISO
  356.     if [ $ISO ]||[ $IP ]||[ "$CFGDEV" = /mnt/isoloop ]; then
  357.         echo $i"Booting from ISO or network detected. Skipping updates ..."
  358.     else
  359.         if is_writable $CFGDEV/$FOLDER/base; then
  360.             echo $i"Copying base updates ... please wait"
  361.             basemods=`ls -1 $CFGDEV/$FOLDER/updates | grep "^00[1-3]-[a-z|A-Z]"`
  362.             for x in $basemods; do
  363.                 echo "Copying: $x ot $CFGDEV/$FOLDER/porteus/"
  364.                 cp $CFGDEV/$FOLDER/updates/$x $CFGDEV/$FOLDER/base/ 2>/dev/null
  365.                 rm $CFGDEV/$FOLDER/updates/$x
  366.             done
  367.             rm -rf $CFGDEV/$FOLDER/updates && echo "Removed updates folder" echo "Copying: $x ot $CFGDEV/$FOLDER/porteus/" || echo "COuld not remove updates folder"
  368.         else
  369.             echo $i"Non writable media. Skipping updates ..."
  370.         fi
  371.     fi
  372. fi
  373.  
  374. # Find modules:
  375. find $PTH $PTH/base $PTH/modules -maxdepth 1 -name "*.squashfs" 2>/dev/null | egrep -ve "$NOLOAD" | sort >/tmp/modules
  376. find $PTH/optional -name "*.squashfs" 2>/dev/null | egrep -e "$LOAD" | sort >>/tmp/modules
  377.  
  378. if param vga_detect; then
  379.     echo $i"detecting GPU"
  380.     lspci >/tmp/lspci; nv=`grep "0300: 10de:" /tmp/lspci | cut -d":" -f4`; amd=`grep "0300: 1002:" /tmp/lspci | cut -d":" -f4`
  381.     if [ $nv ]; then
  382.     echo $i"$nv chipset found, checking which nvidia driver supports it"
  383.     cd /usr/share/pciids/NVIDIA; NV=`grep $nv * | cut -d: -f1`; cd /
  384.     if [ $NV ]; then
  385.         echo $i"nvidia-$NV.xx driver will be activated -"
  386.         echo $i"if present in $PTH/optional folder"
  387.         find $PTH/optional -name "nvidia-$NV*" 2>/dev/null >>/tmp/modules
  388.     else
  389.         echo $i"latest nvidia driver will be activated -"
  390.         echo $i"if present in $PTH/optional folder"
  391.         find $PTH/optional -name "nvidia-*" 2>/dev/null | egrep -v '96.43.|173.14.|304.' >>/tmp/modules
  392.     fi
  393.     elif [ $amd ]; then
  394.     echo $i"checking if $amd GPU belongs to 'Radeon HD' series"
  395.     cd /usr/share/pciids/AMD; HD=`grep $amd * | cut -d: -f1`; cd /
  396.     if [ $HD ]; then
  397.             echo $i"$HD-xx driver will be activated -"
  398.             echo $i"if present in $PTH/optional folder"
  399.             find $PTH/optional -name "$HD-*" 2>/dev/null >>/tmp/modules
  400.         else
  401.             echo $i"$amd GPU is not supported by amd-catalyst driver - refusing activation"
  402.         fi
  403.     else
  404.         echo $i"could not find any nVidia/AMD GPU on this PC"
  405.     fi
  406. fi
  407.  
  408. if param base_only; then
  409. grep live /tmp/modules | grep -v modules > /tmp/mod
  410. #    grep base/0 /tmp/modules > /tmp/mod
  411.     mv /tmp/mod /tmp/modules
  412. else
  413.     if [ "$EXTRAMOD" ]; then
  414.     for folder in $EXTRAMOD; do
  415.         echo $i"searching for additional modules in $folder"
  416.         locate -d $folder && { find /mnt/$DEV/$LPTH -name "*.squashfs" 2>/dev/null | egrep -ve "$NOLOAD" | sort >>/tmp/modules; } || fail $folder
  417.     done
  418.     fi
  419. fi
  420.  
  421. # Copy data to RAM:
  422. if param copy2ram; then
  423.     echo $i"copying data to RAM, this may take some time..."
  424.     [ $RAMMOD ] && { egrep -e "$RAMMOD" /tmp/modules > /tmp/rammod; cpmod /tmp/rammod; } || cpmod /tmp/modules
  425. fi
  426.  
  427. # Populate aufs with modules:
  428. umount /lib/modules /opt/000-kernel 2>/dev/null
  429.  
  430. #while read line; do
  431. #    NAME=`basename "$line"`
  432. #    mkdir /memory/images/"$NAME"
  433. #    mount -o loop "$line" /memory/images/"$NAME" 2>/dev/null
  434. #    if [ $? -eq 0 ]; then
  435. #   echo "  $m  $NAME"; mount -no remount,add:1:/memory/images/"$NAME"=rr aufs /union
  436. #    else
  437. #   echo $i"""Cannot read $NAME - corrupted module?"""; rmdir /memory/images/"$NAME"
  438. #    fi
  439. #done < /tmp/modules
  440.  
  441. IncludeModules
  442.  
  443.  
  444. #mount -no bind /union/lib/modules /lib/modules 2>/dev/null
  445.  
  446. # Add "changes on exit" device/file/folder:
  447. #if [ -e /tmp/changes-exit ]; then
  448. #    mkdir /memory/images/changes
  449. #    if [ -d $CHNEXIT ]; then
  450. #   mount -o bind $CHNEXIT/changes /memory/images/changes
  451. #    elif [ -b /dev/mapper/crypt ]; then
  452. #   mount /dev/mapper/crypt /memory/images/changes
  453. #    else
  454. #   mount -o loop $CHNEXIT /memory/images/changes
  455. #    fi
  456. #    echo "  $m  changes"; mount -no remount,add:1:/memory/images/changes=ro aufs /union
  457. #    echo $CHNEXIT/changes >>/tmp/modules
  458. #    param changes-ro && rm /tmp/changes-exit
  459. #fi
  460.  
  461. debug
  462. # Copy /rootcopy folder:
  463. if param norootcopy; then
  464.     ROOTCOPY=none
  465.     echo $i"skipping /rootcopy directory"
  466. else
  467.     if [ $ROOTCOPY ]; then
  468.     locate -d $ROOTCOPY
  469.     if [ $? -eq 0 ]; then echo $i"copying content of $ROOTCOPY directory"; cp -af /mnt/$DEV/$LPTH/. /union/. 2>/dev/null; else fail $ROOTCOPY; ROOTCOPY=none; fi
  470.     else
  471.     ROOTCOPY=none
  472.     echo $i"copying content of $PTH/rootcopy directory"
  473.     cp -af $PTH/rootcopy/. /union/. 2>/dev/null
  474.     fi
  475. fi
  476.  
  477. # Collect boot arguments
  478. #grep "^[aA0-zZ9]" $PORTCFG > /union/etc/bootcmd.cfg
  479. #cat /proc/cmdline | tr ' ' '\n' >> /union/etc/bootcmd.cfg
  480.  
  481. ## Finish:
  482. # Create 7 free loop devices for truecrypt, etc...
  483. #x=`losetup | tail -n1 | cut -d: -f1 | sed 's@/dev/loop@@'`
  484. x=`grep -oE 'loop[0-9]+$' /proc/partitions  | tail -n1 | tr -d [:alpha:]`
  485. let y=x+255
  486. #while [ $x -le $y ]; do [ -b /dev/loop$y ] && break || mknod /dev/loop$y b 7 $y; let y=y-1; done
  487. #x=`losetup | tail -n1 | cut -d: -f1 | sed 's@/dev/loop@@'`; let y=x+20
  488. while [ $x -le $y ]; do [ -b /dev/loop$y ] && break || mknod /dev/loop$y b 7 $y; chmod g+rw-x,o-rwx /dev/loop$y; let y=y-1; done
  489.  
  490. if param nonetwork; then
  491.     echo $i"disabling dhcpcd and NetworkManager services"
  492.     chmod -x /union/etc/rc.d/rc.inet1 /union/etc/rc.d/rc.networkmanager 2>/dev/null
  493.     nma=/union/etc/xdg/autostart/nm-applet.desktop
  494.     test -e $nma && ! grep -q "Hidden=true" $nma && echo "Hidden=true" >> $nma
  495. fi
  496.  
  497. if [ "$IP" -a -x /union/etc/rc.d/rc.networkmanager ]; then
  498.     if [ -z "`egrep -o "copy2ram( |\$)" /proc/cmdline`" -o -d /mnt/nfs/storage/client-$MAC ]; then
  499. #    if [ -z "`egrep -o "^copy2ram" /union/etc/bootcmd.cfg`" -o -d /mnt/nfs/storage/client-$MAC ]; then
  500.     echo "nameserver $IP" > /union/etc/resolv.conf
  501.     nmc=/union/etc/NetworkManager/NetworkManager.conf; HW=`ifconfig | grep eth0 | cut -dW -f2 | cut -d" " -f2`
  502.     ! grep -q "unmanaged-devices=mac:$HW" $nmc && sed -i '/\[keyfile\]/ a\unmanaged-devices=mac:'$HW'' $nmc
  503.     fi
  504. fi
  505.  
  506. if [ $IP ] && [ -f /etc/resolv.conf ]; then
  507.     cp /etc/resolv.conf /union/etc/resolv.conf
  508. fi
  509.  
  510. # Start bluetooth if cheat exists
  511. if param bluetooth; then
  512.     echo "Starting bluetooth ..."
  513.     [ -e /union/etc/rc.d/rc.bluetooth ] && chmod +x /union/etc/rc.d/rc.bluetooth
  514. fi
  515.  
  516. cp -af /dev/console /union/dev
  517. #cat > /union/etc/mtab << EOF
  518. #aufs / aufs rw 0 0
  519. #proc /proc proc rw 0 0
  520. #sysfs /sys sysfs rw 0 0
  521. #devtmpfs /dev devtmpfs rw 0 0
  522. #devpts /dev/pts devpts rw,mode=0620,gid=5 0 0
  523. #EOF
  524.  
  525. fstab
  526.  
  527. debug
  528. #if param copy2ram; then
  529. if param copy2ram; then
  530.     [ $CFGDEV = /mnt/isoloop -o $CFGDEV = /mnt/nfs ] && { umount `grep $CFGDEV /etc/mtab | sed -n 1p | cut -d" " -f2` 2>/dev/null; CFGDEV=$BOOTDEV; }
  531.     CHNDISK=`echo $CHNDEV | cut -b6-8`; CFGDISK=`echo $CFGDEV | cut -b6-8`; REMOVABLE=`cat /sys/block/$CFGDISK*/removable 2>/dev/null`
  532.     if [ -z "`egrep -o " noeject( |\$)" /etc/cmdline`" -a "$CHNDISK" != "$CFGDISK" ]; then
  533.     if [ "$REMOVABLE" = 1 ]; then
  534.         for rdisk in `ls /mnt | grep $CFGDISK`; do
  535.         umount -n /mnt/$rdisk 2>/dev/null && rmdir /mnt/$rdisk
  536.         if [ $? -eq 0 ]; then
  537.             ! grep -qw "/dev/$rdisk.*iso9660" /etc/fstab && echo $rdisk >> /tmp/ejected || /union/bin/eject /dev/$rdisk
  538.             sed -i "/$rdisk/d" /etc/fstab
  539.         fi
  540.         done
  541.         [ `ls /mnt | grep $CFGDISK` ] || echo $i"""finished copying to RAM - booting media can be removed safely"""
  542.     else
  543.         if param nohd; then umount $CFGDEV 2>/dev/null; rmdir $CFGDEV 2>/dev/null; fi
  544.     fi
  545.     fi
  546. fi
  547.  
  548. # Create debug file:
  549. [ -e /tmp/devices ] && { echo "# Recognized devices:" >$livedbg; cat /tmp/devices >>$livedbg; }
  550. [ $BOOTDEV ] && CFGDEV=$BOOTDEV
  551. echo -e "\n# Booting device:\n$CFGDEV\n\n# data found in:\n$PTH\n\n# Changes are stored in:\n$CHANGES\n\n# Non standard /rootcopy dir:\n$ROOTCOPY\n\n# Modules activated during boot time:" >>$livedbg; cat /tmp/modules >>$livedbg
  552. grep "^/mnt/isoloop" $livedbg && echo "" >> $livedbg && echo "ISO=$ISOSRC" >> $livedbg
  553. #if [ $ISO ]; then
  554. #   [ -d /union/mnt/isoloop ] && rmdir /union/mnt/isoloop
  555. #   ln -sf /mnt/live/mnt/isoloop /union/mnt/isoloop
  556. #fi
  557. cp -af $livedbg /union/var/log/porteus-livedbg
  558.  
  559. ## Check for text mode cheat code
  560. #chk_bootcfg 3 && export OPTS="3"
  561.  
  562. cat /proc/cmdline
  563.  
  564. echo $i"changing root directory"
  565. for x in `ls -1 /union/mnt | grep -v live`; do
  566.  echo $x
  567.  [ -d /union/mnt/$x ] && rmdir /union/mnt/$x # Will fail if dir not empty!
  568.  [ -L /union/mnt/$x ] && rm -f /union/mnt/$x
  569. done
  570. #if chk_bootcfg noauto; then
  571. if grep -q noauto /proc/cmdline; then
  572.   FDEV=`echo $CFGDEV | sed s@/mnt/@@`
  573.   CDEV=`echo $CHNDEV | sed s@/mnt/@@`
  574. [ $CDEV ] && echo $CDEV > /tmp/cdev
  575.     for x in `grep /mnt/ /etc/fstab | cut -d/ -f3`; do mkdir -p /union/mnt/$x;
  576. if grep -q copy2ram /proc/cmdline; then
  577.   if [ $CFGDEV = $CHNDEV ]; then
  578. [ "$FDEV" = "$x" ] && continue  # keep $x mounted
  579.   else
  580. [ "$CDEV" = "$x" ] && continue  # keep $x mounted
  581.   fi
  582. fi
  583. if grep -qv copy2ram /proc/cmdline; then
  584.  [ "$CDEV" = "$x" ] && continue  # keep $x mounted
  585. fi
  586.  umount -n /mnt/$x 2>/dev/null && rmdir /mnt/$x;
  587.  done
  588. else
  589.     #grep /mnt/ /etc/fstab >> /union/etc/mtab
  590.     for x in `grep /mnt/ /etc/fstab | cut -d/ -f3`; do mkdir -p /union/mnt/$x; mount -n --move /mnt/$x /union/mnt/$x; rmdir /mnt/$x; done
  591. fi
  592.  
  593. sed -i 's/ ntfs / ntfs-3g /g' /etc/fstab
  594. #cp -f /etc/fstab /union/etc 2>/dev/null
  595.  
  596. # Add all symlinks of all mount points at /mnt to union
  597. #for x in `ls -1 /mnt`; do
  598. # [ -d /union/mnt/$x ] && rmdir /union/mnt/$x
  599. # ln -sf /mnt/live/mnt/$x /union/mnt/$x
  600. #done
  601.  
  602. #cp -r /etc/porteus /union/etc 2>/dev/null
  603. umount -n /lib/modules 2>/dev/null
  604. rm -r /lib/* /usr/*
  605.  
  606. debug
  607.  
  608. echo """live system is ready now - starting Debian"""
  609.  
  610. if param init=/bin/systemd; then
  611.     if [ -f /union/lib/systemd/systemd ]; then
  612. cp -f /union/lib/systemd/systemd /bin
  613.         if [ $? -eq 0 ]; then
  614.     mkdir -p /union/mnt/live
  615. echo """using systemd..."""
  616.     pivot_root /union  /union/mnt/live
  617.     exec usr/sbin/chroot . /mnt/live/bin/systemd "$@" <dev/console >dev/console 2>&1
  618.         else
  619.     echo -e """!!ERROR!!\nSomething went wrong and I cannot continue.\nPress Ctrl+Alt+Del to reboot."""
  620.     sh  
  621.         fi
  622.     else
  623.  echo """systemd not found, trying to use initscripts..."""
  624. cp -f /union/sbin/init /bin
  625.         if [ $? -eq 0 ]; then
  626.     mkdir -p /union/mnt/live
  627.     pivot_root /union  /union/mnt/live
  628.     exec usr/sbin/chroot . /mnt/live/bin/init "$@" <dev/console >dev/console 2>&1
  629.         else
  630.     echo -e """!!ERROR!!\nSomething went wrong and I cannot continue.\nPress Ctrl+Alt+Del to reboot."""
  631.     sh
  632.         fi
  633.     fi
  634. else
  635.     if [ -L /union/sbin/init ]; then
  636. echo """/sbin/init appears to be a symlink, assuming systemd-sysv is installed"""
  637. echo """trying to switch to systemd now..."""
  638. cp -f /union/lib/systemd/systemd /bin
  639.         if [ $? -eq 0 ]; then
  640.     mkdir -p /union/mnt/live
  641. echo """using systemd..."""
  642.     pivot_root /union  /union/mnt/live
  643.     exec usr/sbin/chroot . /mnt/live/bin/systemd "$@" <dev/console >dev/console 2>&1
  644.         else
  645.     echo -e """!!ERROR!!\nSomething went wrong and I cannot continue.\nPress Ctrl+Alt+Del to reboot."""
  646.     sh  
  647.         fi
  648.     else
  649. cp -f /union/sbin/init /bin
  650.         if [ $? -eq 0 ]; then
  651.     mkdir -p /union/mnt/live
  652.     pivot_root /union  /union/mnt/live
  653.     exec usr/sbin/chroot . /mnt/live/bin/init "$@" <dev/console >dev/console 2>&1
  654.         else
  655.     echo -e """!!ERROR!!\nSomething went wrong and I cannot continue.\nPress Ctrl+Alt+Del to reboot."""
  656.     sh
  657.         fi
  658.     fi
  659. fi
  660.  
  661.  
  662.  
  663.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement