Pagina 2 di 3

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: gio 19 mar 2009, 16:41
da zoros
Offtopic: Bene Mario, aspettiamo allora i risultati del tuo "write-rewrite usb-stick crash test" !

Ciao tigerwalk,
mi pare che usi già una Slackware su USB-disk, probabilmente un vero HD esterno ... magari puoi postare qui qualche tua idea/esperienza in merito ...

attualmente sono un po' "incavolato" con il riconoscimento BIOS di queste pennine usb: in alcuni casi basta inserire la pennina e il boot è subito abilitato, in altri tocca proprio entrare in Setup e scambiare l'ordine degli HDD, in altri bisogna premere F8, in altri F11, ecc. ... poi la questione della prima fase del boot da USB: alcune schede madri sono lentissime nel caricare il kernel, anche con l'opzione "compact" attiva (provato anche con altri boot manager, sembra proprio un questione di BIOS: probabilmente viene letto un settore alla volta via INT13h) ...

ancora una domandina in generale ... attualmente ho portato in RAM:
/home
/root
/tmp
/var/tmp
/var/run
/var/log
in tutto sono circa 70M di cui 40M di dati (/home e /root), il sistema risponde velocemente, solo all'inizio della sessione kde e nella formazione dei menù K si nota un fastidioso rallentamento, segno che kde scrive anche in qualche altra directory ... qualche idea in merito ?

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: gio 19 mar 2009, 20:38
da Mario Vanoni
Mario Vanoni ha scritto:
zoros ha scritto: @Mario
ho capito, adotti la tecnica della manutenzione programmata come fanno le imprese sostituendo l'hw a scadenza regolare ... è sicuramente un approccio valido, "costosetto" però per un privato ...
[OT]
USB stick VERBATIM 512MB
- usato forse 100 volte
- riformatato con mkfs.ext + e2fsck, no errors
- scriverci 459MB non nello stesso ordine, cancellare tutto
- dopo circa 2000 cicli raggiunti 397MB "no space left"
- riformatato con mkfs.ext + e2fsck, no errors
- stessa procedura, durera` 4-5 giorni, aspettiamo ...
[/OT]
[OT]
Chiusura del test, dopo altri 131 cicli:
stavolta raggiunti 450MB "no space left"
512'000'000 / 1024 / 1024 = 487MiB
USB stick non piu` affidabile, pattumiera!

Anche se con Lifetime Warranty, comprato 07.02.2007.

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: gio 19 mar 2009, 22:48
da zoros
Non la metto in OT perché attinente al problema disco-usb:

Mario, ho visto i test, solo che sinceramente non riesco ad interpretare i dati che riporti ... non era anche significativo fare una scrittura "grezza" con il dd e vedere se esce qualche "I/O error" ? ... per esempio io non so bene se e2fsck marca i settori guasti ed eventualmente in che modo ...

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: ven 20 mar 2009, 19:34
da tigerwalk
ho seguito le tue indicazioni ma al boot non trova il signature (che ho creato in /etc). C'è qualche accorgimento da adottare nella creazione di tale file?

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: ven 20 mar 2009, 21:39
da zoros
tigerwalk ha scritto:ho seguito le tue indicazioni ma al boot non trova il signature (che ho creato in /etc). C'è qualche accorgimento da adottare nella creazione di tale file?
Ciao,
non segnali quale kernel stai usando ... immagino comunque che tu stia facendo le prove con un kernel custom che già ti funzionava via usb-disk ... come già evidenziato, il kernel originale 12.2 non ha il supporto usb-storage built-in (e/o altro) e quindi non riconosce i dischi usb ...

init della ramdisk, se non può fare il chroot, apre una console e lì dovresti avere tutti i comandi necessari per risalire al problema ... per esempio prova "fdisk -l" per sapere se il disco usb è stato riconosciuto dal kernel ... dovrebbe funzionare anche "dmesg", ecc.

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: ven 20 mar 2009, 21:51
da Mario Vanoni
zoros ha scritto:Non la metto in OT perché attinente al problema disco-usb:

Mario, ho visto i test, solo che sinceramente non riesco ad interpretare i dati che riporti ... non era anche significativo fare una scrittura "grezza" con il dd e vedere se esce qualche "I/O error" ? ... per esempio io non so bene se e2fsck marca i settori guasti ed eventualmente in che modo ...
[OT]
I test dimostrano che gli USB sticks
sono stati creati con il FS FAT in mente.

Copiando a caso files da 10B a 5GB,
controllando il numero della inode,
vengono sparpagliati a caso sul medium,
stranamente come se fosse diviso in settori,
inodes sui 30'000 poi sui 100'000 ecc.

Sembra che sia suddiviso in settori predefiniti.

Riformattato la quarta volta in modo cattivo,
mkfs.ext2 -b 4096 -i 4096 -c -c -m 0 /dev/s...,
con e2fsck che dice 0.0% non-contiguous,
creando files di 13B fino a fine spazio usabile,
scrive le 125'696 inodes in ordine corretto,
poi cancella tutti i files e ricomincia.
27 cicli compiuti identici, aspettiamo ...

Non sono stati creati con UNIX in mente!

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: sab 21 mar 2009, 16:23
da Mario Vanoni
[OT]
Riformattato la quinta volta in modo cattivo,
mkfs.ext2 -b 4096 -i 4096 -c -c -m 0 /dev/s...,
e2fsck -y -f dice 0.0% non-contiguous,
creando un file unico fino alla fine dello spazio disponibile,
programma in C, non shell,
e2fsck dice 8.3% non-contiguous (sic!), un file, una sola volta,
che organizzazione del medium!

Prossimi test con un USB stick di 16GB.
Ci risentiamo tra un mese ...

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: sab 21 mar 2009, 23:59
da zoros
Siccome leggere non è facile come scrivere ho riletto l'articolo di spina in merito al boot da pennina usb ... nell'articolo si parla dell'utilizzo della busybox precompilata del pacchetto mkinitrd che si trova in /usr/share/mkinitrd/initrd-tree.tar.gz ... siccome non avevo aggiornato quel pacchetto, avevo fatto delle prove con la versione "mkinitrd-1.1.2-i486-3" che contiene una busybox incompleta di certi applet simile a quella usata nel DVD di installazione della 12.2 (chissà perché Pat continua ad usare la vecchia versione ?) ...

aggiornato a mkinitrd-1.3.3-i486-1 (con busybox v1.7.2, statica e completa), ripeto le prove con il risultato che il kernel "vmlinuz-huge-smp-2.6.27.7-smp" rileva dischi usb e pennine senza problemi (eppure con l'altra busybox non rilevava i dischi ... mah) ...

ecco quindi un nuovo script che crea ora una "ramusb.igz" tutta Slackware e rileva anche delle options aggiuntive come root=... rootfstype=...

Codice: Seleziona tutto

#!/bin/sh
# *** Makeramusb-slack *** copyleft (!C) FZ

#Thanks:
#jootamam: http://jootamam.net/howto-initramfs-image.htm
#spina: http://www.slacky.eu/wikislack/index.php?title=Slackware_su_pennina_USB

echo "Removing previous structure and files ..."
#--------------------------------------------------------
rm -Rf work
rm -Rf initrd-tree

echo "Getting mkinitrd busybox ..."
#--------------------------------------------------------
if [ ! -f ./initrd-tree.tar.gz ] ; then
 cp -f /usr/share/mkinitrd/initrd-tree.tar.gz .
fi

if [ -f ./initrd-tree.tar.gz ] ; then
 mkdir -p initrd-tree
 tar -C initrd-tree -xzplf initrd-tree.tar.gz
else
 echo  "
./initrd-tree.tar.gz not found
/usr/share/mkinitrd/initrd-tree.tar.gz not found

get and install mkinitrd package ... exit
"
 exit
fi

echo "Creating the folder structure ..."
#--------------------------------------------------------
mkdir -p work/initramfs/{bin,sbin,etc,proc,sys,newroot,usr,usr/bin,usr/sbin}

cp -f ./initrd-tree/bin/busybox ./work/initramfs/bin/

cd work
touch initramfs/etc/mdev.conf

chmod +x initramfs/bin/busybox
ln -s busybox initramfs/bin/sh

echo "Creating a init script"
#--------------------------------------------------------
echo '#!/bin/sh

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

#Mount things needed by this script
busybox mount -t proc proc /proc
busybox mount -t sysfs sysfs /sys

#Create all the symlinks to /bin/busybox
/bin/busybox --install -s

touch /etc/mtab

#Disable kernel messages from popping onto the screen
echo 0 > /proc/sys/kernel/printk

#insmod /kernel_modules/usb-storage.ko

#Clear the screen
clear

echo
echo
echo "------------------------------------"
echo "     **** USB Boot v 0.1 ****       "
echo "------------------------------------"
echo

#Create device nodes
mknod /dev/null c 1 3
mknod /dev/tty c 5 0

echo /bin/mdev > /proc/sys/kernel/hotplug

#Scan for devices
mdev -s

#Defaults
init="/sbin/init"
root="/dev/sda1"

#Get USB-disk SIGNATURE
USB_LABEL=
COMMAND_LINE=`cat /proc/cmdline`

R_RW_OPT="-r"
FS_TYPE=""
ROOTDEV=""

#Parse 12 option parameters
#------------------------------------------------

for i in 1 2 3 4 5 6 7 8 9 10 11 12
do

 OPTION=`echo "$COMMAND_LINE" | cut -d" " -f$i`
 PARAM=`echo "$OPTION" | cut -d"=" -f1`
 VALUE=`echo "$OPTION" | cut -d"=" -f2`

 #Test ro|rw mount option
 case "$OPTION" in
  "ro" | "read-only")  R_RW_OPT="-r";;
  "rw" | "read-write") R_RW_OPT="-w";;
 esac

 #Test fs type
 if [ "a$PARAM" = "arootfstype" ] ; then
  FS_TYPE="-t $VALUE"
 fi

 #Test root device
 if [ "a$PARAM" = "aroot" ] ; then
  ROOTDEV="$VALUE"
 fi

 if [ "a$PARAM" = "aUSB_DISK_SIGNATURE" ] ; then
  USB_LABEL=$VALUE
 fi
