LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-10-2022, 05:19 AM   #1
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 270

Rep: Reputation: 26
Post Slackware(64) 14.2 + Xephyr using chroot


The second time i make this exact same question was -> https://unix.stackexchange.com/quest...unt-partitions


Hi there, 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 a inside a 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 :
Code:
#!/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 << EOF | chroot	"$OBJETIVO"
export DISPLAY=:1.0 2>/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 << EOF | chroot	"$OBJETIVO"
$(export DISPLAY=:1.0 2>/dev/null) 
EOF

chroot									"$OBJETIVO"	/bin/bash -l		<<"EOT"
#Primero Detectar Particiones, Crear Directorios dentro de /media y finalmente montarlas
#Nombre De Particion :
#	NPD1="1SlackIni"	# Esta es la particion /boot de la particion que estoy usando en chroot
	NPD2="72GB"
	NPD3="Compartido"
	NPD4="2SlackIni"
	NPD5="Slack64"	#Esta es la particion Anfrition, ya que intercambiare datos, la necesito montar.

#Parte de la Particion
#	PPD1=$(blkid -l -t LABEL="$NPD1" | awk '{print $01}' | sed 's/:.*//g')
	PPD2=$(blkid -l -t LABEL="$NPD2" | awk '{print $01}' | sed 's/:.*//g')
	PPD3=$(blkid -l -t LABEL="$NPD3" | awk '{print $01}' | sed 's/:.*//g')
	PPD4=$(blkid -l -t LABEL="$NPD4" | awk '{print $01}' | sed 's/:.*//g')
	PPD5=$(blkid -l -t LABEL="$NPD5" | awk '{print $01}' | sed 's/:.*//g')
$(mkdir -p /media/"$NPD2" ; mount "$PPD2" /media/"$NPD2" )
$(mkdir -p /media/"$NPD3" ; mount "$PPD3" /media/"$NPD3" )
$(mkdir -p /media/"$NPD4" ; mount "$PPD4" /media/"$NPD4" )
$(mkdir -p /media/"$NPD5" ; mount "$PPD5" /media/"$NPD5" )
#$(USER="inukaze" ; gpasswd -a $USER video)
$(rm -rf /tmp/.X1-lock)
$(chown root:root /tmp/.ICE-unix)
$(su - inukaze)

$(export DISPLAY=:1)
$(DISPLAY=:1 "/usr/bin/xfce4-session" -- :1 2>/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.

Last edited by inukaze; 07-10-2022 at 05:31 AM.
 
  


Reply

Tags
bash, chroot, slackware 14.2/x86_64, umount, xephyr



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using KDE or Trinity in Xephyr Raevyn Linux - Desktop 2 01-31-2012 08:45 PM
Suggestions on using Xnest and Xephyr? Need help linus72 Linux - Software 0 08-16-2009 06:43 PM
Xephyr nested login on Debian tekhead2 Linux - General 0 06-25-2009 10:58 AM
xephyr to listen on tcp/udp bradbobak Linux - Software 2 11-16-2008 02:49 AM
Xephyr/Xnest - all I can get is a weave pattern instead of remote desktop gctaylor1 Linux - Desktop 1 01-05-2007 10:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration