Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 6.6: Kernel panic - not syncing: Can't create rootfs #31

Open
fulalas opened this issue Nov 6, 2023 · 12 comments
Open

Version 6.6: Kernel panic - not syncing: Can't create rootfs #31

fulalas opened this issue Nov 6, 2023 · 12 comments

Comments

@fulalas
Copy link

fulalas commented Nov 6, 2023

I'm not sure if this is related to aufs, but I'm failing to boot on PorteuX 0.7 and Porteus 5.01 with the new kernel 6.6 + aufs 6.6 branch:

kernel panic - not syncing: Can't create rootfs

photo_2023-11-06_10-11-42

@sfjro
Copy link
Owner

sfjro commented Nov 7, 2023 via email

@fulalas
Copy link
Author

fulalas commented Nov 7, 2023

I just tried to build kernel 6.6 without aufs and the same error occurs.

I'm closing this because although I don't know how to fix it, it's clear not aufs's fault.

Sorry for bothering you and thanks for the help :)

@fulalas fulalas closed this as completed Nov 7, 2023
@fulalas
Copy link
Author

fulalas commented Nov 10, 2023

@sfjro, I'm re-opening this because it seems the problem is really related to your code, specifically this file tmpfs-idr.patch.

If I build kernel 6.6.x with all patches but without tmpfs-idr.patch, it works, otherwise it doesn't (kernel panic as seen in the first post of this thread).

I haven't tried to use tmpfs-idr.patch from 6.5.x on 6.6.x -- most likely it will fail to build. But I checked and there are a bunch of changes made to this file in your 6.6 branch when compared to 6.5 branch.

What parameters did you give to kernel cmdline?

BOOT_IMAGE=/boot/syslinux/vmlinuz mitigations=off initrd=/boot/syslinux/initrd.zst

Do you mind taking a look at this issue?

Thanks once again for the hard work! :)

@fulalas fulalas reopened this Nov 10, 2023
@sfjro
Copy link
Owner

sfjro commented Nov 11, 2023 via email

@fulalas
Copy link
Author

fulalas commented Nov 11, 2023

  • Are there any logs left? If there is, post please.

Not sure what kind of logs you're expecting.

  • Without tmpfs-idr.patch, what will /proc/mounts look like just after
    the boot?

Without tmpfs-idr.patch (kernel 6.6.1):

tmpfs /mnt/live tmpfs rw,relatime,mode=755,inode64 0 0
proc /mnt/live/proc proc rw,relatime 0 0
sysfs /mnt/live/sys sysfs rw,relatime 0 0
none /mnt/live/dev devtmpfs rw,relatime,size=16382364k,nr_inodes=4095591,mode=755,inode64 0 0
/dev/nvme0n1p1 /mnt/nvme0n1p1 fuseblk rw,noatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/nvme0n1p2 /mnt/nvme0n1p2 fuseblk rw,noatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/sda1 /mnt/sda1 vfat rw,noatime,nodiratime,uid=1000,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,check=s,utf8,errors=remount-ro 0 0
/dev/sda3 /mnt/sda3 fuseblk rw,noatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/sdb1 /mnt/sdb1 fuseblk rw,noatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/sdb2 /mnt/sdb2 vfat rw,noatime,nodiratime,uid=1000,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,check=s,utf8,errors=remount-ro 0 0
/dev/sdb3 /mnt/sdb3 btrfs rw,noatime,nodiratime,ssd,discard=async,space_cache=v2,subvolid=5,subvol=/ 0 0
tmpfs /mnt/live/memory/changes tmpfs rw,relatime,size=27854312k,inode64 0 0
aufs / aufs rw,relatime,si=11f9dff4f5c9c1c0,nowarn_perm 0 0
/dev/loop0 /mnt/live/memory/images/000-kernel-6.6.1.xzm squashfs ro,relatime,errors=continue 0 0
/dev/loop1 /mnt/live/memory/images/001-core-stable-20231013.xzm squashfs ro,relatime,errors=continue 0 0
/dev/loop2 /mnt/live/memory/images/002-xorg-stable-20231013.xzm squashfs ro,relatime,errors=continue 0 0
/dev/loop3 /mnt/live/memory/images/002-xtra-stable-20231013.xzm squashfs ro,relatime,errors=continue 0 0
/dev/loop4 /mnt/live/memory/images/003-xfce-4.12-stable-20231013.xzm squashfs ro,relatime,errors=continue 0 0
devtmpfs /dev devtmpfs rw,relatime,size=16382364k,nr_inodes=4095591,mode=755,inode64 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
tmpfs /dev/shm tmpfs rw,relatime,inode64 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,relatime,mode=755,inode64 0 0
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
tmpfs /sys/fs/cgroup tmpfs rw,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755,inode64 0 0
cgroup /sys/fs/cgroup/elogind cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib64/elogind/elogind-cgroups-agent,name=elogind 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=3276976k,nr_inodes=819244,mode=700,uid=1000,gid=100,inode64 0 0
gvfsd-fuse /run/user/1000/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=100 0 0

With tmpfs-idr.patch (kernel 6.5.7):

tmpfs /mnt/live tmpfs rw,relatime,mode=755,inode64 0 0
proc /mnt/live/proc proc rw,relatime 0 0
sysfs /mnt/live/sys sysfs rw,relatime 0 0
none /mnt/live/dev devtmpfs rw,relatime,size=16382364k,nr_inodes=4095591,mode=755,inode64 0 0
/dev/nvme0n1p1 /mnt/nvme0n1p1 fuseblk rw,noatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/nvme0n1p2 /mnt/nvme0n1p2 fuseblk rw,noatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/sda1 /mnt/sda1 vfat rw,noatime,nodiratime,uid=1000,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,check=s,utf8,errors=remount-ro 0 0
/dev/sda3 /mnt/sda3 fuseblk rw,noatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/sdb1 /mnt/sdb1 fuseblk rw,noatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/sdb2 /mnt/sdb2 vfat rw,noatime,nodiratime,uid=1000,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,check=s,utf8,errors=remount-ro 0 0
/dev/sdb3 /mnt/sdb3 btrfs rw,noatime,nodiratime,ssd,discard=async,space_cache=v2,subvolid=5,subvol=/ 0 0
tmpfs /mnt/live/memory/changes tmpfs rw,relatime,size=27854368k,inode64 0 0
aufs / aufs rw,relatime,si=4dc91af0f407bcf4,nowarn_perm 0 0
/dev/loop0 /mnt/live/memory/images/000-kernel-6.5.7.xzm squashfs ro,relatime,errors=continue 0 0
/dev/loop1 /mnt/live/memory/images/001-core-stable-20231013.xzm squashfs ro,relatime,errors=continue 0 0
/dev/loop2 /mnt/live/memory/images/002-xorg-stable-20231013.xzm squashfs ro,relatime,errors=continue 0 0
/dev/loop3 /mnt/live/memory/images/002-xtra-stable-20231013.xzm squashfs ro,relatime,errors=continue 0 0
/dev/loop4 /mnt/live/memory/images/003-xfce-4.12-stable-20231013.xzm squashfs ro,relatime,errors=continue 0 0
devtmpfs /dev devtmpfs rw,relatime,size=16382364k,nr_inodes=4095591,mode=755,inode64 0 0
sysfs /sys sysfs rw,relatime 0 0
proc /proc proc rw,relatime 0 0
tmpfs /dev/shm tmpfs rw,relatime,inode64 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,relatime,mode=755,inode64 0 0
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
tmpfs /sys/fs/cgroup tmpfs rw,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755,inode64 0 0
cgroup /sys/fs/cgroup/elogind cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib64/elogind/elogind-cgroups-agent,name=elogind 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=3276984k,nr_inodes=819246,mode=700,uid=1000,gid=100,inode64 0 0
gvfsd-fuse /run/user/1000/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=100 0 0
  • Does your distribution 'Porteus' make change about tmpfs or something?
    Where can I found their source files?

I'm actually using PorteuX. The initrd has this script which is responsible for mounting everything in the boot time:

#!/bin/sh
export PATH=/bin:/usr/bin:./

# Source functions
. ./finit

# Enable pivot_root in initramfs to let it behave like initrd:
if [ -d /m ]; then
	mount -nt tmpfs tmpfs -o mode=0755 /m
	cp -a ??* /m 2>/dev/null
	exec switch_root /m linuxrc "$@"
fi

mount -nt proc proc /proc
mount -nt sysfs sysfs /sys
echo 0 >/proc/sys/kernel/printk

clear
echo -e "${BOLD}PorteuX - The Next Experience${RST}"
echo

# Variables:
i=$(echo -e "${X_BLUE}^ ${RST}")
m=$(echo -e "${X_BLUE}>${RST}")
m_warning=$(echo -e "${YELLOW}>${RST}")
arch=`uname -m`; [ $arch = x86_64 ] || arch=i586
CFG=`value cfgfile`; [ $CFG ] || CFG=porteux.cfg
FROM=`value from`; ISO=`echo $FROM | egrep ".*\.iso( |\$)"`
MOPT=`value mopt`; [ $MOPT ] || MOPT="noatime,nodiratime,suid,dev,exec,async"
CHANGES=`value changes`
RAMSIZE=`value ramsize`; [ $RAMSIZE ] || RAMSIZE=85%
LOAD=`value load | sed 's/;/|/g'`; [ $LOAD ] || LOAD=._null
NOLOAD=`value noload | sed 's/;/|/g'`; [ $NOLOAD ] || NOLOAD=._null
EXTRAMOD=`value extramod | sed 's/;/ /g'`
RAMMOD=`value rammod | sed 's/;/|/g'`
ROOTCOPY=`value rootcopy`
FOLDER=porteux
livedbg=/var/log/livedbg
LOGFILE=/var/log/boot.log