done

export R_RW_OPT=$R_RW_OPT
export FS_TYPE=$FS_TYPE
export ROOTDEV=$ROOTDEV

#Search for disk signature
#------------------------------------------------

if [ "a$USB_LABEL" != "a" ] ; then

 #Try to mount USB-disk
 echo -n "Searching disk signature: $USB_LABEL "

 n=0
 export IFS=`echo -ne " \t\n"`

 #Repeat test 10 times
 while [ $n -le 9 ]
 do
  #Rescan for new devices
  mdev -s

  #Try to mount all sd devices
  #---------------------------------------------

  ls -1 /dev/sd* 2> /dev/null |
  while
   read TRY_DISK
   do
    mount $R_RW_OPT $FS_TYPE $TRY_DISK /newroot 1> /dev/null 2> /dev/null
    if [ -f /newroot/etc/$USB_LABEL ] ; then
     break
    fi
    umount $TRY_DISK 2> /dev/null
  done
  #---------------------------------------------

  if [ -f /newroot/etc/$USB_LABEL ] ; then
   break
  fi

  sleep 1
  let n=$n+1
  echo -n "."
 done

 echo " done."

 IS_ROOT_MOUNTED=`mount | grep /newroot`

 if [ "a$IS_ROOT_MOUNTED" != "a" ] ; then
  echo "$USB_LABEL --> $IS_ROOT_MOUNTED"
 else
  echo "Error: disk signature <<$USB_LABEL>> not found !!!"
 fi

else
  echo "Warning: USB_DISK_SIGNATURE not in command line ..."

fi

#If nothing mounted try root= parameter
#------------------------------------------------
if [ "a$IS_ROOT_MOUNTED" = "a" ] && [ "a$ROOTDEV" != "a" ] ; then
 echo "Try to mount append device root=$ROOTDEV ..."
 mount $R_RW_OPT $FS_TYPE $ROOTDEV /newroot 1> /dev/null 2> /dev/null
fi

IS_ROOT_MOUNTED=`mount | grep /newroot`

#If nothing mounted ... ask
#------------------------------------------------

if [ "a$IS_ROOT_MOUNTED" = "a" ] ; then
 echo "Error: root device not mounted ..."
 echo -n "give me another device to try (ex: /dev/sda1) : "
 read ALT_DEVICE

 mount $R_RW_OPT $FS_TYPE $ALT_DEVICE /newroot 1> /dev/null 2> /dev/null
fi

#Check if $init exists and is executable
#------------------------------------------------

if [[ -x "/newroot/${init}" ]] ; then
 #Unmount all other mounts so that the ram used by
 #the initramfs can be cleared after switch_root
 umount /sys /proc

 #Switch to the new root and execute init
 exec switch_root /newroot "${init}"
fi

#This will only be run if the exec above failed
echo "Failed to switch_root, dropping to a shell"
exec sh' > initramfs/init

chmod +x initramfs/init

echo "Creating the .cpio and .igz ..."
#--------------------------------------------------------
cd initramfs
find . | cpio -H newc -o > ../ramusb.cpio
cd ..
cat ramusb.cpio | gzip > ramusb.igz

echo "Done."
per cui ora lilo.conf può essere:

Codice: Seleziona tutto

# Start LILO global section

boot = /dev/sdc   # hda,sda=MBR or hda1,sda1=bootrecord

compact        # ha sempre funzionato
prompt
large-memory   # non servirebbe in questo caso
timeout = 50
vga = 788

# End LILO global section

# Linux bootable partition config begins

image = /boot/vmlinuz-huge-smp-2.6.27.7-smp
  label = UZBlinux
  initrd=/boot/ramusb.igz
  read-only
  append = "USB_DISK_SIGNATURE=mySlack12.2"
Nota: non distanziare il segno di uguale nelle options altrimenti lo script init non riconosce i parametri ...

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: mar 24 mar 2009, 0:03
da zoros
Continuo a portare avanti questo argomento, perché mi sta dando delle soddisfazioni ... la Slackware su pennina ora mi sembra molto reattiva e veloce, tutto sommato le modifiche da fare non sono molte e lo script per automatizzare il tutto potrebbe essere relativamente semplice ... riporto le ultime modifiche:

rc.S (subito dopo il mount -a)

Codice: Seleziona tutto

##-------------
echoc "  Mount working disks (/tmp /root /home)" green
mount -t tmpfs none /ramdisk

echoc "  Copy in tmpfs RAMDISK /root /home" green

mkdir -p   /ramdisk/tmp
mkdir -p   /ramdisk/var/tmp
mkdir -p   /ramdisk/var/run
mkdir -p   /ramdisk/var/log-usb
mkdir -p   /ramdisk/var/lib-usb

mkdir -p   /ramdisk/root-usb
mkdir -p   /ramdisk/home-usb
chmod 4777 /ramdisk/tmp
chmod 4777 /ramdisk/var/tmp

echoc "Syncing USB-Disk to /ramdisk/root ... wait please ..." magenta
rsync -arz --delete --force /root-usb/ /ramdisk/root-usb

echoc "Syncing USB-Disk to /ramdisk/home ... wait please ..." yellow
rsync -arz --delete --force /home-usb/ /ramdisk/home-usb

echoc "Syncing USB-Disk to /ramdisk/var ...  wait please ..." blue
rsync -arz --delete --force /var/log-usb/ /ramdisk/var/log-usb
rsync -arz --delete --force /var/lib-usb/ /ramdisk/var/lib-usb
rc.6 (subito dopo il "Turning off swap.")

Codice: Seleziona tutto

echoc "Syncing /ramdisk/root to USB-Disk ... wait please ..." magenta
rsync -arz --delete --force /ramdisk/root-usb/ /root-usb

echoc "Syncing /ramdisk/home to USB-Disk ... wait please ..." yellow
rsync -arz --delete --force /ramdisk/home-usb/ /home-usb

echoc "Syncing /ramdisk/var to USB-Disk ...  wait please ..." blue
rsync -arz --delete --force /ramdisk/var/log-usb/ /var/log-usb
rsync -arz --delete --force /ramdisk/var/lib-usb/ /var/lib-usb
ora ho una pennina da 16G con tre partizioni, la prima con NTFS (l'unica vista da vindows) e due ext2, una con Slackware ed una più piccola per una recovery-tools ... non male direi

Codice: Seleziona tutto

Disk /dev/sdb: 16.1 GB, 16173236224 bytes
64 heads, 32 sectors/track, 15424 cylinders
Units = cilindri of 2048 * 512 = 1048576 bytes

Dispositivo Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        3816     3907568    7  HPFS/NTFS
/dev/sdb2   *        3817       14784    11231232   83  Linux
/dev/sdb3           14785       15424      655360   83  Linux
le mie conclusioni sono che per avere la Slack su pennina non è indispensabile ricorrere ad una distro dedicata allo scopo, la versatilità di Slackware si rivela anche in questo caso formidabile ...

[OT] nella mia esposizione ci sono state alcune imprecisioni e degli errori, per esempio il kernel-huge rileva perfettamente le pennine e non occorre compilare un nuovo kernel ... sono un po' sorpreso per il fatto che nessuno abbia evidenziato l'errore ... mica mi arrabbiavo :-k

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: mer 25 mar 2009, 17:13
da tigerwalk
Ciao zoros,
Come ho avuto modo di dirti, avviavo già slackware da disco esterno oppure da pennina con i kernel-huge-smp, utilizzando il file initrd.gz generato seguendo le indicazioni del wiki di spina su "slackware su penna usb".
Adesso utilizzo il tuo metodo (ramusb.igz) con il signature file e l'avvio è davvero molto rapido. La lentezza del sistema su pennetta, viene senz'altro migliorato dall'utilizzo del ramdisk. A questo punto però, sorge un problema: tutto va bene per la home e tmp in ramdisk ma, se metto le directory /var/xxx in ramdisk, alcuni applicativi (es wicd) non funzionano e ricevo errori di dbus. A questo punto o utilizzo il sistema con solo la /root e la /home e va tutto bene (ma il sistema è alquanto lento), oppure metto in ramdisk anche /var/xxx e qualcosa non funziona, anche se la velocità aumenta notevolmente!
Consigli su come utilizzare la /var in ramdisk senza problemi?
p.s.: slackware current, kernel-huge-smp-2.6.28.7, penna usb da 8 giga, unica partizione in ext2.

Cari saluti!

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: mer 25 mar 2009, 20:36
da zoros
Hi tigerwalk,
diciamo anche che tu sei in current, mentre io sto facendo le ultime prove sul mio "ibrido" che è sincronizzato alla 12.2 come glibc (ma mi serviva questo) ... comunque non credo sia questo il problema, piuttosto qualche piccolo ritocco da fare manualmente ... queste in sintesi le parti che appaiono modificate nel mio filesystem:

Codice: Seleziona tutto

ls -l /
...
lrwxrwxrwx  1 root root    17 16 mar 21:13 home -> /ramdisk/home-usb
drwxr-xr-x  5 root root  4096 16 mar 22:21 home-usb
drwxr-xr-x  2 root root  4096 16 mar 20:55 ramdisk
lrwxrwxrwx  1 root root    17 16 mar 21:13 root -> /ramdisk/root-usb
drwx------ 45 root root  4096 25 mar 10:50 root-usb
lrwxrwxrwx  1 root root    12 16 mar 21:11 tmp -> /ramdisk/tmp
...

Codice: Seleziona tutto

ls -l /var
...
lrwxrwxrwx  1 root root   20 23 mar 20:58 lib -> /ramdisk/var/lib-usb
drwxr-xr-x 26 root root 4096 12 ott  2007 lib-usb
lrwxrwxrwx  1 root root   20 17 mar 17:05 log -> /ramdisk/var/log-usb
drwxr-xr-x 18 root root 4096 25 mar 10:39 log-usb
lrwxrwxrwx  1 root root   16 17 mar 16:26 tmp -> /ramdisk/var/tmp
...
noterai che alcune directory sono state rinominate e le due "tmp" completamente rimosse ...

ci sono anche delle "stranezze" nelle date dei vari files dovute ad alcuni ripristini che ho dovuto fare ... basta dimenticarsi una "/" finale in un path ed rsync non fa quello che ti aspetti (per esempio invece di sincronizzare in uscita la /var/usb-lib mi ritrovavo un duplicato tipo /var/usb-lib/usb-lib ... quindi intervento manuale) ...

adesso hai la situazione delle mie directory e gli esatti comandi che sto usando per la sincronizzazione (sono quelli del mio precedente post) ... confido nei tuoi prossimi test per capire se il metodo è corretto o va perfezionato ...
ho anche installato wicd e mi ritrovo una directory /var/log-usb/wicd, solo che non mi funziona perché non ho aggiornato tutte le librerie, quindi non ti so dire di più al momento ...

alla prossima ... intanto grazie

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: gio 26 mar 2009, 19:17
da tigerwalk
Salve zoros,
ho rifatto il procedimento con calma e stavolta funziona tutto bene. Noto un certo rallentamento al login ed alla partenza di X fino al caricamento del desktop, insomma non ha la reattività di una Slax ma tutto sommato è accettabile. Notevole la velocità del boot, infatti stavo pensando di usare ramusb.igz col signature file e le modifiche a lilo e fstab sulla current che ho sull'hd esterno (senza usare ramdisk perchè la velocità è identica a quella di un hd interno).
Saluti e complimenti!

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: gio 26 mar 2009, 21:57
da zoros
tigerwalk ha scritto:Salve zoros,
ho rifatto il procedimento con calma e stavolta funziona tutto bene. Noto un certo rallentamento al login ed alla partenza di X fino al caricamento del desktop, insomma non ha la reattività di una Slax ma tutto sommato è accettabile. Notevole la velocità del boot, infatti stavo pensando di usare ramusb.igz col signature file e le modifiche a lilo e fstab sulla current che ho sull'hd esterno (senza usare ramdisk perchè la velocità è identica a quella di un hd interno).
Saluti e complimenti!
Ottimo lavoro tigerwalk, grazie :thumbright:
questo feedback mi conferma che c'è un problema di rallentamento al login, problema che ho notato anch'io, ma solo su alcune macchine e con una certa casualità (cioè non si manifesta sempre, in prevalenza il login è veloce quanto da HD) ... mi sembra comunque che con le ultime modifiche la maggior parte dei file "attivi in rw" sia stato portato in RAM ... forse c'è qualche altro "inghippo" da risolvere ... penso ad esempio a qualche problemino nella risoluzione IP<->hostname, cosa che talvolta rallenta l'avvio di X e del desktop manager (da pennina, chiaramente, stiamo usando il DHCP, quindi ...) ... un'ipotesi ...

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: mar 14 apr 2009, 1:11
da zoros
Come ho scritto da qualche altra parte, pensavo di incorporare la initramfs direttamente nel kernel ... visto che lo scriptino di cui sopra crea anche l'archivio .cpio ho provato a vedere se era effettivamente compatibile con il kernel ... ho fatto quindi delle prove con la 2.6.29.1 ... la procedura:
ho eseguito lo scriptino Makeramusb-slack in una directory /usr/src/initramfs/ creata appositamente ... questo mi ha creato l'archivio non compresso work/ramusb.cpio ... poi in "make xconfig" --> General setup --> Initramfs source file(s): ho inserito il percorso completo a questo archivio .cpio ... il kernel era già precompilato ed i moduli installati ... il solo "make bzImage" mi ha creato quindi un nuovo kernel comprensivo di ramdisk ...

con sorpresa il comportamento al boot è stato diverso dall'avvio con initramfs separata ... in questo caso il kernel deve trovare già pronta una /dev con alcuni devices (la console e tty) ... ecco quindi una revisione dello script, peccato che questa versione debba girare da root per il mknod dei dispositivi:

Codice: Seleziona tutto

#!/bin/sh
# *** Makeramusb-slack *** copyleft (!C) FZ

echo "Removing previous structure and files ..."
#--------------------------------------------------------
rm -Rf work
rm -Rf initrd-tree

echo "Getting mkinitrd busybox ..."
#--------------------------------------------------------
if [ ! -f ./initrd-tree.tar.gz ] ; then
 cp -f /usr/share/mkinitrd/initrd-tree.tar.gz .
fi

if [ -f ./initrd-tree.tar.gz ] ; then
 mkdir -p initrd-tree
 tar -C initrd-tree -xzplf initrd-tree.tar.gz
else
 echo  "
./initrd-tree.tar.gz not found
/usr/share/mkinitrd/initrd-tree.tar.gz not found

get and install mkinitrd package ... exit
"
 exit
fi

echo "Creating the folder structure ..."
#--------------------------------------------------------
mkdir -p work/initramfs/{dev,bin,sbin,etc,proc,sys,newroot,usr,usr/bin,usr/sbin}

#Create device nodes
mknod work/initramfs/dev/null c 1 3
mknod work/initramfs/dev/tty c 5 0
mknod work/initramfs/dev/console c 5 1

cp -f ./initrd-tree/bin/busybox ./work/initramfs/bin/

cd work
touch initramfs/etc/mdev.conf

chmod +x initramfs/bin/busybox
ln -s busybox initramfs/bin/sh

echo "Creating a init script"
#--------------------------------------------------------
echo '#!/bin/sh

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

#Mount things needed by this script
busybox mount -t proc proc /proc
busybox mount -t sysfs sysfs /sys

#Create all the symlinks to /bin/busybox
/bin/busybox --install -s

touch /etc/mtab

#Disable kernel messages from popping onto the screen
echo 0 > /proc/sys/kernel/printk

#Clear the screen
clear

echo
echo
echo "------------------------------------"
echo "     **** USB Boot v 0.2 ****       "
echo "------------------------------------"
echo

echo /bin/mdev > /proc/sys/kernel/hotplug

#Scan for devices
mdev -s

#Defaults
init="/sbin/init"
root="/dev/sda1"

#Get USB-disk SIGNATURE
USB_LABEL=
COMMAND_LINE=`cat /proc/cmdline`

R_RW_OPT="-r"
FS_TYPE=""
ROOTDEV=""

#Parse 12 option parameters
#------------------------------------------------

for i in 1 2 3 4 5 6 7 8 9 10 11 12
do

 OPTION=`echo "$COMMAND_LINE" | cut -d" " -f$i`
 PARAM=`echo "$OPTION" | cut -d"=" -f1`
 VALUE=`echo "$OPTION" | cut -d"=" -f2`

 #Test ro|rw mount option
 case "$OPTION" in
  "ro" | "read-only")  R_RW_OPT="-r";;
  "rw" | "read-write") R_RW_OPT="-w";;
 esac

 #Test fs type
 if [ "a$PARAM" = "arootfstype" ] ; then
  FS_TYPE="-t $VALUE"
 fi

 #Test root device
 if [ "a$PARAM" = "aroot" ] ; then
  ROOTDEV="$VALUE"
 fi

 if [ "a$PARAM" = "aUSB_DISK_SIGNATURE" ] ; then
  USB_LABEL=$VALUE
 fi
done

export R_RW_OPT=$R_RW_OPT
export FS_TYPE=$FS_TYPE
export ROOTDEV=$ROOTDEV

#Search for disk signature
#------------------------------------------------

if [ "a$USB_LABEL" != "a" ] ; then

 #Try to mount USB-disk
 echo -n "Searching disk signature: $USB_LABEL "

 n=0
 export IFS=`echo -ne " \t\n"`

 #Repeat test 10 times
 while [ $n -le 9 ]
 do
  #Rescan for new devices
  mdev -s

  #Try to mount all sd devices
  #---------------------------------------------

  ls -1 /dev/sd* 2> /dev/null |
  while
   read TRY_DISK
   do
    mount $R_RW_OPT $FS_TYPE $TRY_DISK /newroot 1> /dev/null 2> /dev/null
    if [ -f /newroot/etc/$USB_LABEL ] ; then
     break
    fi
    umount $TRY_DISK 2> /dev/null
  done
  #---------------------------------------------

  if [ -f /newroot/etc/$USB_LABEL ] ; then
   break
  fi

  sleep 1
  let n=$n+1
  echo -n "."
 done

 echo " done."

 IS_ROOT_MOUNTED=`mount | grep /newroot`

 if [ "a$IS_ROOT_MOUNTED" != "a" ] ; then
  echo "$USB_LABEL --> $IS_ROOT_MOUNTED"
 else
  echo "Error: disk signature <<$USB_LABEL>> not found !!!"
 fi

else
  echo "Warning: USB_DISK_SIGNATURE not in command line ..."

fi

#If nothing mounted try root= parameter
#------------------------------------------------
if [ "a$IS_ROOT_MOUNTED" = "a" ] && [ "a$ROOTDEV" != "a" ] ; then
 echo "Try to mount append device root=$ROOTDEV ..."
 mount $R_RW_OPT $FS_TYPE $ROOTDEV /newroot 1> /dev/null 2> /dev/null
fi

IS_ROOT_MOUNTED=`mount | grep /newroot`

#If nothing mounted ... ask
#------------------------------------------------

if [ "a$IS_ROOT_MOUNTED" = "a" ] ; then
 echo "Error: root device not mounted ..."
 echo -n "give me another device to try (ex: /dev/sda1) : "
 read ALT_DEVICE

 mount $R_RW_OPT $FS_TYPE $ALT_DEVICE /newroot 1> /dev/null 2> /dev/null
fi

#Check if $init exists and is executable
#------------------------------------------------

if [[ -x "/newroot/${init}" ]] ; then
 #Unmount all other mounts so that the ram used by
 #the initramfs can be cleared after switch_root
 umount /sys /proc

 #Switch to the new root and execute init
 exec switch_root /newroot "${init}"
fi

#This will only be run if the exec above failed
echo "Failed to switch_root, dropping to a shell"
exec sh' > initramfs/init

chmod +x initramfs/init

echo "Creating the .cpio and .igz ..."
#--------------------------------------------------------
cd initramfs
find . | cpio -H newc -o > ../ramusb.cpio
cd ..
cat ramusb.cpio | gzip > ramusb.igz

echo "Done."

Offtopic:
raffaele181188 ha scritto:
zoros ha scritto:Offtopic: a questo punto volevo mettere un link ma questo conteneva nell'url la string m_s_g (senza trattini) ... ma, niente da fare: m_s_g mi viene corretto in automatico come "messaggio" quindi il link non funziona ... ma può essere ? dove sbaglio ?
Offtopic:
Da nessuna parte... E' una feature per evitare la "scrittura tipo SMS"... Non so se e se sì come si può disabilitare...
Offtopic:

Immaginavo, infatti ho provato col Quote,Code ... stesso risultato ... però devo dire che molti siti utilizzano "m_s_g" per ritrovare un messaggio in un forum ... spero si possa impostare diversamente questa funzione per quanto riguarda l'URL ...

Re: Makeramusb: avviare da disco USB con kernel statico

Inviato: dom 19 apr 2009, 0:31
da zoros
Direi che ci siamo ! ... cioè mi sembra di avere finalmente una initramfs soddisfacente ... cerco di sintetizzare la logica di boot:
1) cerca il "Signature file" sui dischi HDs
2) se non lo trova lo cerca allora sui dischi SDs
3) se non trova niente tenta il boot sul dispositivo passato come root=
4) se tutto fallisce allora chiede
5) se anche chiedendo non va, apre un console (e non è detta l'ultima parola)

e se ha trovato un file "Signature" allora:
1) se è un file lo monta in loop e se dentro c'è un init lo avvia
2) se invece è una directory e dentro c'è un init allora avvia questo
3) se non è vero 1) o 2) allora tenta l'init alla radice ... se niente da fare allora passa a 4), 5)

Codice: Seleziona tutto

#!/bin/sh
# *** Makeramusb-slack *** copyleft (!C) FZ
# *** rev 0.4

echo "Removing previous structure and files ..."
#--------------------------------------------------------
rm -Rf work
rm -Rf initrd-tree

echo "Getting mkinitrd busybox ..."
#--------------------------------------------------------
if [ ! -f ./initrd-tree.tar.gz ] ; then
cp -f /usr/share/mkinitrd/initrd-tree.tar.gz .
fi

if [ -f ./initrd-tree.tar.gz ] ; then
mkdir -p initrd-tree
tar -C initrd-tree -xzplf initrd-tree.tar.gz
else
echo  "
./initrd-tree.tar.gz not found
/usr/share/mkinitrd/initrd-tree.tar.gz not found

get and install mkinitrd package ... exit
"
exit
fi

echo "Creating the folder structure ..."
#--------------------------------------------------------
mkdir -p work/initramfs/{dev,bin,sbin,etc,proc,sys,newroot,usr,usr/bin,usr/sbin}

#Create device nodes
mknod work/initramfs/dev/null c 1 3
mknod work/initramfs/dev/tty c 5 0
mknod work/initramfs/dev/console c 5 1

cp -f ./initrd-tree/bin/busybox ./work/initramfs/bin/

cd work
touch initramfs/etc/mdev.conf

chmod +x initramfs/bin/busybox
ln -s busybox initramfs/bin/sh

echo "Creating a init script"
#--------------------------------------------------------
echo '#!/bin/sh

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

#Mount things needed by this script
busybox mount -t proc proc /proc
busybox mount -t sysfs sysfs /sys

#Create all the symlinks to /bin/busybox
/bin/busybox --install -s

touch /etc/mtab

#Disable kernel messages from popping onto the screen
echo 0 > /proc/sys/kernel/printk

#Clear the screen
clear

echo
echo
echo "------------------------------------"
echo "     **** FaZo Boot v 0.4 ****      "
echo "------------------------------------"
echo

echo /bin/mdev > /proc/sys/kernel/hotplug

#Scan for devices
mdev -s

#Defaults
init="/sbin/init"
root="/dev/sda1"

HD_FOUND=

#Get USB-disk SIGNATURE
USB_LABEL=
COMMAND_LINE=`cat /proc/cmdline`

#adjust command line, remove white spaces, etc.
COMMAND_LINE=`echo $COMMAND_LINE | sed s/\s+//`
COMMAND_LINE=`echo $COMMAND_LINE | sed "s/ =/=/g"`
COMMAND_LINE=`echo $COMMAND_LINE | sed "s/= /=/g"`

R_RW_OPT="-r"
FS_TYPE=""
ROOTDEV=""

#Parse 12 option parameters
#------------------------------------------------

for i in 1 2 3 4 5 6 7 8 9 10 11 12
do

 OPTION=`echo "$COMMAND_LINE" | cut -d" " -f$i`
 PARAM=`echo "$OPTION" | cut -d"=" -f1`
 VALUE=`echo "$OPTION" | cut -d"=" -f2`

 #Test ro|rw mount option
 case "$OPTION" in
  "ro" | "read-only")  R_RW_OPT="-r";;
  "rw" | "read-write") R_RW_OPT="-w";;
 esac

 #Test fs type
 if [ "a$PARAM" = "arootfstype" ] ; then
   FS_TYPE="-t $VALUE"
 fi

 #Test root device
 if [ "a$PARAM" = "aroot" ] ; then
   ROOTDEV="$VALUE"
 fi

 if [ "a$PARAM" = "aUSB_DISK_SIGNATURE" ] ; then
   USB_LABEL=$VALUE
 fi

