View previous topic :: View next topic |
Author |
Message |
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Sat May 21, 2022 2:36 pm Post subject: |
|
|
immolo,
Add like this.
Code: | #Mount USB
mount -t ext4 -o ro /dev/sda2 /mnt || echo "Failed to mount sda2"
sleep 30
#mount --move /sys /mnt
#mount --move /dev /mnt
#mount --move /proc /mnt |
That will give you time to read the message before it scrolls off the screen. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
pingtoo l33t
Joined: 10 Sep 2021 Posts: 926 Location: Richmond Hill, Canada
|
Posted: Sat May 21, 2022 2:53 pm Post subject: |
|
|
Suggest you enter shell after you mount /proc, that way we know you successfully enter initramfs.
Not sure about the devfs. Are you sure your kernel have CONFIG_DEVFS_FS? on my kernel only have CONFIG_DEVTMPFS, so it would been mount -t devtmpfs none /dev
For initramfs it is already in memory, you don't need to mount tmpfs to /var, /tmp. |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
Posted: Sat May 21, 2022 3:34 pm Post subject: |
|
|
Neddy,
Sleep 30 shows the drive being mounted now
Pingtoo,
The second I added devtmpfs everything works as intended and drops me to shell.
So at least we know the initramfs works correctly so now it's just figuring out why switch_root keeps failing.
My new init is as follows:
Code: |
#!/bin/busybox sh
/bin/busybox --install -s
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH
#Mount Section
mount -t devtmpfs none /dev
mount -t sysfs none /sys
mount -t proc none /proc
mkdir /dev/pts
mount -t devpts none /dev/pts
mount -t debugfs none /sys/kernel/debug
#Load PS2 Modules
depmod
modprobe ps2fb mode_option=640x512i@50
modprobe sif
modprobe iop-memory
modprobe iop-module
modprobe iop-irq
modprobe sd_mod
modprobe ohci-ps2
modprobe ums-usbat
modprobe usbhid
modprobe hid-generic
sleep 5
#Mount USB
mount -t ext4 -o ro /dev/sda2 /mnt || echo "Failed to mount sda2"
sleep 30
mount --move /sys /mnt
mount --move /dev /mnt
mount --move /proc /mnt
exec 0</dev/console
exec 1>/dev/console
exec 2>/dev/console
#Debug
/bin/sh
#Cleanup
#umount /proc
#umount /sys
#umount /dev
#Boot Root
#init=/sbin/init
exec switch_root /mnt /sbin/init
exec /bin/sh
|
|
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Sat May 21, 2022 3:58 pm Post subject: |
|
|
immolo,
I've never done
Code: | mount --move /sys /mnt
mount --move /dev /mnt
mount --move /proc /mnt |
and I don't think it does what you intended.
man mount: | The move operation
Move a mounted tree to another place (atomically). The call is:
mount --move olddir newdir
This will cause the contents which previously appeared under olddir to
now be accessible under newdir. The physical location of the files is
not changed. Note that olddir has to be a mountpoint.
|
You have your soon to be root filesystem at /mnt
So those --move commands should be along the lines of
Code: | mount --move /sys /mnt/sys | or they will all pile up on top of the root fs and only /proc will be visible.
Then Code: | exec switch_root /mnt /sbin/init | because there is no /sbin/init in /proc.
I would drop the becase you will need those filesystem in the old locations if you drop into the shell.
Put the Code: | #Cleanup
#umount /proc
#umount /sys
#umount /dev | back though. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Sat May 21, 2022 5:01 pm Post subject: |
|
|
immolo,
Here's a working init script from a KVM.
Its mostly full of junk as it was cut down from a similar install on the bare metal.
It expects to find the environment
Code: | # directory structure
dir /proc 755 0 0
dir /usr 755 0 0
dir /bin 755 0 0
dir /sys 755 0 0
dir /var 755 0 0
#dir /lib 755 0 0
dir /lib64 755 0 0
dir /sbin 755 0 0
dir /mnt 755 0 0
dir /mnt/root 755 0 0
dir /etc 755 0 0
dir /root 700 0 0
dir /dev 755 0 0
nod /dev/null 666 0 0 c 1 3
nod /dev/tty 666 0 0 c 5 0
nod /dev/console 600 0 0 c 5 1 | when it starts.
The interesting bit of the init script is
Code: | PATH="/sbin:/bin"
# start for real here
# temporarily mount proc,sys and dev
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs devtmpfs /dev
# mounting rootfs on /mnt/root - from the UUID on the kernel command line
uuidlabel_root || rescue_shell "Error with uuidlabel_root"
# clean up. The init process will remount proc sys and dev later
umount /proc
umount /sys
umount /dev
# switch to the real root and execute init
exec /sbin/switch_root /mnt/root /sbin/init |
How do you make all the mount points that you use? _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
Posted: Sat May 21, 2022 5:29 pm Post subject: |
|
|
Neddy,
Hmm I have all those directories and /dev nods - www.immolo.co.uk/dev.png www.immolo.co.uk/layout.png
I created the init layout using Code: | mkdir bin dev etc lib mnt proc root sbin sys tmp usr usr/bin usr/sbin var |
Then set the following in my kernel config for ownership and permisions:
Code: |
CONFIG_INITRAMFS_ROOT_UID=1000
CONFIG_INITRAMFS_ROOT_GID=1000
|
This is how I believe it's supposed to be done. |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Sat May 21, 2022 5:38 pm Post subject: |
|
|
immolo,
Roots usual UID/GID are both 0 but in the initrd, there is only root, so it shouldn't matter.
How do you build the initrd?
-- edit --
Unless the initrd has permissions problems becase its built with userID 0 for root and executing with userID 1000, so it has no access to some things. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
pingtoo l33t
Joined: 10 Sep 2021 Posts: 926 Location: Richmond Hill, Canada
|
Posted: Sat May 21, 2022 6:05 pm Post subject: |
|
|
I usually get this error because I did not exec switch_root ... in the interactive shell.
If your rootfs house a Gentoo based stage3 (openrc or systemd), it will manage mount /proc, /sys and /dev. So you should umount them before switch_root.
The reason for your umount fail is because you mount /dev/pts and /sys/kernel/debug.
/dev/pts is really unnecessary. at this point in boot sequence you have nothing will allocate pseudo terminal. May be later you wish to use ssh in initramfs that's when you should mount /dev/pts.
/sys/kernel/debug, unless you plan to go some kind of tuning during initramfs, you don't need that too. |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Sat May 21, 2022 6:09 pm Post subject: |
|
|
pingtoo,
Well caught! _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
Posted: Sat May 21, 2022 8:24 pm Post subject: |
|
|
Pingtoo,
Can't believe I missed that!
This is still saying that /dev is busy though with my init.
Just so you can see the changes I'll show here:
Code: |
#!/bin/busybox sh
/bin/busybox --install -s
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH
#Mount Section
mount -t devtmpfs none /dev
mount -t sysfs none /sys
mount -t proc none /proc
#Load PS2 Modules
depmod
modprobe ps2fb mode_option=640x512i@50
modprobe sif
modprobe iop-memory
modprobe iop-module
modprobe iop-irq
modprobe sd_mod
modprobe ohci-ps2
modprobe ums-usbat
modprobe usbhid
modprobe hid-generic
sleep 5
#Mount USB
mount -t ext4 -o ro /dev/sda2 /mnt || echo "Failed to mount sda2"
sleep 30
exec 0</dev/console
exec 1>/dev/console
exec 2>/dev/console
#Debug
#/bin/sh
#Cleanup
umount /proc
umount /sys
umount /dev
#Boot Root
#init=/sbin/init
exec switch_root /mnt /sbin/init
|
Neddy,
I'm building them into into my kernel as this machine doesn't have a bootloader:
Code: |
export ARCH=mips
export CROSS_COMPILE=mipsr5900el-unknown-linux-gnu-
export INSTALL_MOD_PATH=../initramfs/ps2
export INSTALL_MOD_STRIP=1
make vmlinuz
|
I ran make modules_install previously to have them built into the initramfs just for clarity. |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Sat May 21, 2022 8:45 pm Post subject: |
|
|
immolo,
Grabbing at straws a bit.
Code: | exec 0</dev/console
exec 1>/dev/console
exec 2>/dev/console | That looks harmless but its too late in the proceedings to be useful, sice all you do afterwards is clean up.
It may be worth removing it. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
Posted: Sat May 21, 2022 9:08 pm Post subject: |
|
|
I was having the same thought process and testing this out but now it just seems to hang with no output where it used to give the init error before, I can upload a quick video to YouTube if you think it might shed some light while I try to think of something else. |
|
Back to top |
|
|
pingtoo l33t
Joined: 10 Sep 2021 Posts: 926 Location: Richmond Hill, Canada
|
Posted: Sat May 21, 2022 9:13 pm Post subject: |
|
|
As Neddy point out Code: | exec 0</dev/console
exec 1>/dev/console
exec 2>/dev/console | Mean you current shell session hold open file descriptor (fd) on /dev/console, so your umount /dev likely will fail.
some other initramfs script do that because the redirect stdin/stdout/stderr to file/pipe to log input/output. this is not needed for you since you did none of that redirection.
Do you use serial line to connect your machine? if your kernel command line parameters have console=ttyS<n> you should be fine.
Are you still not able to boot into rootfs? even you failed to umount /dev, it should still let you do switch_root. |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Sat May 21, 2022 9:15 pm Post subject: |
|
|
immolo
It won't do any harm to show us the video.
What are your kernel parameters?
They can be built into the kernel, just like the initrd.
I'm not sure why you need an initrd at all.
Humour me an put your kernel .config file onto a pastebin please. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
pingtoo l33t
Joined: 10 Sep 2021 Posts: 926 Location: Richmond Hill, Canada
|
Posted: Sat May 21, 2022 9:23 pm Post subject: |
|
|
immolo wrote: | I was having the same thought process and testing this out but now it just seems to hang with no output where it used to give the init error before, I can upload a quick video to YouTube if you think it might shed some light while I try to think of something else. |
A simple trick you can do is replace /sbin/init to /bin/sh. As in Code: | mount -t proc proc /mnt/proc
mount -t sys sysfs /mnt/sys
mount -t devtmpfs dev /mnt/dev
exec switch_root /mnt /bin/sh |
This will prove you have some kind storage device mounted on /mnt and it have basic linux file system structure to function and the file system contain /bin/sh, so maybe we can do some debugging from there. |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
Posted: Sat May 21, 2022 9:40 pm Post subject: |
|
|
Neddy,
I've tried to set root=/dev/sda2 in the config but it doesn't seem to do anything, this is one day going to be the base for a LiveUSB for a PS2 so a user can either boot an environment to install to hard drive or just have a base to continue installing on the USB as there is limited ports, so I think I'm going to need to the initram to do UUID detection later on.
Code: | CONFIG_CMDLINE="video=AV-MULTI-OUT:1920x1080@50 root=/dev/sda2" |
Kernel config - https://dpaste.com/9EVLGUR58
Video - https://youtu.be/FYZjGfjA7u4 |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
Posted: Sat May 21, 2022 10:11 pm Post subject: |
|
|
Pingtoo,
Huh, neat. I didn't know you could use switch_root like you could chroot.
When setting it to use /bin/sh then I still get the kernel panic so I used my debug initram and have confirmed the filesystem is mounted and the binaries compatible.
www.immolo.co.uk/chroot.png - I'll include this on the off chance it helps. |
|
Back to top |
|
|
pingtoo l33t
Joined: 10 Sep 2021 Posts: 926 Location: Richmond Hill, Canada
|
Posted: Sat May 21, 2022 10:43 pm Post subject: |
|
|
immolo wrote: | When setting it to use /bin/sh then I still get the kernel panic so I used my debug initram and have confirmed the filesystem is mounted and the binaries compatible.
www.immolo.co.uk/chroot.png - I'll include this on the off chance it helps. | Please help me understand the context and sequence, your use /bin/sh and got kernel panic but you use debug initram and confirm file system is mounted, I don't understand how.
I assume you did boot twice, first time use my suggested trick and got a kernel panic? and what is that kernel panic message? same as before?
Second time you tried with a different initramfs:/init script, this time you got drop to shell than manually mount /dev/sda2 to /mnt, follow by doing my suggested trick and you were able to run the /bin/sh from /dev/sda2?
As the picture you named it as chroot.png, so it is showing you second try as my questions above? or it is a separated session you executed somewhere else (not the PS2 machine)
My time is 6:40PM now. It is my offline hour. I can continue tomorrow if it is not resolved by then. |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
Posted: Sat May 21, 2022 10:52 pm Post subject: |
|
|
Pingtoo,
I have two kernels on my system, one that has an initram that follows what you said about using the switch_root which panics and a second kernel which drops to the busybox sh before the Cleanup line so I could test some items out.
I was trying to paint a picture that the rootfs does mount correct and is usable from a chroot just not when I use switch_root in it.
It's midnight here anyway my friend so you taking a break does me a favour, thanks for all the support so far though. |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Sun May 22, 2022 11:31 am Post subject: |
|
|
immolo,
To chroot sucesfully, you will need /proc and /dev mounted inside the chroot.
Where do your modules
Code: | modprobe sif
modprobe iop-memory
modprobe iop-module
modprobe iop-irq | come from?
What I have in mind is to build a static kernel with a Code: | CONFIG_CMDLINE="video=AV-MULTI-OUT:1920x1080@50 root=/dev/sda2 rootdelay=30 |
I can find all the modules in your kernel except the ones above.
The rootdelay is essential to booting from USB. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
Posted: Sun May 22, 2022 12:00 pm Post subject: |
|
|
Neddy,
I just did the non proc and dev mount for speed
The IOP (Input/Output Processor) modules parts load the firmware to access the MIPS chip that controls USB functions for the PS2 in this case.
I'd need do some research to see if it's possible to build that in as at this point I think it's easier to just use initram. |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Sun May 22, 2022 12:11 pm Post subject: |
|
|
immolo,
In that case, rootdelay=30 on the kernel command line does the wrong thing.
It would delay mounting the initrd as root, which is not what you want. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
immolo Tux's lil' helper
Joined: 11 Feb 2005 Posts: 122
|
Posted: Sun May 22, 2022 12:18 pm Post subject: |
|
|
Neddy,
Well at least this confirms what I thought about the boot process. |
|
Back to top |
|
|
pingtoo l33t
Joined: 10 Sep 2021 Posts: 926 Location: Richmond Hill, Canada
|
Posted: Sun May 22, 2022 5:35 pm Post subject: |
|
|
Below is what I have in mind for testing initramfs's:/init. I did little modify from your script, rearrange /proc mount order and at the end use /bin/sh as first process after switch_root.
Code: | !/bin/busybox sh
/bin/busybox --install -s
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH
#Mount Section
mount -t proc none /proc
mount -t devtmpfs none /dev
mount -t sysfs none /sys
#Load PS2 Modules
depmod
modprobe ps2fb mode_option=640x512i@50
modprobe sif
modprobe iop-memory
modprobe iop-module
modprobe iop-irq
modprobe sd_mod
modprobe ohci-ps2
modprobe ums-usbat
modprobe usbhid
modprobe hid-generic
sleep 5
#Mount USB
mount -t ext4 -o ro /dev/sda2 /mnt || echo "Failed to mount sda2"
sleep 30
#Debug
#/bin/sh
mkdir -p /mnt/proc
mount -o move /proc /mnt/proc
mkdir -p /mnt/sys
mount -o move /sys /mnt/sys
mkdir -p /mnt/dev
mount -o move /dev /mnt/dev
exec switch_root /mnt /bin/sh |
What I don't understand from current situation is how is chroot(1) work whereas switch_root(busybox) does not. because switch_root internally just call chroot(2) than execv(2).
I learn that this thread is discuss how to make switch_root work for Sony PS2 machine, as I search Internet around I found you were following github:/frno7/Installing a PlayStation-2 Linux Initramfs root filesystem.
You have combined two init scripts into one, However the frno7's design is to run entire system in RAM, whereas your intention is to run use secondary storage system, nothing wrong about using secondary storage system to start Gentoo, however I cannot find on github:frno7 about what was used for rootfs, can you share with us what did you load to the /dev/sda2?
Also can you share when you use chroot to the target rootfs, output of follow command Code: | /usr/bin/file /sbin/init | or if /usr/bin/file does not exist try Code: | /usr/bin/ldd /sbin/init |
I like to learn more about target rootfs environment. |
|
Back to top |
|
|
|