FindPorteuxUnit() {
	lazySearchUuid porteux/$CFG
	[ ! $FOUNDPORTEUXUNIT ] && lazySearch porteux/$CFG
}

## Let's start!
mount -nt devtmpfs none /dev

DELAY=`value delay`; [ $DELAY ] && { echo $i"delaying $DELAY sec (waiting for slow devices to settle)"; sleep $DELAY; }

# Perform filesystem check:
if param fsck || param fscknolog; then
	echo $i"performing filesystem check on all available devices..."
	[ ! $DELAY ] || [ $DELAY -lt 3 ] && sleep 3
	blkidValue=$(blkid)
	log=/tmp/fsck.log
	for x in ${blkidValue// /}; do
		fs=$(echo $x | egrep -o 'TYPE="[^"]+' | cut -d\" -f2)
		case $fs in ext|ext2|ext3|ext4|vfat|exfat|ntfs)
			partition=$(echo $x | cut -d: -f1)
			echo "Partition $partition scan result:" >> $log
			case $fs in
				ext|ext2|ext3|ext4) e2fsck -C 0 -p $partition >> $log 2>&1 ;;
				vfat) fsck.fat -a $partition >> $log 2>&1 ;;
				exfat) exfatfsck -p $partition >> $log 2>&1 ;;
				ntfs) ntfsfix -bd $partition >> $log 2>&1 ;;
			esac
			echo "----------" >> $log
		esac
	done
	wait
fi

# Create /etc/fstab and mount devices:
fstab

# Find porteux.cfg file:
echo $i"checking PorteuX data"
if [ $ISO ]; then
	CFGDEV=/mnt/isoloop
	locate $FROM && {
		BOOTDEV=/mnt/$DEV
		mkdir /mnt/isoloop
		mount -o loop /mnt/$DEV/$LPTH /mnt/isoloop
		ISOSRC=/mnt/$DEV/$LPTH
	}
else
	if [ $FROM ]; then
		locate $FROM/porteux/$CFG
		if [ $? -eq 0 ]; then
			DIR=`echo $LPTH | rev | cut -d/ -f3- | rev`; [ $DIR ] && FOLDER=$DIR/porteux
		else
			echo -e "${YELLOW}from= cheatcode is incorrect; searching through all devices${RST}"
			FindPorteuxUnit
		fi
	else
		FindPorteuxUnit
	fi

	CFGDEV=/mnt/$DEV
fi

[ -e $CFGDEV/$FOLDER/$CFG ] && PTH=$CFGDEV/$FOLDER || . fatal

