Aggancia questa barra allo schermo |  Disattiva gli effetti grafici

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.



Una mini Slackware su pendrive


 

Vi presento uno script bash che crea una mini Slackware su pendrive in automatico.

script

Questo esempio fa riferimento a Slackware dalla 14.0 in poi sia a 32 bit che 64 bit.
Cerca i pacchetti elencati nell'array se sono già presenti nella directory impostata, se non li trova e se c'è il dvd di Slackware montato li copia da esso, altrimenti li scarica da internet.
Poi esegue una procedura ispirata alla guida presente su slacky.eu.

A partire da Slackware 14.1, non sono più stati inclusi builtin i driver per l'USB (sono stati abilitati come moduli), quindi ho dovuto fare delle piccole aggiunte allo script per poter includere tali driver nell'initrd.

mk.minislack (Slackware >= 14.0)

#!/bin/sh
# Copyright (C) 2013-2017, Andrea Peluso <sya54m@gmail.com>
# Tutti i diritti riservati.
#
# ___ changelog ___
#
# 14.2.2 (19/11/2017)
# corretto bug mancanza directory packages
# aggiornati pacchetti current
#
# 14.2.1 (27/05/2016)
# corretto bug su 64 bit
#
# 14.2 (12/05/2016)
# aggiunta lista pacchetti di Slackware 14.2
# modifica dell'initrd per includere i driver usb
# aggiunto supporto 64 bit
# aggiunto controllo esistenza dispositivo passato per argomento
# aggiunta configurazione del file lang.sh
# rilevamento automatico delle versioni dei pacchetti
# rilevamento automatico delle dipendenze di mount
#
# 14.1.1 (26/05/2015)
# aggiunte patch di sicurezza rilasciate per la 14.1
# aggiunto controllo permessi root
# modificato messaggio di aiuto
#
# 14.1 (14/11/2013)
# aggiornata lista pacchetti a Slackware 14.1
# modifica dell'initrd per includere i driver usb
#
# 14.0 (29/04/2013)
# prima versione (basata su Slackware 14.0)

#### Configurazione ####
TMPPKG="/tmp/minislackpkg"
TMPINITRD="/tmp/initrd"
MNT="/mnt/memory"
DVD="/media/SlackDVD"
MIRROR="http://ftp.slackware.com/pub/slackware"
ARCH="" # vuoto per 32 bit, "64" per 64 bit
VERSION="current"
lng="it"
COD="UTF-8"
########################

if [ "$VERSION" == "current" ]; then
  PKG=(
aaa_base- aaa_elflibs- aaa_terminfo- acl- acpid- attr- bash- btrfs-progs- bin-
coreutils- dcron- devs- dialog- dosfstools- e2fsprogs- elvis- etc-
eudev- file- findutils- glibc-solibs- glibc-zoneinfo- gpm- grep- gzip- hdparm-
hwdata- kbd- kernel-firmware- kernel-huge-smp- kernel-modules-smp- kmod- less-
libcgroup- libgudev- mkinitrd- ntfs-3g- openssl-solibs- pciutils- pkgtools-
procps-ng- sed- shadow- sharutils- smartmontools- sysvinit-[0-9]
sysvinit-scripts- tar- util-linux- xz-
dmidecode- lm_sensors- mc- nano-
libxml2-
net-tools- network-scripts- openssh-
)
elif [ "$VERSION" == "14.2" ]; then
  PKG=(
aaa_base- aaa_elflibs- aaa_terminfo- acl- acpid- attr- bash- btrfs-progs- bin-
coreutils- dcron- devs- dialog- dosfstools- e2fsprogs- eject- elvis- etc-
eudev- file- findutils- glibc-solibs- glibc-zoneinfo- gpm- grep- gzip- hdparm-
hwdata- kbd- kernel-firmware- kernel-huge-smp- kernel-modules-smp- kmod- less-
libcgroup- libgudev- mkinitrd- ntfs-3g- openssl-solibs- pciutils- pkgtools-
procps-ng- sed- shadow- sharutils- smartmontools- sysvinit-[0-9]
sysvinit-scripts- tar- util-linux- xz-
dmidecode- lm_sensors- mc- nano-
json-c- libxml2-
net-tools- network-scripts- openssh-
)
elif [ "$VERSION" == "14.1" -o "$VERSION" == "14.0" ]; then
  PKG=(
aaa_base- aaa_elflibs- aaa_terminfo- acl- acpid- attr- bash- bin- btrfs-progs-
coreutils- cxxlibs- dcron- devs- dialog- dosfstools- e2fsprogs- eject- elvis-
etc- file- findutils- glibc-solibs- glibc-zoneinfo- gpm- grep- gzip- hdparm-
kbd- kernel-firmware- kernel-huge-smp- kernel-modules-smp- kmod- less-
libcgroup- ntfs-3g- openssl-solibs- pciutils- pkgtools- procps- sed- shadow-
sharutils- smartmontools- sysvinit- sysvinit-scripts- tar- udev- util-linux-
xz-
dmidecode- lm_sensors- mc- nano-
net-tools- network-scripts- openssh-
)
fi