done

export R_RW_OPT=$R_RW_OPT
export FS_TYPE=$FS_TYPE
export ROOTDEV=$ROOTDEV

export IFS=`echo -ne " \t\n"`

#Search for disk signature in HDs
#------------------------------------------------

if [ "a$USB_LABEL" != "a" ] ; then

 #Try to mount USB-disk
 echo -n "Searching disk signature: $USB_LABEL "

 #Rescan for new devices
 mdev -s

 #Try to mount all HD devices
 #---------------------------------------------

 ls -1 /dev/hd* 2> /dev/null |
 while
  read TRY_DISK
  do
   mount $R_RW_OPT $FS_TYPE $TRY_DISK /newroot 1> /dev/null 2> /dev/null
   if [ -e /newroot/$USB_LABEL ] ; then
    echo "$USB_LABEL --> HARD DISK $TRY_DISK found"
    HD_FOUND="yes"
    break
   fi
   umount $TRY_DISK 2> /dev/null
 done

fi

#Search for disk signature in SDs
#------------------------------------------------

if [ "a$USB_LABEL" != "a" ] && [ "a$HD_FOUND" = "a" ] ; then

 #Try to mount USB-disk

 n=0

 #Repeat test 10 times
 while [ $n -le 9 ]
 do
  #Rescan for new devices
  mdev -s

  #Try to mount all sd devices
  #---------------------------------------------

  ls -1 /dev/sd* 2> /dev/null |
  while
   read TRY_DISK
   do
    mount $R_RW_OPT $FS_TYPE $TRY_DISK /newroot 1> /dev/null 2> /dev/null
    if [ -e /newroot/$USB_LABEL ] ; then
     echo
     echo "$USB_LABEL found in --> $TRY_DISK"
     echo
     break
    fi
    umount $TRY_DISK 2> /dev/null
  done
  #---------------------------------------------

  if [ -e /newroot/$USB_LABEL ] ; then
   break
  fi

  sleep 1
  let n=$n+1
  echo -n "."
 done

 echo " done."

fi

IS_ROOT_MOUNTED=`mount | grep /newroot`

#Check if device with LABEL is mounted
#-------------------------------------
if [ "a$USB_LABEL" != "a" ] ; then

 if [ "a$IS_ROOT_MOUNTED" != "a" ] ; then

  #try also to mount USB_SIGNATURE_FILE as loop device
  #---------------------------------------------------
  if [ -f /newroot/$USB_LABEL ] ; then
   mount /newroot/$USB_LABEL /newroot -o loop  1> /dev/null 2> /dev/null
  fi

 else
  echo "Error: disk signature <<$USB_LABEL>> not found !!!"

 fi
fi

#If nothing mounted try root= parameter
#------------------------------------------------
if [ "a$IS_ROOT_MOUNTED" = "a" ] && [ "a$ROOTDEV" != "a" ] ; then
 echo "Try to mount append device root=$ROOTDEV ..."
 mount $R_RW_OPT $FS_TYPE $ROOTDEV /newroot 1> /dev/null 2> /dev/null
fi

IS_ROOT_MOUNTED=`mount | grep /newroot`

#If nothing mounted ... ask
#------------------------------------------------

if [ "a$IS_ROOT_MOUNTED" = "a" ] ; then
 echo "Error: root device not mounted ..."
 echo -n "give me another device to try (ex: /dev/sda1) : "
 read ALT_DEVICE

 echo "mount $R_RW_OPT $FS_TYPE $ALT_DEVICE /newroot"
 mount $R_RW_OPT $FS_TYPE $ALT_DEVICE /newroot 1> /dev/null 2> /dev/null
fi

#Check if $init exists and is executable
#------------------------------------------------

#check if perform chroot to /pathname, before
if [ -d /newroot/$USB_LABEL ] && [ -x "/newroot/$USB_LABEL/${init}" ] ; then
 #Unmount all other mounts so that the ram used by
 #the initramfs can be cleared after switch_root
 umount /sys /proc

 #Switch to the new root and execute init
 mount -o bind /newroot/$USB_LABEL /newroot
 exec switch_root /newroot "${init}"
fi

if [[ -x "/newroot/${init}" ]] ; then
 #Unmount all other mounts so that the ram used by
 #the initramfs can be cleared after switch_root
 umount /sys /proc

 #Switch to the new root and execute init
 exec switch_root /newroot "${init}"
fi

#This will only be run if the exec above failed
echo "Failed to switch_root, dropping to a shell"
exec sh' > initramfs/init

chmod +x initramfs/init

echo "Creating the .cpio and .igz ..."
#--------------------------------------------------------
cd initramfs
find . | cpio -H newc -o > ../ramusb.cpio
cd ..
cat ramusb.cpio | gzip > ramusb.igz

echo "Done."
beh ... era divertente presentare 'sta cosetta su slacky.eu :D