# Set some variables to export as environment variables
BOOTDEV=$CFGDEV
MODDIR=$PTH/modules
BASEDIR=${PTH%/*}
PORTDIR=$PTH
PORTCFG=$CFGDEV/$FOLDER/$CFG
echo $i"using PorteuX data from $PTH"

# Make all drivers available:
mount -o loop $PTH/base/000-kernel*.xzm /opt/000-kernel 2>/dev/null
mount -o bind /opt/000-kernel/lib/modules /lib/modules 2>/dev/null

# Create symlinks used often by porteux scripts:
if [ $CFGDEV = /mnt/nfs -o $CFGDEV = /mnt/isoloop ];then
	ln -sf /mnt/live$PTH/modules /porteux/modules
	ln -sf /mnt/live$PTH/optional /porteux/optional
else
	ln -sf $PTH/modules /porteux/modules
	ln -sf $PTH/optional /porteux/optional
fi

# Setup changes:
if [ $CHANGES ]; then
	CHNEXIT=`echo $CHANGES | cut -d: -f1`
	[ $CHNEXIT = EXIT ] && CHANGES=`echo $CHANGES | cut -d: -f2-`
	[ -r $CFGDEV/$CHANGES ] && { DEV=`echo $CFGDEV | sed s@/mnt/@@`; LPTH=$CHANGES; } || locate $CHANGES && [ -r /mnt/$DEV/$LPTH ]
	if [ $? -eq 0 ]; then
		if [ -d /mnt/$DEV/$LPTH ]; then
			mkdir -p /mnt/$DEV/$LPTH/changes 2>/dev/null && \
			mount -o bind /mnt/$DEV/$LPTH/changes /memory/changes && touch /memory/changes/._test1 2>/dev/null
		else
			if blkid /mnt/$DEV/$LPTH 2>/dev/null | cut -d" " -f3- | grep -q _LUKS; then
				modprobe -a dm_crypt cryptd cbc sha256_generic aes_generic aes_x86_64 2>/dev/null
				load_hid_drivers &
				losetup /dev/loop2 /mnt/$DEV/$LPTH
				echo $i"found encrypted .dat container"
				/opt/000-kernel/sbin/cryptsetup luksOpen /dev/loop2 crypt
				fsck_dat /dev/mapper/crypt
				mount /dev/mapper/crypt /memory/changes 2>/dev/null && touch /memory/changes/._test1 2>/dev/null
			else
				fsck_dat /mnt/$DEV/$LPTH
				mount -o loop /mnt/$DEV/$LPTH /memory/changes 2>/dev/null && touch /memory/changes/._test1 2>/dev/null
			fi
		fi
		if [ $? -eq 0 ]; then
			ln -s /memory/changes/._test1 /memory/changes/._test2 2>/dev/null && chmod +x /memory/changes/._test1 2>/dev/null && [ -x /memory/changes/._test1 ] && chmod -x /memory/changes/._test1 2>/dev/null && [ ! -x /memory/changes/._test1 ] && rm -f /memory/changes/._test1 /memory/changes/._test2
			if [ $? -ne 0 ]; then
				rm -f /memory/changes/._test1 /memory/changes/._test2
				umount /memory/changes
				echo -e $i${YELLOW}"posix not detected, disabling automatic save changes"${RST}
				CHGERR=1
				rmdir /mnt/$DEV/$LPTH/changes
				fail_chn
			else
				echo $i"filesystem is posix compatible"
				CHNDEV=/mnt/$DEV
				rmdir /memory/changes/mnt/* 2>/dev/null
				rm -rf /memory/changes/var/lock/* /var/run/laptop-mode-tools/* /var/spool/cron/cron.??????
				for x in `find /memory/changes/var/run -name "*pid" 2>/dev/null`; do
					rm $x
				done
				if [ $CHNEXIT = EXIT -o "`egrep -o " changes-ro( |\$)" /proc/cmdline`" ]; then
					CHNEXIT=$CHNDEV/$LPTH
					echo $CHNEXIT >/tmp/changes-exit
					param changes-ro && echo -e $i${LIGHT_RED}"changes will not be saved for this session"${RST} || echo -e $i${X_BLUE}"changes will be saved only during reboot/shutdown"${RST}
					for x in `find /memory/changes -name ".wh.*" | grep -v '.wh..wh..opq' | tr ' ' '@' `; do
						x=`echo $x | tr '@' ' ' `
						cp -a --parents "$x" /var
					done
					umount /memory/changes
					mount -nt tmpfs -o size=$RAMSIZE tmpfs /memory/changes
					mv /var/memory/changes/* /memory/changes 2>/dev/null
					CHANGES=memory
				fi
			fi
		else
			echo $i"changes not writable, using memory instead"
			CHGERR=2
			umount /memory/changes 2>/dev/null
			fail_chn
		fi
	else
		CHGERR=3
		fail $CHANGES
		fail_chn
	fi
else
	echo $i"changes cheatcode not found, using memory only"
	fail_chn
fi

mkdir -p /memory/changes/mnt/live

# Setup aufs:
echo $i"creating live filesystem"
mount -t aufs -o nowarn_perm,xino=/memory/xino/.aufs.xino,br:/memory/changes=rw aufs /union
if [ $? -ne 0 ]; then
	echo -e ${LIGHT_RED}"can't setup union (aufs) - read only filesystem?\nWhen you finish debugging press Ctrl+Alt+Del to reboot."${RST}
	sh
fi

# Find modules:
find -L $PTH/base $PTH/modules -name "*.xzm" 2>/dev/null | egrep -ve "$NOLOAD" | sort >/tmp/modules
find -L $PTH/optional -name "*.xzm" 2>/dev/null | egrep -e "$LOAD" | sort >>/tmp/modules

# Find nvidia video card
if param vga_detect; then
	nvidia=`lspci | grep "0300: 10de:"`
	if [ "$nvidia" ]; then
		echo $i"nvidia video card found"
		find $PTH/optional -name "*nvidia-[0-9]*.xzm" 2>/dev/null >>/tmp/modules
	fi
fi

if param base_only; then
	grep base/0 /tmp/modules > /tmp/mod
	mv /tmp/mod /tmp/modules
else
	if [ "$EXTRAMOD" ]; then
		for folder in $EXTRAMOD; do
			locate $folder && { echo $i"loading additional modules in $folder"
					find -L /mnt/$DEV/$LPTH -name "*.xzm" 2>/dev/null | egrep -ve "$NOLOAD" | sort >> /tmp/modules
				} || echo -e $i${LIGHT_RED}"couldn't load additional modules in $folder"${RST}
		done
	fi
fi

# Copy data to RAM:
if param copy2ram; then
	echo $i"copying PorteuX data to RAM..."
	[ $RAMMOD ] && { egrep -e "$RAMMOD" /tmp/modules > /tmp/rammod; cpmod /tmp/rammod; } || cpmod /tmp/modules
fi

# Populate aufs with modules:
umount /lib/modules /opt/000-kernel 2>/dev/null
while read line; do
	NAME=`basename "$line"`
	if [ -d "/memory/images/$NAME" ];then
		echo "  $m_warning $NAME"
	else
		mkdir /memory/images/"$NAME"
		mount -o loop "$line" /memory/images/"$NAME" 2>/dev/null
		if [ $? -eq 0 ]; then
			echo "  $m $NAME"
			mount -no remount,add=1:/memory/images/"$NAME"=rr aufs /union
		else
			echo -e $i${LIGHT_RED}"Cannot read $NAME - corrupted module?"${RST}
			rmdir /memory/images/"$NAME"
		fi
	fi
done < /tmp/modules
mount -no bind /union/lib/modules /lib/modules 2>/dev/null

# Add "changes on exit" device/file/folder:
if [ -e /tmp/changes-exit ]; then
	mkdir /memory/images/changes
	if [ -d $CHNEXIT ]; then
		mount -o bind $CHNEXIT/changes /memory/images/changes
	elif [ -b /dev/mapper/crypt ]; then
		mount /dev/mapper/crypt /memory/images/changes
	else
		mount -o loop $CHNEXIT /memory/images/changes
	fi
	echo "  $m changes"
	mount -no remount,add=1:/memory/images/changes=ro aufs /union
	echo $CHNEXIT/changes >>/tmp/modules
	param changes-ro && rm /tmp/changes-exit
fi

# Copy /rootcopy folder:
if param norootcopy; then
	ROOTCOPY=none
	echo $i"skipping /rootcopy directory"
else
	FILESYSTEM=$(cat /etc/fstab | grep -o /mnt/$DEV.* | cut -f2- -d' ' | cut -f1 -d' ')
	COPYPARAMS="-af"

	# when non-posix filesystem, always copy rootcopy keeping destination permissions
	if [ $FILESYSTEM = "vfat" ] || [ $FILESYSTEM = "ntfs" ] || [ $FILESYSTEM = "exfat" ]; then
		COPYPARAMS="-rf"
		NONPOSIX=true
	fi

	if [ $ROOTCOPY ]; then
		locate $ROOTCOPY && ROOTCOPYPATH=/mnt/$DEV/$LPTH/.
	elif [ -e $PTH/rootcopy ]; then
		ROOTCOPYPATH=$PTH/rootcopy/.
	else
		ROOTCOPY=none
		fail $ROOTCOPY
	fi

	if [ $ROOTCOPYPATH ]; then
		if param rootmount && ! param copy2ram && [ ! $NONPOSIX ]; then
			echo $i"mounting $ROOTCOPYPATH directory..."
			mount -no remount,add=1:"$ROOTCOPYPATH"=rr aufs /union
		else
			echo $i"copying $ROOTCOPYPATH directory..."
			cp $COPYPARAMS "$ROOTCOPYPATH" /union/. 2>/dev/null
		fi
	fi
fi

profileFolder=/union/etc/profile.d
profileFile=$profileFolder/porteux.sh
mkdir -p $profileFolder 2>/dev/null
cat > "$profileFile" << EOF 
export DISTRO=porteux
export BOOTDEV=$CFGDEV
export BASEDIR=${PTH%/*}
export PORTDIR=$PTH
export MODDIR=$MODDIR
export PORTCFG=$PORTCFG
EOF
if [ $CHGERR ]; then
  echo "export CHGERR=$CHGERR" >> $profileFile
fi
chmod +x $profileFile

# Collect boot arguments
grep "^[aA0-zZ9]" $PORTCFG > /union/etc/bootcmd.cfg
cat /proc/cmdline | tr ' ' '\n' >> /union/etc/bootcmd.cfg

## Finish:
# Create 7 free loop devices for truecrypt, etc...
x=`grep -oE 'loop[0-9]+$' /proc/partitions | tail -n1 | tr -d [:alpha:]`
let y=x+7
while [ $x -le $y ]; do
	[ -b /dev/loop$y ] && break || mknod /dev/loop$y b 7 $y
	let y=y-1
done

if param nonetwork; then
	echo $i"disabling dhcpcd and NetworkManager services"
	chmod -x /union/etc/rc.d/rc.inet1 /union/etc/rc.d/rc.networkmanager 2>/dev/null
	nma=/union/etc/xdg/autostart/nm-applet.desktop
	test -e $nma && ! grep -q "Hidden=true" $nma && echo "Hidden=true" >> $nma
fi

cp -af /dev/console /union/dev
fstab

if chk_bootcfg copy2ram; then
	echo -e $i${X_BLUE}"finished copying to RAM - booting media can be removed safely"${RST}
fi

# Create debug file:
[ -e /tmp/devices ] && { echo "# Recognized devices:" >$livedbg
		cat /tmp/devices >>$livedbg
	}
[ $BOOTDEV ] && CFGDEV=$BOOTDEV
echo -e "\n# Booting device:\n$CFGDEV\n\n# PorteuX data found in:\n$PTH\n\n# Changes are stored in:\n$CHANGES\n\n# Non standard /rootcopy dir:\n$ROOTCOPY\n\n# Modules activated during boot time:" >>$livedbg
cat /tmp/modules >>$livedbg
[ -e /mnt/isoloop ] && echo "" >> $livedbg && echo "ISO=$ISOSRC" >> $livedbg
cp -af $livedbg /union/var/log/porteux-livedbg

## Check for text mode cheatcode
chk_bootcfg 3 && export OPTS="3"

# Cleanup mount points at union/mnt for this session
for x in `ls -1 /union/mnt | grep -v "live"`; do
	[ -d /union/mnt/$x ] && rmdir /union/mnt/$x # Will fail if dir not empty!
	[ -L /union/mnt/$x ] && rm -f /union/mnt/$x
done

if chk_bootcfg noauto; then
	for x in `grep /mnt/ /etc/fstab | cut -d/ -f3`; do
		mkdir -p /union/mnt/$x
		umount -n /mnt/$x 2>/dev/null && rmdir /mnt/$x
	done
else
	for x in `grep /mnt/ /etc/fstab | cut -d/ -f3`; do
		mkdir -p /union/mnt/$x
		mount -n --move /mnt/$x /union/mnt/$x
		rmdir /mnt/$x
	done
fi

sed -i 's/ ntfs / ntfs-3g /g' /etc/fstab
cp -f /etc/fstab /union/etc 2>/dev/null

# Add all symlinks of all mount points at /mnt to union
for x in `ls -1 /mnt`; do
	[ -d /union/mnt/$x ] && rmdir /union/mnt/$x
	ln -sf /mnt/live/mnt/$x /union/mnt/$x
done

cp -r /etc/porteux /union/etc 2>/dev/null
umount -n /lib/modules 2>/dev/null
rm -r /lib/* /usr/*

echo -e ${X_BLUE}"live system is ready - starting PorteuX"${RST}
cp -f /union/sbin/init /bin
if [ $? -eq 0 ]; then
	pivot_root /union /union/mnt/live
	exec bin/chroot . /mnt/live/bin/init "$@" $OPTS <dev/console >dev/console 2>&1
else
	echo -e ${LIGHT_RED}"!!ERROR!!\nSomething went wrong and the system cannot be initialized.\nPress Ctrl+Alt+Del to reboot."${RST}
	sh
fi

@fulalas
Copy link
Author

fulalas commented Nov 11, 2023

One more file from initrd that I forgot to post:

## Functions for porteux init

# Export some color functions
RED='\033[0;31m'
LIGHT_RED='\033[1;31m'
GREEN='\033[0;32m'
LIGHT_GREEN='\033[1;32m'
X_BLUE='\x1b[1;38;2;0;150;255m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
BOLD='\033[1;37m'
RST='\033[0m' # Reset Color

# Find a parameter on boot line
param() {
	if [ -e $CFGDEV/$FOLDER/$CFG ]; then
		egrep -qo "^${1}$" $CFGDEV/$FOLDER/$CFG || egrep -qo " $1( |\$)" /proc/cmdline
	else
		egrep -qo " $1( |\$)" /proc/cmdline
	fi
}

value() {
	if [ -e $CFGDEV/$FOLDER/$CFG ]; then
		egrep -o "^${1}=[^ ]+" $CFGDEV/$FOLDER/$CFG | cut -d= -f2
		egrep -o " $1=[^ ]+" /proc/cmdline | cut -d= -f2
	else
		egrep -o " $1=[^ ]+" /proc/cmdline | cut -d= -f2
	fi
}

# Run fstab for setup
fstab() {
	rm -f /tmp/devices
	param nocd || for x in /dev/sr*; do
		blkid $x >>/tmp/devices
		done
	param nohd || blkid | egrep -v '/dev/sr|/dev/loop|/dev/mapper' >>/tmp/devices
	dev=`egrep -v 'TYPE="sw|TYPE="LVM|TYPE=".*_raid_member"' /tmp/devices 2>/dev/null | cut -d: -f1 | cut -d/ -f3 | sort | uniq`
	cat > /etc/fstab << EOF
# Do not edit this file as fstab is recreated automatically during every boot.
# Please use /etc/rc.d/rc.local or sysvinit scripts if you want to mount/unmount
# drive, filesystem or network share.

# System mounts:
aufs / aufs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
devtmpfs /dev devtmpfs defaults 0 0
devpts /dev/pts devpts rw,mode=0620,gid=5 0 0

# Device partitions:
EOF
	for x in $dev; do
		fs=`grep -w /dev/$x /tmp/devices | egrep -o ' TYPE=[^ ]+' | cut -d'"' -f2`
		[ $fs = vfat ] && echo "/dev/$x /mnt/$x vfat $MOPT,umask=0,check=s,utf8,uid=1000 0 0" >>/etc/fstab || echo "/dev/$x /mnt/$x $fs $MOPT 0 0" >>/etc/fstab
		if [ ! -d /mnt/$x ]; then
			mkdir /mnt/$x
			if [ $fs = ntfs ]; then
				ntfs-3g /dev/$x /mnt/$x -o $MOPT,uid=1000,big_writes 2>/dev/null || { sed -i "/$x /d" /etc/fstab; rmdir /mnt/$x; }
			else
				mount -n /mnt/$x 2>/dev/null || { modprobe $fs 2>/dev/null && mount -n /mnt/$x 2>/dev/null || { sed -i "/$x /d" /etc/fstab; rmdir /mnt/$x; }; }
			fi
		fi
	done

	if [ -z "`egrep -o " noswap( |\$)" /proc/cmdline`" -a -e /tmp/devices ]; then
		for x in `grep 'TYPE="swap"' /tmp/devices | cut -d: -f1`; do
			echo "$x none swap sw,pri=1 0 0" >> /etc/fstab
		done
	fi
}

# Mount devices
mount_device() {
	fs=`blkid /dev/$1 | egrep -o ' TYPE=[^ ]+' | cut -d'"' -f2`
	if [ "$fs" ]; then
		mkdir /mnt/$1
		case $fs in
			vfat) mount -n /dev/$1 /mnt/$1 -o $MOPT,umask=0,check=s,utf8,uid=1000 2>/dev/null || rmdir /mnt/$1 ;;
			ntfs) ntfs-3g /dev/$1 /mnt/$1 -o $MOPT,uid=1000,big_writes 2>/dev/null || rmdir /mnt/$1 ;;
			*) mount -n /dev/$1 /mnt/$1 -o $MOPT 2>/dev/null || { modprobe $fs 2>/dev/null && mount -n /dev/$1 /mnt/$1 -o $MOPT || rmdir /mnt/$1; } ;;
		esac
	fi
}

# Search for uuid -- if the uuid inside initrd (generated during install) matches
# a unit that contains /porteux/porteux.cfg then that's the unit we want to boot from
searchUuid() {
	for x in `ls /mnt | tac`; do
		if [ ! -f /mnt/$x/$1 ]; then
			continue
		fi
		currentUnitInfo=`blkid /dev/$x`
		currentUnitUuid=`echo ${currentUnitInfo##* UUID} | cut -d '"' -f2`
		initrdUuid=`cat uuid`
		if [ $initrdUuid = $currentUnitUuid ]; then
			DEV=$x
			FOUNDPORTEUXUNIT=true
			return 0
		fi
	done
	return 1
}

# Search for boot location
search() {
	for x in `ls /mnt | tac`; do
		if [ -f /mnt/$x/$1 ]; then
			DEV=$x
			FOUNDPORTEUXUNIT=true
			return 0
		fi
	done
	return 1
}

# Delay booting a little until devices have settled
nap() {
	echo -en $i"device not ready yet? delaying ${X_BLUE}$SLEEP${RST} seconds \r"
	sleep 1
}

lazySearchUuid() {
	[ ! -e uuid ] && return 1
	SLEEP=10
	while [ $SLEEP -gt 0 ]; do
		searchUuid $*
		if [ $FOUNDPORTEUXUNIT ]; then
			return 0
		fi
		nap
		fstab
		let SLEEP=SLEEP-1
	done
	return 1
}

lazySearch() {
	SLEEP=10
	while [ $SLEEP -gt 0 ]; do
		search $*
		if [ $FOUNDPORTEUXUNIT ]; then
			return 0
		fi
		nap
		fstab
		let SLEEP=SLEEP-1
	done
	return 1
}

# Find location of PorteuX files
locate() {
	PATHPREFIX=`echo $1 | cut -b-5 | sed s@/dev@/mnt@`
	if [ $PATHPREFIX = /mnt/ ]; then
		DEV=`echo $1 | cut -d/ -f3`
		LPTH=`echo $1 | cut -d/ -f4-`
		SLEEP=6
		while [ $SLEEP -gt 0 -a ! -b /dev/$DEV ]; do
			nap
			let SLEEP=SLEEP-1
			fstab
		done
		[ -d /mnt/$DEV ] || mount_device $DEV
		[ -e /mnt/$DEV/$LPTH ]
	elif [ $PATHPREFIX = UUID: -o $PATHPREFIX = LABEL ]; then
		ID=`echo $1 | cut -d: -f2 | cut -d/ -f1`
		LPTH=`echo $1 | cut -d/ -f2-`
		SLEEP=6
		while [ $SLEEP -gt 0 ]; do
			DEV=`blkid | grep $ID | cut -d: -f1 | cut -d/ -f3`
			if [ "$DEV" ]; then
				break
			fi
			nap
			let SLEEP=SLEEP-1
			fstab
		done
		[ -d /mnt/$DEV ] || mount_device $DEV
		[ -e /mnt/$DEV/$LPTH ]
	else
		LPTH=$1
		lazySearch $1
	fi
}

# Booting failed. Failed to find porteux files.
fail() {
	echo -e ${YELLOW}"couldn't find $1. Correct your from= cheatcode."${RST}
	CHGERR=4
}

# Failed to initiate changes. Creating temporary changes on tmpfs for this session.
fail_chn() {
	mount -nt tmpfs -o size=$RAMSIZE tmpfs /memory/changes
	CHANGES=memory
	CHNDEV=memory
}

# Just draw a line
draw() {
	echo -e ${YELLOW}"---------------------------------------------------------"${RST}
}

# Error checking a save file.
fsck_dat() {
	local log=/tmp/fsck.log
	echo $i"checking $1 for errors..."
	echo "Save data x scan result:" >> $log
	fs=`blkid $1 | egrep -o ' TYPE=[^ ]+' | cut -b8-10`
	case $fs in
		xfs) echo "Detected xfs partition - fsck is automatically performed at mount time" >> $log ;;
		ext|ext2|ext3|ext4)
			e2fsck -C 0 -p $1 >> $log 2>&1
			wait
		;;
		*) echo "Detected unsupported filesystem - skipping fsck" >> $log ;;
	esac
	echo "----------" >> $log
}

# Copy modules
cpmod() {
	NUM=`grep -c '.' $1`
	modfile=$1
	while read x; do
		echo -en ${X_BLUE}"  ($NUM modules left)  \r"${RST}
		let NUM=NUM-1
		NAME=`basename "$x"`
		cp -L "$x" /memory/copy2ram 2>/dev/null
		if [ $? -eq 0 ]; then
			sed -i s@^.*/"$NAME"@/memory/copy2ram/"$NAME"@ /tmp/modules
		else
			rm /memory/copy2ram/"$NAME"
			echo -e $i${LIGHT_RED}"Not enough memory to copy $NAME"${RST}
			echo -e $i${LIGHT_RED}"Other modules will be skipped."${RST}
			find /memory/copy2ram -name "*.xzm" | sort >/tmp/modules
			break
		fi
	done < $modfile
	echo -en "					   \r"
}

# If bootlog cheatcode is present then make log entry
blog() {
	param log && echo "$1" >> $LOGFILE
}

# Check for a boot param
chk_bootcfg() {
	grep "^$1" /union/etc/bootcmd.cfg
}

# Make sure all keyboards will work
load_hid_drivers() {
	hid_drivers=$(find /lib/modules/$(uname -r)/kernel/drivers/hid -type f -name '*.ko' | rev | cut -d / -f1 | rev)
	modprobe -a ${hid_drivers//.ko/} 2>/dev/null
}

@sfjro
Copy link
Owner

sfjro commented Nov 12, 2023 via email

@sfjro
Copy link
Owner

sfjro commented Nov 14, 2023 via email

@fulalas
Copy link
Author

fulalas commented Nov 14, 2023

Hahaha! No rush! :)

@sfjro
Copy link
Owner

sfjro commented Nov 30, 2023 via email

@fulalas
Copy link
Author

fulalas commented Dec 6, 2023

Sure! :)

@sfjro
Copy link
Owner

sfjro commented Dec 6, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants