User talk:Vit r

Main aim is to get: - ro /bin,/sbin,/lib while they are on rw root-p7n - rw /bin,/sbin,/lib in a simple way when needed - run lilo in a simple way

RO_PATH.sh-script is designed for ro /bin,/sbin,/lib


 * 1) ! The beginning of RO_PATH.sh
 * 2) !/bin/sh


 * 1) Copyright (C) 2010 Vit Rosin
 * 2) License: GNU GENERAL PUBLIC LICENSE Version 2, June 1991


 * 1) ! Testing release ver-0.0.2-2010-07-30
 * 1) ! Testing release ver-0.0.2-2010-07-30


 * 1) ! Copy, uncomment and run next few lines to clarify the situation
 * 2) rwtest="__writetest-$(date +%Y.%m.%d-%H+%M+%S)__"
 * 3) if chmod 555 /bin/ && touch /bin/$rwtest; then
 * 4)    rm /bin/$rwtest; echo -e "\n\n THERE IS NO NEED TO READ MORE! \n\n"
 * 5)    chmod 755 /bin/
 * fi


 * 1) ! Main aim is to get:
 * 2) !        - ro /bin,/sbin,/lib while they are on rw root-p7n
 * 3) !        - rw /bin,/sbin,/lib in a simple way when needed
 * 4) !        - run lilo in a simple way
 * 5) ! From LiveCD(or other OS) when /usr/* are on ro-p7n:
 * 6) ! 'cd /mnt/root-p7n'
 * 7) ! 'mkdir -p usr/RO/ boot/RO/'
 * 8) ! 'mv bin boot/RO/'
 * 9) ! 'ln -s ../../boot/RO/bin usr/RO/bin' # lrwxrwxrwx 1 root root ... usr/RO/bin -> ../../boot/RO/bin
 * 10) ! 'ln -s usr/RO/bin bin' # lrwxrwxrwx 1 root root ... bin -> usr/RO/bin/
 * 11) !    /mnt/root-p7n/usr/RO/-links provide access to boot/RO/*
 * 12) !    at boot-time(when only ' / ' is mounted)
 * 13) ! 'cp -a /mnt/root-p7n/usr/RO/ /mnt/usr-p7n/'
 * 14) !    /mnt/usr-p7n/RO/-links provide access to boot/RO/*
 * 15) !    at run-time(when '/usr' is mounted)
 * 16) ! >> rc.local:
 * 17) ! mount --bind -o ro /boot/RO /usr/RO
 * 18) ! mount -o ro,remount /usr/RO/
 * 19) ! mount -o ro,remount /usr/
 * 20) ! # Now /bin/* should be at run-time ro
 * 1) ! mount --bind -o ro /boot/RO /usr/RO
 * 2) ! mount -o ro,remount /usr/RO/
 * 3) ! mount -o ro,remount /usr/
 * 4) ! # Now /bin/* should be at run-time ro
 * 1) ! # Now /bin/* should be at run-time ro


 * 1) ! So if You are still reading let's start:
 * 2) ! Provide working mini-test-OS with at least two p7ns:
 * 3) ! 1. rw p7n(called here root-p7n)
 * 4) ! /boot,/etc,/bin,/lib,/sbin,...
 * 5) ! Important: if /boot/ is on other p7n, then copy /boot/ to root-p7n
 * 6) !           and comment the corresponding line in /etc/fstab.
 * 7) ! 2. ro p7n(called here usr-p7n)
 * 8) ! Only /usr/* (and other ro-dirs except /boot/) can reside on usr-p7n.
 * 1) !           and comment the corresponding line in /etc/fstab.
 * 2) ! 2. ro p7n(called here usr-p7n)
 * 3) ! Only /usr/* (and other ro-dirs except /boot/) can reside on usr-p7n.
 * 1) ! Only /usr/* (and other ro-dirs except /boot/) can reside on usr-p7n.


 * 1) ! Note: /home,/root,/tmp,/var,... can reside on root-p7n or elsewhere except usr-p7n.
 * 2) ! Warning: there should be no such files: boot/RO/ usr/RO/(they will be deleted).
 * 1) ! Warning: there should be no such files: boot/RO/ usr/RO/(they will be deleted).


 * 1) ! Then reboot to other OS or LiveCD(this is less preferable)
 * 2) ! and execute this script(called here RO_PATH.sh):
 * 3) !   ~# './RO_PATH.sh sda2 sdb4' (sda2 here is root-p7n, sdb4 here is usr-p7n)
 * 4) ! _OR_:
 * 5) !   ~# './RO_PATH.sh' # You will be asked to type them
 * 6) ! On success reboot to mini-test-OS
 * 1) ! On success reboot to mini-test-OS


 * 1) ! This script is looking only for two p7ns:
 * 2) !       - root-p7n
 * 3) !       - usr-p7n


 * 1) ! Important: this script is run only once!
 * 2) !           To run it once more:
 * 3) !   ~# rm  /mnt/root-p7n/{$DIRS}
 * 4) !   ~# mv  /mnt/root-p7n/boot/RO/{$DIRS} /mnt/root-p7n/
 * 5) !   ~# run script

EXiT {   echo -e "\n $0:$LINENO: seems fault: LINENO='$1'" echo -e "\n '$2' \n" echo -e " press  to exit\n" read oops exit }

un_mount {   dir="$1" if grep " $dir " /proc/mounts; then umount $dir || EXiT "$LINENO" "first umount $dir" if grep " $dir " /proc/mounts; then EXiT "$LINENO" "umount $dir unlikeky to happen" fi   fi }

mount_dir {   DiR="$1" if [ -d $DiR ]; then un_mount $DiR else mkdir -p $DiR || EXiT "$LINENO" "mkdir -p \"$DiR\"" fi   MOUNTED=; while [ ! $MOUNTED ] do     echo -e "\n type device  without /dev/, ie:" echo -ne " sdb3\n " read device mount /dev/$(echo $device) $DiR && MOUNTED=1 done }

checkings { cd $USR [ ! -d $USR/share ] && EXiT "$LINENO" "[ ! -d $USR/share ]"

cd $ROOT [ -L bin ] && EXiT "$LINENO" "[ -L bin ]" [ ! -d bin ] && EXiT "$LINENO" "[ ! -d bin ]" [ ! -d boot ] && EXiT "$LINENO" "[ ! -d boot ]" [ ! -d lib ] && EXiT "$LINENO" "[ ! -d lib ]" [ ! -d sbin ] && EXiT "$LINENO" "[ ! -d sbin ]"

rm -rf $ROOT/boot/RO/ $ROOT/usr/RO/ $USR/RO/ }

set -e

ROOT="/mnt/root-p7n" USR="/mnt/usr-p7n" if [ "$#" = "2" ]; then [ "$1" = "$2" ] && EXiT "$LINENO" "[ \"/dev/$1\" == \"/dev/$2\" ]" un_mount $ROOT mount "/dev/$1" $ROOT || EXiT "$LINENO" "mount \"/dev/$1\" $ROOT" un_mount $USR mount "/dev/$2" $USR || EXiT "$LINENO" "mount \"/dev/$1\" $USR" else echo -e "\n to cancel Ctrl+C or:\n type ROOT_dev without /dev/, ie:" mount_dir "$ROOT" mount_dir "$USR" fi

checkings

cd $ROOT/ mkdir -p usr/RO/ boot/RO/boot/ DIRS="bin sbin lib" # etc for DIR in $DIRS do ln -s ../../boot/RO/$DIR usr/RO/$DIR || EXiT "$LINENO" "ln -s ../../boot/RO/$DIR usr/RO/$DIR" done

cp -a $ROOT/usr/RO/ $USR/ umount $USR # Done with usr-p7n rmdir $USR

for DIR in $DIRS do mv $DIR boot/RO/ || EXiT "$LINENO" "mv $DIR boot/RO/" touch boot/RO/$DIR/._its_boot-RO-$DIR ln -s usr/RO/$DIR $DIR || EXiT "$LINENO" "ln -s usr/RO/$DIR $DIR" done

touch boot/RO/boot/it_is_empty_dir touch boot/RO/boot/to_hide_rw-boot-files

cd $ROOT/etc/rc.d/ cat >> rc.local << EOF

/bin/sync sleep 1

if /bin/mount --bind -o ro /boot/RO /usr/RO 1>/dev/null; then /bin/mount -o ro,remount /usr/RO/ /bin/mount -o ro,remount /usr/ /bin/sync # Better to keep(don't comment) this '/bin/sync' /bin/mount --bind -o ro /usr/RO/boot/ /boot/ /bin/sync else echo -e " rc.local:\$LINENO: mount --bind ... failed" fi EOF

umount $ROOT # Done with root-p7n rmdir $ROOT


 * 1) ! The end of RO_PATH.sh


 * 1) ! for OS-modifyings:
 * 2) ! disconnect inet
 * 3) ! /bin/umount /boot
 * 4) ! /bin/mount -o rw,remount /usr/
 * 5) ! /bin/mount -o rw,remount /usr/RO/
 * 6) !        modules_install, etc
 * 7) !        install-remove pkgs, etc
 * 8) ! /bin/mount -o ro,remount /usr/RO/
 * 9) ! /bin/mount -o ro,remount /usr/
 * 10) ! /bin/sync # Better to have this '/bin/sync'-line
 * 11) ! /bin/mount --bind -o ro /usr/RO/boot/ /boot/
 * 12) ! /bin/sync
 * 1) ! /bin/mount -o ro,remount /usr/RO/
 * 2) ! /bin/mount -o ro,remount /usr/
 * 3) ! /bin/sync # Better to have this '/bin/sync'-line
 * 4) ! /bin/mount --bind -o ro /usr/RO/boot/ /boot/
 * 5) ! /bin/sync
 * 1) ! /bin/mount --bind -o ro /usr/RO/boot/ /boot/
 * 2) ! /bin/sync


 * 1) ! for lilo:
 * 2) ! disconnect inet
 * 3) ! /bin/umount /boot
 * 4) ! /sbin/lilo
 * 5) ! /bin/mount --bind -o ro /usr/RO/boot/ /boot/
 * 1) ! /sbin/lilo
 * 2) ! /bin/mount --bind -o ro /usr/RO/boot/ /boot/


 * 1) ! Actually it is almost not tested because of may be rare interest
 * 2) ! For example:
 * 3) !       - is there need to include /etc also?
 * 4) !       - is there need to make it run more then once?
 * 5) ! And so on..
 * 1) ! And so on..


 * 1) ! That's seems all for test starting


 * 1) ! Excuses for mistakes, weak comments and everything else


 * 1) ! 2010-07-30


 * 1) ! Vit