From e24dba96f2546241e768f16f911ef587b93626f9 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Wed, 9 Nov 2016 09:35:56 +0100 Subject: [PATCH 01/11] =?UTF-8?q?Se=20establece=20el=20tipo=20de=20la=20pa?= =?UTF-8?q?rtici=C3=B3n=202=20a=20intercambio=20de=20Linux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- instalar | 3 +++ 1 file changed, 3 insertions(+) diff --git a/instalar b/instalar index af1d211..38c820b 100644 --- a/instalar +++ b/instalar @@ -50,6 +50,9 @@ p 2 +"$HD_SWAP"M +t +2 +82 n p 3 From 71d3c1a302a77fbb635679fcc79cb135c7943015 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Wed, 9 Nov 2016 09:45:18 +0100 Subject: [PATCH 02/11] =?UTF-8?q?Correcci=C3=B3n=20a=20variable=20en=20men?= =?UTF-8?q?saje=20de=20creaci=C3=B3n=20de=20intercambio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- instalar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instalar b/instalar index 38c820b..850a761 100644 --- a/instalar +++ b/instalar @@ -131,7 +131,7 @@ echo "Instalando y configurando GRUB..." chroot /tmp/root update-grub2 &> /dev/null chroot /tmp/root grub-install $HD &> /dev/null -echo "Generando UUID $HD2 (swap)..." +echo "Generando UUID ${HD}2 (swap)..." OLD_SWAP_UUID=`cat /tmp/root/etc/fstab | grep swap | grep 'UUID' | cut -d "=" -f 2 | cut -d " " -f 1` sed -i "s/$OLD_SWAP_UUID/$NEW_SWAP_UUID/g" /tmp/root/etc/fstab From 4bc584c478c9fb900d72f4490b66debc32d85fdb Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Wed, 9 Nov 2016 09:53:46 +0100 Subject: [PATCH 03/11] =?UTF-8?q?Se=20fuerza=20la=20creaci=C3=B3n=20de=20l?= =?UTF-8?q?os=20sistemas=20de=20ficheros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit En otro caso, si el comienzo de la partición coincidiera con una ext existente con anterioridad, ``mkfs`` se detendría a preguntar si reemplazar el sistema de ficheros. --- instalar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instalar b/instalar index 850a761..7e8d44e 100644 --- a/instalar +++ b/instalar @@ -65,9 +65,9 @@ partprobe $HD sleep 5 echo "Formateando las nuevas particiones..." -mkfs -t ext4 "$HD"1 &> /dev/null +mkfs -t ext4 -F "$HD"1 &> /dev/null NEW_SWAP_UUID=`mkswap /dev/sda2 | grep 'UUID' | cut -d "=" -f 2` -mkfs -t ext4 "$HD"3 &> /dev/null +mkfs -t ext4 -F "$HD"3 &> /dev/null swapon "$HD"2 &> /dev/null echo "Preparación del disco duro finalizada" From 6d84aec56566d4d9dcf2c47363a41f9a4dc3f106 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Wed, 9 Nov 2016 12:22:12 +0100 Subject: [PATCH 04/11] =?UTF-8?q?Funci=C3=B3n=20para=20obtener=20UUID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- instalar | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/instalar b/instalar index 7e8d44e..1479d7b 100644 --- a/instalar +++ b/instalar @@ -25,6 +25,10 @@ function pause(){ read -p "$*" } +function get_uuid(){ +perl -ne 'print if s/.*?((?:[[:xdigit:]]+-){4}[[:xdigit:]]+).*/\1/' +} + function init_msg(){ START_TIME=`date +%s` pause "** INSTALACIÓN AUTOMÁTICA DE SSOO ** @@ -66,7 +70,7 @@ sleep 5 echo "Formateando las nuevas particiones..." mkfs -t ext4 -F "$HD"1 &> /dev/null -NEW_SWAP_UUID=`mkswap /dev/sda2 | grep 'UUID' | cut -d "=" -f 2` +NEW_SWAP_UUID=$(mkswap "$HD"2 2> /dev/null | get_uuid) mkfs -t ext4 -F "$HD"3 &> /dev/null swapon "$HD"2 &> /dev/null @@ -132,7 +136,7 @@ chroot /tmp/root update-grub2 &> /dev/null chroot /tmp/root grub-install $HD &> /dev/null echo "Generando UUID ${HD}2 (swap)..." -OLD_SWAP_UUID=`cat /tmp/root/etc/fstab | grep swap | grep 'UUID' | cut -d "=" -f 2 | cut -d " " -f 1` +OLD_SWAP_UUID=$(grep swap /tmp/root/etc/fstab | get_uuid) sed -i "s/$OLD_SWAP_UUID/$NEW_SWAP_UUID/g" /tmp/root/etc/fstab echo "Desmontando $HD y sus particiones" From 6cfc3fcb7d663ed95f9d332d69fd2a583f8f49d5 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Wed, 9 Nov 2016 12:42:52 +0100 Subject: [PATCH 05/11] No se formatean las particiones ext4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La restauración del sistema de ficheros ya se encarga de hacerlo. --- instalar | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/instalar b/instalar index 1479d7b..ccde6ca 100644 --- a/instalar +++ b/instalar @@ -68,10 +68,8 @@ dmsetup remove_all partprobe $HD sleep 5 -echo "Formateando las nuevas particiones..." -mkfs -t ext4 -F "$HD"1 &> /dev/null +echo "Formateando la partición de swap..." NEW_SWAP_UUID=$(mkswap "$HD"2 2> /dev/null | get_uuid) -mkfs -t ext4 -F "$HD"3 &> /dev/null swapon "$HD"2 &> /dev/null echo "Preparación del disco duro finalizada" From e7d26cde2ed13434caa1a4eecbb706f1e690e0ec Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Wed, 9 Nov 2016 15:25:42 +0100 Subject: [PATCH 06/11] =?UTF-8?q?Se=20permite=20a=20la=20partici=C3=B3n=20?= =?UTF-8?q?raiz=20llenar=20el=20espacio=20libre=20en=20disco?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si ``HD_ROOT`` es ``FILL``, primero se crea la partición de intercambio al final del disco y a continuación la raiz ocupando el resto de espacio, y la tercera partición de datos ni se crea ni se restaura. --- instalar | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/instalar b/instalar index ccde6ca..5f90a0f 100644 --- a/instalar +++ b/instalar @@ -12,8 +12,8 @@ SERVER=10.10.20.3 HD='/dev/sda' -HD_SWAP=4096 -HD_ROOT=20480 +HD_SWAP=${HD_SWAP:-4096} # MiB +HD_ROOT=${HD_ROOT:-20480} # MiB o "FILL" LOCAL_MP='/tmp/pxe' REMOTE_MP='/pxe' IMAGE_DIR="$LOCAL_MP/img" @@ -44,7 +44,29 @@ echo "Limpiando MBR..." dd if=/dev/zero of=$HD count=1 bs=512 &> /dev/null echo 'Creando las nuevas particiones...' -echo "n + +if [ "$HD_ROOT" = 'FILL' ]; then + local hd_size_kb=$(sed -ne "s/.* \([0-9]*\) $(basename "$HD")$/\1/p" /proc/partitions) + local hd_size_sectors=$((hd_size_kb * 2)) + local swap_first_sector=$((hd_size_sectors - ($HD_SWAP * 1024 * 2))) + echo "\ +n +p +2 +$swap_first_sector + +n +p +1 + + +t +2 +82 +w" +else + echo "\ +n p 1 @@ -62,7 +84,8 @@ p 3 -w" | fdisk $HD &> /dev/null +w" +fi | fdisk $HD &> /dev/null dmsetup remove_all partprobe $HD @@ -110,7 +133,9 @@ echo "Comenzando la instalación de la imagen. La operación puede durar aproximadamente 5 minutos." fsarchiver restfs $IMAGE_DIR/${IMAGES[$SELECTED]} id=0,dest="$HD"1 &> /dev/null -fsarchiver restfs $IMAGE_DIR/${IMAGES[$SELECTED]} id=1,dest="$HD"3 &> /dev/null +if [ "$HD_ROOT" != 'FILL' ]; then + fsarchiver restfs $IMAGE_DIR/${IMAGES[$SELECTED]} id=1,dest="$HD"3 &> /dev/null +fi umount $IMAGE_DIR &> /dev/null if [ $NFSMOUNT = 'started' ]; then From 22b8cb15040e421524dac524f261795f0b245077 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Wed, 9 Nov 2016 15:55:37 +0100 Subject: [PATCH 07/11] =?UTF-8?q?Tama=C3=B1o=20autom=C3=A1tico=20para=20la?= =?UTF-8?q?=20partici=C3=B3n=20de=20intercambio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si ``HD_SWAP`` se establece a ``AUTO``, se calcula una partición de intercambio de 1,5 veces el tamaño de la memoria, como se recomienda aquí: # env HD_SWAP=AUTO instalar Se puede combinar con ``HD_ROOT=FILL``. --- instalar | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/instalar b/instalar index 5f90a0f..4207e78 100644 --- a/instalar +++ b/instalar @@ -12,7 +12,7 @@ SERVER=10.10.20.3 HD='/dev/sda' -HD_SWAP=${HD_SWAP:-4096} # MiB +HD_SWAP=${HD_SWAP:-4096} # MiB o "AUTO" HD_ROOT=${HD_ROOT:-20480} # MiB o "FILL" LOCAL_MP='/tmp/pxe' REMOTE_MP='/pxe' @@ -45,6 +45,11 @@ dd if=/dev/zero of=$HD count=1 bs=512 &> /dev/null echo 'Creando las nuevas particiones...' +if [ "$HD_SWAP" = 'AUTO' ]; then + local mem_kb=$(sed -rn 's/^MemTotal:\s*([0-9]+) kB/\1/p' /proc/meminfo) + HD_SWAP=$((mem_kb / 1024 * 3 / 2)) # RAM * 1.5 (MiB) +fi + if [ "$HD_ROOT" = 'FILL' ]; then local hd_size_kb=$(sed -ne "s/.* \([0-9]*\) $(basename "$HD")$/\1/p" /proc/partitions) local hd_size_sectors=$((hd_size_kb * 2)) From 18a3ae460005ea6450adef0ccc3eb217897925c8 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Wed, 9 Nov 2016 15:56:28 +0100 Subject: [PATCH 08/11] =?UTF-8?q?D=C3=B3lar=20innecesario=20en=20expresi?= =?UTF-8?q?=C3=B3n=20matem=C3=A1tica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- instalar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instalar b/instalar index 4207e78..541976b 100644 --- a/instalar +++ b/instalar @@ -53,7 +53,7 @@ fi if [ "$HD_ROOT" = 'FILL' ]; then local hd_size_kb=$(sed -ne "s/.* \([0-9]*\) $(basename "$HD")$/\1/p" /proc/partitions) local hd_size_sectors=$((hd_size_kb * 2)) - local swap_first_sector=$((hd_size_sectors - ($HD_SWAP * 1024 * 2))) + local swap_first_sector=$((hd_size_sectors - (HD_SWAP * 1024 * 2))) echo "\ n p From c252c1adb431d7a57f164e252f98cfba01cbb597 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Thu, 10 Nov 2016 11:50:20 +0100 Subject: [PATCH 09/11] =?UTF-8?q?No=20es=20necesario=20habilitar=20la=20pa?= =?UTF-8?q?rtici=C3=B3n=20de=20intercambio=20en=20el=20sistema=20actual?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prepararla con ``mkswap`` es suficiente, y las operaciones siguientes del script probablemente no necesitan mucha más memoria. --- instalar | 1 - 1 file changed, 1 deletion(-) diff --git a/instalar b/instalar index 541976b..78dfc5a 100644 --- a/instalar +++ b/instalar @@ -99,7 +99,6 @@ sleep 5 echo "Formateando la partición de swap..." NEW_SWAP_UUID=$(mkswap "$HD"2 2> /dev/null | get_uuid) -swapon "$HD"2 &> /dev/null echo "Preparación del disco duro finalizada" } From c94b878bccbcd617a736400d885f40f1af52fb2d Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Thu, 10 Nov 2016 12:20:45 +0100 Subject: [PATCH 10/11] Se inhabilitan los espacios de intercambio antes de formatear el disco MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit De lo contrario puede haber problemas, epecialmente si alguna de las particiones del disco ya había sido habilitada (automáticamente) como espacio de intercambio. --- instalar | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instalar b/instalar index 78dfc5a..1ec483d 100644 --- a/instalar +++ b/instalar @@ -40,6 +40,8 @@ Pulse ENTER para comenzar la instalación." function hd_format(){ echo "* Preparación del disco duro *" +echo "Inhabilitando swap..." +swapoff -a echo "Limpiando MBR..." dd if=/dev/zero of=$HD count=1 bs=512 &> /dev/null From 9f2bebddc123fa610afff8cf10b77e71f4029255 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Thu, 10 Nov 2016 12:30:14 +0100 Subject: [PATCH 11/11] Se inhabilitan los espacios de intercambio tras leer la nueva tabla de particiones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit En caso contrario la preparación de la partición de intercambio puede fallar si ya había otra con el mismo nombre en uso. --- instalar | 1 + 1 file changed, 1 insertion(+) diff --git a/instalar b/instalar index 1ec483d..0d905b1 100644 --- a/instalar +++ b/instalar @@ -99,6 +99,7 @@ partprobe $HD sleep 5 echo "Formateando la partición de swap..." +swapoff -a NEW_SWAP_UUID=$(mkswap "$HD"2 2> /dev/null | get_uuid) echo "Preparación del disco duro finalizada"