Sample Header Ad - 728x90

Slackware(64) 14.2 + Xephyr using chroot, umount partitions

1 vote
0 answers
87 views
This Exact Same Question i first time i do was ib -> https://www.linuxquestions.org/questions/showthread.php?p=6366697#post6366697 i need improve my script : For close the Xephyr window automatically after click xfce4-session and for use the safest way to umount partiions after finish inside of chroot env. **---- You can ignore this part ---- :** i have write a own script (on spanish, because i am from venezuela) for mount chroot and start in gracphical env inside a Xephyr Window from Virtual HardDrive, the idea of this script is make the folow things : 01 - Run like root 02 - Mount the Hard Drive (in this case is image qcow2 format) 03 - Mount the partition 04 - Start chroot 05 - Start Xephyr 06 - Run some commands inside chroot 07 - Xephyr window start xfce4-session 08 - Wait until Xephyr finish 09 - When Xephyr finish, start the umount of partitions 10 - Finish the script with "exit 0" **---- The follow part is the important ---- :** Ok here the code i had right now : #!/usr/bin/env bash echo ' Autor ----------------> Inukaze ( Venezuela ) Sitio ----------------> https://goo.gl/ij6WqW Correo-E -------------> bloginukaze@gmail.com Licencia -------------> GPL 2 ' #Establecer mediante la variable "$OBJETIVO" #La particion con una distribucion a la cual se accedera mediante chroot export OBJETIVO="/media/ddvirt" mkdir -p "$OBJETIVO" #Prevenir que se autoejecuten las funciones que se definiran despues unset montar unset desmontar unset MensajeBase unset xephyr #Establecer y definir funciones : function MensajeBase() { echo -e "\nLa forma correcta de utilizar este guion es :\n$0 «montar» , «xephyr» ó «desmontar», Por ejemplo : \n" echo -e "$0 montar" echo -e "$0 xephyr (Modo Ventana)" echo -e "$0 desmontar\n" } function montar(){ #Desmontar en caso de que estuviera montado previamente : umount /dev/nbd0p1 2>/dev/null ; \ qemu-nbd --disconnect /dev/nbd0 1>/dev/null ; \ #Preparar para montar el disco duro virtual modprobe nbd max_part=8 qemu-nbd --connect=/dev/nbd0 /home/inukaze/.aqemu/Slack64-15.0.qcow2 2>/dev/null mount /dev/nbd0p1 "$OBJETIVO" 2>/dev/null #Preparar acceso para programas de entorno grafico : export DISPLAY=:0.0 2>/dev/null xhost + local 2>/dev/null #Montar todo de una vez para una distro de 64 Bits (En este caso Slackware64 15.0) : mount --rbind /proc "$OBJETIVO/proc" ; \ mount --make-rslave "$OBJETIVO/proc" ; \ mount --rbind /sys "$OBJETIVO/sys" ; \ mount --make-rslave "$OBJETIVO/sys" ; \ mount --rbind /dev "$OBJETIVO/dev" ; \ mount --make-rslave "$OBJETIVO/dev" ; \ mount --rbind /run "$OBJETIVO/run" ; \ mount --make-rslave "$OBJETIVO/run" ; \ mount --rbind /tmp "$OBJETIVO/tmp" ; \ mount --make-rslave "$OBJETIVO/tmp" ; \ mount --bind /etc/fstab "$OBJETIVO/etc/fstab" ; \ mount --bind /etc/hostname "$OBJETIVO/etc/hostname" ; \ mount --bind /etc/hosts "$OBJETIVO/etc/hosts" ; \ mount --bind /etc/resolv.conf "$OBJETIVO/etc/resolv.conf" ; \ cat /dev/null EOF chroot "$OBJETIVO" /bin/bash -l ; \ umount "$OBJETIVO" ; \ mount -a 2>/dev/null } function xephyr(){ umount "$OBJETIVO/etc/resolv.conf" 2>/dev/null umount "$OBJETIVO/etc/hosts" 2>/dev/null umount "$OBJETIVO/etc/hostname" 2>/dev/null umount "$OBJETIVO/etc/fstab" 2>/dev/null umount "$OBJETIVO/lib/modules" 2>/dev/null umount "$OBJETIVO/var/lib/dbus" 2>/dev/null umount "$OBJETIVO/var/run/dbus" 2>/dev/null umount "$OBJETIVO/tmp" 2>/dev/null umount "$OBJETIVO/run" 2>/dev/null umount "$OBJETIVO/dev/pts" 2>/dev/null umount -l "$OBJETIVO/dev" 2>/dev/null umount -l "$OBJETIVO/sys" 2>/dev/null umount "$OBJETIVO/proc" 2>/dev/null umount -l /dev/ndb0p1 2>/dev/null sleep 7 qemu-nbd --disconnect /dev/nbd0 1>/dev/null modprobe nbd max_part=8 qemu-nbd --connect=/dev/nbd0 /home/inukaze/.aqemu/Slack64-15.0.qcow2 sleep 3 mount /dev/nbd0p1 "$OBJETIVO" #Copiar archivo de autorizacion X.Org : rm -f "$OBJETIVO/home/inukaze/.Xauthority" rm -f "$OBJETIVO/root/.Xauthority" cp -f "/home/inukaze/.Xauthority" "$OBJETIVO/root/.Xauthority" cp -f "/home/inukaze/.Xauthority" "$OBJETIVO/home/inukaze/.Xauthority" chown inukaze:users "$OBJETIVO/home/inukaze/.Xauthority" echo "" if [ ! -f "$OBJETIVO/etc/X11/Xwrapper.config" ] ; then # Prevenir el error « /usr/libexec/Xorg.wrap: Only console users are allowed to run the X server » echo '# Xwrapper.config (Debian X Window System server wrapper configuration file) # # This file was generated by the post-installation script of the x11-common # package using values from the debconf database. # # See the Xwrapper.config(5) manual page for more information. # # This file is automatically updated on upgrades of the x11-common package # *only* if it has not been modified since the last upgrade of that package. # # If you have edited this file but would like it to be automatically updated # again, run the following command as root: # dpkg-reconfigure x11-common #allowed_users=console allowed_users=anybody' | tee "$OBJETIVO/etc/X11/Xwrapper.config" fi echo "" #Preparar acceso para programas de entorno grafico : $(export DISPLAY=:0.0) $(xhost + local 2>/dev/null) #Montar todo de una vez para una distro de 64 Bits (En este caso Slackware64 15.0) : mount --rbind /proc "$OBJETIVO/proc" ; \ mount --make-rslave "$OBJETIVO/proc" ; \ mount --rbind /sys "$OBJETIVO/sys" ; \ mount --make-rslave "$OBJETIVO/sys" ; \ mount --rbind /dev "$OBJETIVO/dev" ; \ mount --make-rslave "$OBJETIVO/dev" ; \ mount --rbind /dev/pts "$OBJETIVO/dev/pts" ; \ mount --make-rslave "$OBJETIVO/dev/pts" ; \ mount --rbind /run "$OBJETIVO/run" ; \ mount --make-rslave "$OBJETIVO/run" ; \ mount --rbind /tmp "$OBJETIVO/tmp" ; \ mount --make-rslave "$OBJETIVO/tmp" ; \ mount --rbind /var/run/dbus "$OBJETIVO/var/run/dbus" ; \ mount --make-rslave "$OBJETIVO/var/run/dbus" ; \ mount --rbind /var/lib/dbus "$OBJETIVO/var/lib/dbus" ; \ mount --make-rslave "$OBJETIVO/var/lib/dbus" ; \ mount --rbind /lib/modules "$OBJETIVO/lib/modules" ; \ mount --make-rslave "$OBJETIVO/lib/modules" ; \ mount --bind /etc/fstab "$OBJETIVO/etc/fstab" ; \ mount --bind /etc/hostname "$OBJETIVO/etc/hostname" ; \ mount --bind /etc/hosts "$OBJETIVO/etc/hosts" ; \ mount --bind /etc/resolv.conf "$OBJETIVO/etc/resolv.conf" ; \ $(Xephyr -screen 1070x887 -ac -br -reset -terminate :1.0 \ +extension Composite \ +extension DAMAGE \ +extension DOUBLE-BUFFER \ +extension DPMS \ +extension GLX \ +extension MIT-SCREEN-SAVER \ +extension MIT-SHM \ +extension RANDR \ +extension RENDER \ +extension X-Resource \ +extension XFIXES \ +extension XTEST \ +extension XVideo \ +iglx \ 2>/dev/null &) export xerphid=$(pidof "Xephyr") cat /dev/null) EOF chroot "$OBJETIVO" /bin/bash -l /dev/null &) EOT #Esperar que Xephyr sea cerrado para desmontar particiones : tail --pid="$xerphid" -f /dev/null sleep 120 umount "$OBJETIVO/etc/resolv.conf" umount "$OBJETIVO/etc/hosts" umount "$OBJETIVO/etc/hostname" umount "$OBJETIVO/etc/fstab" umount "$OBJETIVO/lib/modules" umount "$OBJETIVO/var/lib/dbus" umount "$OBJETIVO/var/run/dbus" umount "$OBJETIVO/tmp" umount -l "$OBJETIVO/run" umount "$OBJETIVO/dev/pts" umount -l "$OBJETIVO/dev" umount -l "$OBJETIVO/sys" umount "$OBJETIVO/proc" umount -l /dev/ndb0p1 qemu-nbd --disconnect /dev/nbd0 1>/dev/null sleep 7 mount -a 2>/dev/null } function desmontar(){ # Desmontar umount "$OBJETIVO/etc/resolv.conf" umount "$OBJETIVO/etc/hosts" umount "$OBJETIVO/etc/hostname" umount "$OBJETIVO/etc/fstab" umount "$OBJETIVO/lib/modules" umount "$OBJETIVO/var/lib/dbus" umount "$OBJETIVO/var/run/dbus" umount "$OBJETIVO/tmp" #umount -l "$OBJETIVO/run" 2>/dev/null umount "$OBJETIVO/run" umount "$OBJETIVO/dev/pts" #umount -l "$OBJETIVO/dev" 2>/dev/null umount "$OBJETIVO/dev" #umount -l "$OBJETIVO/sys" 2>/dev/null umount "$OBJETIVO/sys" umount "$OBJETIVO/proc" #umount -l /dev/ndb0p1 2>/dev/null umount -l /dev/ndb0p1 2>/dev/null qemu-nbd --disconnect /dev/nbd0 1>/dev/null sleep 7 mount -a 2>/dev/null } #Este guión necesita ser ejecutado como SuperUsuario #o en su defecto con permisos administrativos suficientes #Para montar / desmontar particiones. if [ "$(whoami)" != root ]; then echo echo echo 'Por favor ejecuta este guion como SuperUsuario (root)' echo echo 'Utilize este guión bajo su Propio Riesgro' echo 'El Autor , o sea yo , no me hago responsable' echo 'de las consecuencias imprevistas que puedan' echo 'acontecer en tu sistema operativo' echo else # Proceder en caso de tener los permisos suficientes para montar/desmontar particiones : #Si el usuario no pasa ningun parametro iniciar directamente en "Xephyr" #En la interfaz de linea de comandos (ILC / CLI ) indicar como se puede usar este guion if [ -z "$1" ]; then echo MensajeBase echo xephyr fi #Guion : Aqui se ha definido como se utilizara este guion correctamente para montar o desmontar la particion Objetivo #Entrada : Cualquier palabra pasada por el parametro $1 sera convertida en minusculas Entrada=$(echo "$1" | tr -s '[:upper:]' '[:lower:]') if [ "$Entrada" == "montar" ]; then montar fi if [ "$Entrada" == "xephyr" ]; then xephyr fi if [ "$Entrada" == "desmontar" ]; then desmontar fi #Finalizar la condicion global de requerir usar el SuperUsuario o en su defectos persmisos administrativos #Para poder (des)montar particiones : fi The problem is when i indicate on the Xephyr window, and i wait around 5 mins for all process finish for close the Xephyr window manully because never gone, i can't umount the partions, because are still busy by "jbd2/nbd0p1-8", and neither i can force the kernel module "nbd" unload because is on use.
Asked by Inukaze (47 rep)
Jul 10, 2022, 10:28 AM