View previous topic :: View next topic |
Author |
Message |
missinghell n00b

Joined: 04 Dec 2022 Posts: 4
|
Posted: Sun Dec 04, 2022 12:55 pm Post subject: Building an initramfs, but switch_root hangs |
|
|
I am building an initramfs which mounts an LVM thin partition, mounts a squashFS from it and copies the contents over to the real root LV. This works fine when I only mount the rootfs LV and the roots LV, as shown in this init script which works (some functions have been taken out as they are not relevant, for example the break_requested function):
Code: |
# Mount the /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
modprobe dm_thin_pool
modprobe squashfs
modprobe virtio_scsi
modprobe loop
# Do your stuff here.
echo "Xenia Linux initramfs, custom-built by Luna! (it's just a script.)"
echo "Finding LVM..."
lvm vgscan --mknodes
lvm lvchange -a ly vg0/roots
lvm vgscan --mknodes
lvm lvchange -a ly vg0/rootfs
lvm vgscan --mknodes
echo "Mounting (empty) root..."
mount /dev/mapper/vg0-rootfs /mnt/root
echo "Mounted empty root."
echo "Mounting roots volume and squashfs..."
# Mount the root filesystem.
mount /dev/mapper/vg0-roots /mnt/roots
mount /mnt/roots/root.img /mnt/tmp-root -t squashfs -o loop,ro
echo "Mounted roots volume and squasfs to temporary dir."
echo "Extracting squashfs... (this may take a while)"
cp -a /mnt/tmp-root/* /mnt/root
echo "Extracted squashfs."
#/bin/busybox sh # bad debug, drops to shell lol
if [[ -n "$(break_requested)" ]] ; then
/bin/busybox sh
fi
echo "Unmounting everything."
# Clean up.
umount /mnt/tmp-root
umount /mnt/roots
umount /proc
umount /sys
umount /dev
echo "Switching root to Xenia linux. See you there!"
# Boot the real thing.
exec switch_root /mnt/root /sbin/init || rescue_shell
|
This works and loads in to the OS. However, var is on another LV so I added some more code to mount var and now switch_root hangs. This was similar to when I didn't unmount an LV before, and switch_root would hang, but this time I have made sure everything is unmounted, yet it just hangs with no message at all. Here is the init that doesn't work:
Code: |
# Mount the /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
modprobe dm_thin_pool
modprobe squashfs
modprobe virtio_scsi
modprobe loop
# Do your stuff here.
echo "Xenia Linux initramfs, custom-built by Luna! (it's just a script.)"
echo "Finding LVM..."
lvm vgscan --mknodes
lvm lvchange -a ly vg0/roots
lvm vgscan --mknodes
lvm lvchange -a ly vg0/rootfs
lvm vgscan --mknodes
lvm lvchange -a ly vg0/var
lvm vgscan --mknodes
echo "Mounting (empty) root..."
mount /dev/mapper/vg0-rootfs /mnt/root
echo "Mounted empty root."
echo "Mounting roots volume and squashfs..."
# Mount the root filesystem.
mount /dev/mapper/vg0-roots /mnt/roots
mount /mnt/roots/root.img /mnt/tmp-root -t squashfs -o loop,ro
echo "Mounted roots volume and squasfs to temporary dir."
echo "Deleting any existing root..."
rm -rf /mnt/root/*
echo "Deleted existing root."
echo "Mounting var..."
mkdir /mnt/root/var
mount /dev/mapper/vg0-var /mnt/root/var
echo "Mounted var."
echo "Extracting squashfs... (this may take a while)"
cp -a /mnt/tmp-root/* /mnt/root
echo "Extracted squashfs."
#/bin/busybox sh # bad debug, drops to shell lol
if [[ -n "$(break_requested)" ]] ; then
/bin/busybox sh
fi
echo "Unmounting everything."
# Clean up.
umount /mnt/tmp-root
umount /mnt/roots
umount /mnt/root/var
umount /proc
umount /sys
umount /dev
echo "Switching root to Xenia linux. See you there!"
# Boot the real thing.
exec switch_root /mnt/root /sbin/init || rescue_shell
|
I can't see why adding this causes switch_root to hang. There's no output after the Switching root echo, and all I see is a blinking cursor. What have I done wrong?
The code is stored in this repo for anyone interested: Repo |
|
Back to top |
|
 |
pingtoo Veteran


Joined: 10 Sep 2021 Posts: 1660 Location: Richmond Hill, Canada
|
Posted: Sun Dec 04, 2022 2:55 pm Post subject: |
|
|
missinghell,
English is not my first language so I just want to confirm if my understanding of your post is correct.
Are you saying the first script in your post work correctly as you expected and the second script in your post does not work as you expect?
If my understand correct, than I have question for you, is content of your squashfs is Gentoo based system? and are your using OpenRC as your Init system? or is it systemd based?
It is possible what is in your squashfs content does not match your kernel version so some critical modules were not able to load therefor nothing show in console.
Also is it possible to change your second script that after your unmount everything just before your switch_root, drop to shell and review what is in /mnt/toot? |
|
Back to top |
|
 |
Leonardo.b Guru

Joined: 10 Oct 2020 Posts: 308
|
Posted: Sun Dec 04, 2022 3:23 pm Post subject: Re: Building an initramfs, but switch_root hangs |
|
|
missinghell, welcome to the forums.
Squash filesystem is often used to dump / in RAM.
Extracting its contents to disk kinda defeats its purpouse.
What do you want to do? Why?
Thete may be a simpler solution. |
|
Back to top |
|
 |
missinghell n00b

Joined: 04 Dec 2022 Posts: 4
|
Posted: Sun Dec 04, 2022 4:00 pm Post subject: |
|
|
pingtoo wrote: | missinghell,
English is not my first language so I just want to confirm if my understanding of your post is correct.
Are you saying the first script in your post work correctly as you expected and the second script in your post does not work as you expect?
If my understand correct, than I have question for you, is content of your squashfs is Gentoo based system? and are your using OpenRC as your Init system? or is it systemd based?
It is possible what is in your squashfs content does not match your kernel version so some critical modules were not able to load therefor nothing show in console.
Also is it possible to change your second script that after your unmount everything just before your switch_root, drop to shell and review what is in /mnt/toot? |
Yes, the first initramfs works fine and the second just hangs. The squashFS is a gentoo system, and I used the same one to test both initramfs images, so I know the root image itself is fine. It is OpenRC based. I have dropped to a shell, /mnt/root is what I expect with the rootFS unpacked, the same as with the first initramfs. |
|
Back to top |
|
 |
missinghell n00b

Joined: 04 Dec 2022 Posts: 4
|
Posted: Sun Dec 04, 2022 4:02 pm Post subject: Re: Building an initramfs, but switch_root hangs |
|
|
Leonardo.b wrote: | missinghell, welcome to the forums.
Squash filesystem is often used to dump / in RAM.
Extracting its contents to disk kinda defeats its purpouse.
What do you want to do? Why?
Thete may be a simpler solution. |
Essentially I have an LV which contains the root images, eventually it will be able to select one at boot. I want to do it this way so you can update the root image by just replacing the file in the LV. I'm using squashFS because its convenient and did work before the changes I made. It would be the same as doing it as a tar, just I decided to use a squashFS because I knew how to use them. I don't think the squashFS is causing the issue here. |
|
Back to top |
|
 |
missinghell n00b

Joined: 04 Dec 2022 Posts: 4
|
Posted: Sun Dec 04, 2022 5:10 pm Post subject: |
|
|
I have managed to fix this. I added commands in my init to delete the existing rootFS on boot, and for some reason that was causing switch_root to hang. I'm not sure why this is causing switch_root to hang, and I will have to find a workaround eventually, but this works for now. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|