Hi Sergey

On Fri, May 19, 2023 at 4:02 AM Sergey Bugaev <buga...@gmail.com> wrote:

> Hi,
>
> On Fri, May 19, 2023 at 9:43 AM Flávio Cruz <flavioc...@gmail.com> wrote:
> > I have made changes so that it does daily builds and I'm able to boot
> small programs. However, I haven't had the time to boot programs built
> against Glibc. How do you package and boot the static binaries using a
> ramdisk? I've been reading the other threads about the Guix/rumpkernel so I
> might be able to piece something together and try it this weekend.
>
> You just put the entirety of the root filesystem (containing /usr,
> /bin, /lib, /hurd, and so on) as an ext2 image into a *file* that you
> place onto the actual drive (a CD disk in my case), and then you ask
> GRUB to load the file from the drive into memory, tell gnumach to make
> a ramdisk device out of it (you'll need to apply [0]), and tell ext2fs
> to use that device. Here's the relevant piece of my grub config
> script:
>
> [0]:
> https://salsa.debian.org/hurd-team/gnumach/-/blob/master/debian/patches/50_initrd.patch
>
> multiboot /boot/gnumach console=com0
> module /boot/initrd.ext2 initrd.ext2 '$(ramdisk-create)'
> module /sbin/ext2fs.static ext2fs
> --multiboot-command-line='${kernel-command-line}' --readonly
> --host-priv-port='${host-port}' --device-master-port='${device-port}'
> --exec-server-task='${exec-task}' --kernel-task='${kernel-task}' -T
> device rd0 '$(fs-task=task-create)' '$(prompt-task-resume)'
> module /lib/ld.so.1 ld.so.1 /hurd/exec
> --device-master-port='${device-port}' '$(exec-task=task-create)'
> boot
>
> (I should probably change it to not hardcode 'rd0', but whatever).
> Note that /boot/gnumach, /boot/initrd.ext2, /sbin/ext2fs.static, and
> /lib/ld.so.1 are all paths inside the CD image (those are going to be
> loaded by GRUB), and /boot/initrd.ext2 is the ext2 filesystem image
> containing the actual Hurd root. /hurd/exec however is already a path
> inside the fs image -- this is where ld.so (not grub) is going to load
> the exec server from. The only static binary here is ext2fs.static,
> the rest are all dynamically linked.
>
> Then in /libexec/console-run (inside the filesystem image), I have
> written the following:
>
> #! /bin/sh
>
> settrans -ac /dev/mach-console /hurd/streamio console
> exec <>/dev/mach-console >&0 2>&0
> echo Hello from /bin/sh!
> exec /bin/sh -i
>
> (If you're going to do the same, don't forget to create the
> /dev/mach-console node beforehand, since the fs is read-only.) I also
> had to patch streamio a little to do the \r -> \n conversion like
> glibc already does in devstream:
>
> diff --git a/trans/streamio.c b/trans/streamio.c
> index 272a002c..0af1aea3 100644
> --- a/trans/streamio.c
> +++ b/trans/streamio.c
> @@ -500,6 +500,9 @@ trivfs_S_io_read (struct trivfs_protid *cred,
>                   cred->po->openmodes & O_NONBLOCK);
>    pthread_mutex_unlock (&global_lock);
>    *data_len = data_size;
> +  for (size_t i = 0; i < data_size; i++)
> +    if ((*data)[i] == '\r')
> +      (*data)[i] = '\n';
>    return err;
>  }
>
> (maybe I should also add echoing of input characters in the same way,
> which is also what glibc's devstream does -- otherwise currently I
> don't see what I'm typing on the console).
>
> Make sure to use the very latest glibc (Samuel has already pushed all
> of my patches upstream!) + the BRK_START hack.
>

Thanks for the instructions. I was able to make it work and pushed my
changes to Github.

For people that might want to try out the new port using
https://github.com/flavioc/cross-hurd,
the following will download the packages and build a disk image with the
ram disk:

$ export CPU=x86_64
$ bash download.sh && bash bootstrap.sh && bash compile.sh && bash
create-initrd.sh

Then, to run qemu:

$ bash start-qemu-debug.sh


> Sergey
>

Reply via email to