TEST=$?
if [ $# -ne 1 -o $TEST -ne 0 ]; then
  echo -e "Uso: $0 /dev/sdx\n"
  echo "Procedura automatizzata per la costruzione di una mini Slackware."
  echo "Copyright (C) 2013-2016, Andrea Peluso."
  echo "Esempio:"
  echo "  $(basename $0) /dev/sdX"
  echo -e "\nSegnalare i bug di mk.minislack a <sya54m@gmail.com>"
  echo -e "Sito web di mk.minislack: <http://www.sya54m.eu/>\n"
  exit 1
fi
if [ "$(whoami)" != "root" ]; then
  echo -e "Permesso negato: eseguire come root.\n"
  exit 1
fi
if [ ! -b "$1" ]; then
  echo -e "Errore: il dispositivo $1 non esiste.\n"
  exit 1
fi
LNG=$(echo $lng | tr "[:lower:]" "[:upper:]")
rm -rf $TMPINITRD
umount $11 2> /dev/null
set -e
mkdir -p $TMPPKG $MNT
cd $TMPPKG
if [ ! -r FILE_LIST ] || [ -r FILE_LIST -a $(expr `date +%s` - `stat -c %Z FILE_LIST`) -gt 3600 ]; then
	wget $MIRROR/slackware$ARCH-$VERSION/slackware$ARCH/FILE_LIST -O FILE_LIST
fi
if [ ! -r patchesFILE_LIST ] || [ -r patchesFILE_LIST -a $(expr `date +%s` - `stat -c %Z patchesFILE_LIST`) -gt 3600 ]; then
	wget $MIRROR/slackware$ARCH-$VERSION/patches/FILE_LIST -O patchesFILE_LIST
fi
NUM=0
while [ "$NUM" -lt "${#PKG[*]}" ]; do
  if [ "$ARCH" == "64" -a -n "`echo ${PKG[$NUM]} |grep kernel`" ]; then
    PKG[$NUM]=$(echo ${PKG[$NUM]} |sed "s|-smp||g")
  fi
  FILE[$NUM]=$(cat patchesFILE_LIST |egrep ".tgz|.txz" |egrep -v ".asc|.md5" |egrep /${PKG[$NUM]} |cut -d / -f2,3,4)
  if [ -z "${FILE[$NUM]}" ]; then
    FILE[$NUM]=$(cat FILE_LIST |egrep ".tgz|.txz" |egrep -v ".asc|.md5" |egrep /${PKG[$NUM]} |cut -d / -f2,3)
  fi
  if [ -n "$(echo ${FILE[$NUM]} |grep "/kernel-huge")" ]; then
    KERNELVER=$(ls $TMPPKG/${FILE[$NUM]} |rev |cut -d- -f3 |rev)
  fi
  if [ -n "$(echo ${FILE[$NUM]} |grep "/kernel-modules-")" ]; then
    kmodules=$(ls $TMPPKG/${FILE[$NUM]} |rev |cut -d/ -f1 |cut -f2- -d. |rev)
    kmodulesp=$TMPPKG/${FILE[$NUM]}
  fi
  if [ ! -f "$TMPPKG/${FILE[$NUM]}" ]; then
    if [ -r "$DVD/slackware$ARCH/${FILE[$NUM]}" ]; then
      echo "+=============================================================================="
      echo "| Copia del file `expr $NUM + 1` di ${#PKG[*]}: ${FILE[$NUM]}"
      echo "+=============================================================================="
      cp "$DVD/slackware$ARCH/${FILE[$NUM]}" "$TMPPKG/${FILE[$NUM]}" || rm "$TMPPKG/${FILE[$NUM]}"
    else
      echo "+=============================================================================="
      echo "| Download del file `expr $NUM + 1` di ${#PKG[*]}: ${FILE[$NUM]}"
      echo "+=============================================================================="
      if [ "$VERSION" == "current" ]; then
        curl "$MIRROR/slackware$ARCH-$VERSION/slackware$ARCH/${FILE[$NUM]}" --create-dirs -o "$TMPPKG/${FILE[$NUM]}" || rm "$TMPPKG/${FILE[$NUM]}"
      else
        if [ -n "$(echo ${FILE[$NUM]} |grep "packages/")" ]; then
          curl "$MIRROR/slackware$ARCH-$VERSION/patches/${FILE[$NUM]}" --create-dirs -o "$TMPPKG/${FILE[$NUM]}" || rm "$TMPPKG/${FILE[$NUM]}"
        else
          curl "$MIRROR/slackware$ARCH-$VERSION/slackware$ARCH/${FILE[$NUM]}" --create-dirs -o "$TMPPKG/${FILE[$NUM]}" || rm "$TMPPKG/${FILE[$NUM]}"
        fi
      fi
    fi
  fi
  NUM=`expr $NUM + 1`
done
echo -e "\E[031;1mDownload completati.\E[031;0m"
mkfs.ext4 -L minislack $11
tune2fs -O ^has_journal $11
mount -o exec -rw -t ext4 $11 $MNT
installpkg -root $MNT $TMPPKG/*/*.t?z
if [ -n "$(ls $TMPPKG/*.t?z 2> /dev/null)" ]; then
  installpkg -root $MNT $TMPPKG/*.t?z
fi
if [ -n "$(ls $TMPPKG/*/*/*.t?z 2> /dev/null)" ]; then
  installpkg -root $MNT $TMPPKG/*/*/*.t?z
fi
mkdir $TMPINITRD
cd $TMPINITRD
mkdir bin
tar -C $TMPINITRD -zxf $MNT/usr/share/mkinitrd/initrd-tree.tar.gz './bin/busybox'
cd bin
cp -p $MNT/bin/mount $TMPINITRD/bin
mkdir $TMPINITRD/lib$ARCH
libmount=(`ldd $MNT/bin/mount |cut -d' ' -f1 |tr -d '\t' |cut -d/ -f3`)
NUM=0
while [ "$NUM" -lt "${#libmount[*]}" ]; do
  if [ -f $MNT/lib$ARCH/${libmount[$NUM]} ]; then
    cp -p $MNT/lib$ARCH/${libmount[$NUM]} $TMPINITRD/lib$ARCH
  fi
  NUM=`expr $NUM + 1`
done
if [ -f $MNT/lib$ARCH/libm.so.6 ]; then
  cp -p $MNT/lib$ARCH/libm.so.6 $TMPINITRD/lib$ARCH
fi
ln -s busybox ash
ln -s busybox echo
ln -s busybox umount
ln -s busybox sleep
ln -s busybox switch_root
if [ "$VERSION" != "14.0" ]; then
  mkdir $TMPINITRD/sbin
  cd $TMPINITRD/sbin
  ln -s ../bin/busybox modprobe
  controllo=0
  if [ -z "`ls /var/log/packages/$kmodules 2> /dev/null`" ]; then
    controllo=1
    tar -C $TMPPKG -xf $kmodulesp "lib/modules/"$(echo $KERNELVER |tr _ -)
    mv $TMPPKG/lib/modules/$(echo $KERNELVER |tr _ -) /lib/modules/$(echo $KERNELVER |tr _ -)-minislack
    rm -rf $TMPPKG/lib
  fi
  if [ "$VERSION" == "14.1" ]; then
    mkinitrd -c -k $(echo $KERNELVER |tr _ -)-minislack -m ehci-pci:xhci-hcd:uhci-hcd:ohci-hcd:usb-storage
  else
    mkinitrd -c -k $(echo $KERNELVER |tr _ -)-minislack -m ehci-pci:xhci-hcd:xhci-pci:uhci-hcd:ohci-hcd:usb-storage
  fi
  if [ "$controllo" == "1" ]; then
    rm -rf /lib/modules/$(echo $KERNELVER |tr _ -)-minislack
  fi
  mkdir -p $TMPINITRD/lib/modules
  cp -r /boot/initrd-tree/lib/modules/$(echo $KERNELVER |tr _ -)-minislack $TMPINITRD/lib/modules/$(echo $KERNELVER |tr _ -)
fi
mkdir $TMPINITRD/etc
touch $TMPINITRD/etc/mtab
mkdir $TMPINITRD/dev
cp -r /dev/null $TMPINITRD/dev
mknod $TMPINITRD/dev/sda1 b 8 1
mknod $TMPINITRD/dev/sdb1 b 8 17
mknod $TMPINITRD/dev/sdc1 b 8 33
mknod $TMPINITRD/dev/sdd1 b 8 49
mknod $TMPINITRD/dev/sde1 b 8 65
mknod $TMPINITRD/dev/sdf1 b 8 81
mknod $TMPINITRD/dev/sdg1 b 8 97
mkdir $TMPINITRD/proc $TMPINITRD/mnt
if [ "$VERSION" == "14.0" ]; then
  moduli=""
elif [ "$VERSION" == "14.1" ]; then
  moduli="/sbin/modprobe ehci-hcd
/sbin/modprobe ehci-pci
/sbin/modprobe xhci-hcd
/sbin/modprobe uhci-hcd
/sbin/modprobe ohci-hcd
/sbin/modprobe usb-storage"
else
  moduli="/sbin/modprobe ehci-hcd
/sbin/modprobe ehci-pci
/sbin/modprobe xhci-hcd
/sbin/modprobe xhci-pci
/sbin/modprobe uhci-hcd
/sbin/modprobe ohci-hcd
/sbin/modprobe usb-storage"
fi
cat > $TMPINITRD/init <<EOF
#!/bin/ash
mount -n proc /proc -t proc
$moduli
echo "Cerco la partizione con etichetta minislack..."
while ! mount -n -r -L minislack /mnt 2> /dev/null;
 do
    sleep 1;
 done
umount /proc
exec switch_root /mnt /sbin/init \$@
EOF
chmod u+x $TMPINITRD/init
cd $TMPINITRD
chown -R root:root .
find . | cpio -o -H newc | gzip -9 -n > $MNT/boot/initrd.gz
echo -e "LABEL=minislack\t\t/\text4\tdefaults,noatime\t0 1" > $MNT/etc/fstab
cat > $MNT/etc/hardwareclock <<EOF
localtime
EOF
cat > $MNT/etc/rc.d/rc.keymap <<EOF
#!/bin/sh
if [ -x /usr/bin/loadkeys ]; then
 /usr/bin/loadkeys $lng.map
fi
EOF
chmod 755 $MNT/etc/rc.d/rc.keymap
sed -i "s|en_US|$lng\_$LNG.$COD|g" $MNT/etc/profile.d/lang.sh
cat > $MNT/etc/lilo.conf <<EOF
boot = $1
map=$MNT/boot/map
compact
lba32
large-memory

image = $MNT/boot/vmlinuz
  label = Slackware
  initrd = $MNT/boot/initrd.gz
EOF
lilo -C $MNT/etc/lilo.conf
Scarica [.sh]    ...scaricato 8 volte, dimensione: 10 KB

È sufficiente eseguirlo in questo modo:

# ./mk.minislack /dev/sdX

Dove /dev/sdX è il devicenode che punta alla pendrive.

Scritto da: Andrea Peluso (sya54M), . Ultimo aggiornamento: .

Commenti

1 commento

bitcoin vermehren

Karl

https://t.me/s/Bitcoin_verdienen

I campi contrassegnati con * sono obbligatori.

Condividi sui tuoi social preferiti!

Telegram Facebook Linkedin Twitter Pinterest
.