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

rd.live.ram=1 may fill up /run if tmpfs is too small #2550

Open
cbs228 opened this issue Nov 4, 2023 · 5 comments · May be fixed by #2551
Open

rd.live.ram=1 may fill up /run if tmpfs is too small #2550

cbs228 opened this issue Nov 4, 2023 · 5 comments · May be fixed by #2551
Labels
bug Our bugs

Comments

@cbs228
Copy link

cbs228 commented Nov 4, 2023

Describe the bug
Many distros now cap the total size of the /run filesystem at a relatively small percentage of RAM. For example, Fedora Security Live F38 on a VM with 4 GB of RAM caps /run at only 779.89 MB. This is not enough to contain the complete ISO when rd.live.ram=1 is requested. When dracut writes the rootfs image to /run/initramfs/squashed.img, it fills up /run and fails the boot.

Distribution used
Fedora Security Live F38

Dracut version
059-2.fc38

Init system
systemd-253.2-1.fc38

To Reproduce

  1. Obtain Fedora-Security-Live-x86_64-38-1.6.iso
  2. Configure a VM in GNOME Boxes or libvirt with 4000 MB of RAM
  3. At the GRUB2 menu, choose a normal boot option like "Start Fedora-Security Live 38." Press e to edit the boot options. Add rd.live.ram=1 rd.break rd.shell to the end of the linux options line. Press ctrl-x to boot.
  4. Observe that dracut fails to mount the rootfs because mount can't recognize the filesystem.
  5. Run
    echo "something something something" >/run/initramfs/testfile
    and verify that a no space left on device error occurs. Also verify that /run/initramfs/squashed.img is smaller than it should be.
  6. tmpfs size may be queried with
    cat /proc/self/mountinfo

Expected behavior
I believe that dracut dmsquash-live and livenet should either:

  • Create a tmpfs just for squashed.img that is large enough to contain it; OR
  • Resize the existing tmpfs for /run so that it is large enough to contain squashed.img.

Without changes to dracut, distros that want to support rd.live.ram will need to ensure that /run/initramfs is large enough.

Additional context
Requesting rd.live.ram=1 on a system with not enough memory may put the system under severe memory pressure. #2344 adds the capability to check for this, and we probably don't need to second-guess this check.

The tmpfs(5) default size is 50% of memory. The default size should be large enough on most modern hardware to contain a live image of "reasonable" size. It is clear that some distos opt for a lower size limit for /run.

See also downstream bug RH-2035641

@cbs228 cbs228 added the bug Our bugs label Nov 4, 2023
@cbs228 cbs228 changed the title rd.live.ram=1 may fill up /run if filesystem is too small rd.live.ram=1 may fill up /run if tmpfs is too small Nov 4, 2023
@Athwale
Copy link

Athwale commented Apr 5, 2024

This is also a problem when you have rd.writable.fsimg=1
This option copies the rootfs.img into /run, this image can be very large.

It used to run fine on f38 but no longer works on f39.
The /run should be resized automatically to fit the image when writable.fsimg is used otherwise you get "no space left on device"

@Athwale
Copy link

Athwale commented Apr 6, 2024

If you are experiencing this issue and need to temporarily fix it until dracut has a more permanent solution, you can create a custom dracut module, that remounts /run at the size you need like this:

File: module-setup.sh, executable:

#!/bin/bash

check() {
    return 0
}

depends() {
    return 0
}

install() {
    inst_hook pre-udev 10 "$moddir/run-remount.sh" 
}

File run-remount.sh, executable:

#!/bin/sh
# Append emergency_shell to debug.

SIZE="16000M"
echo "Mounting /run with $SIZE" > /dev/kmsg
mount -t tmpfs -o remount,mode=755,rw,nosuid,nodev,size="$SIZE",nr_inodes=819200,inode64 tmpfs /run
mkdir /usr/lib/dracut/modules.d/90dmsquash-a
mv run-remount.sh /usr/lib/dracut/modules.d/90dmsquash-a
mv module-setup.sh /usr/lib/dracut/modules.d/90dmsquash-a
echo 'add_dracutmodules+=dmsquash-a' >> /etc/dracut.conf.d/remount.conf

Then when dracut runs it will pick up the new module and during boot remount /run with the size of 16GB.

@LaszloGombos
Copy link
Collaborator

Perhaps #2551

@Athwale
Copy link

Athwale commented Apr 6, 2024

I tested the #2551 and it does not solve the problem with rd.writable.fsimg=1

In 90dmsquash-live module in dmsquash-live-root.sh
The code that uses the new function is:

fi
if [ -e "$SQUASHED" ]; then
    if [ -n "$live_ram" ]; then
        imgsize=$(($(stat -c %s -- $SQUASHED) / (1024 * 1024)))
        check_live_ram $imgsize
        echo 'Copying live image to RAM...' > /dev/kmsg
        echo ' (this may take a minute)' > /dev/kmsg
        dd if=$SQUASHED of=/run/initramfs/squashed.img bs=512 2> /dev/null
        echo 'Done copying live image to RAM.' > /dev/kmsg
        SQUASHED="/run/initramfs/squashed.img"
    fi
...

This only takes care of the squashfs.img

But writable.fsimg which is a little lower in the file does not use it and the cp command will fail:

if [ -n "$FSIMG" ]; then
    if [ -n "$writable_fsimg" ]; then
        # mount the provided filesystem read/write
        echo "Unpacking live filesystem (may take some time)" > /dev/kmsg
        mkdir -m 0755 -p /run/initramfs/fsimg/
        if [ -n "$SQUASHED" ]; then
            cp -v $FSIMG /run/initramfs/fsimg/rootfs.img
        else
            unpack_archive $FSIMG /run/initramfs/fsimg/
        fi
        FSIMG=/run/initramfs/fsimg/rootfs.img
    fi

@LaszloGombos
Copy link
Collaborator

LaszloGombos commented Apr 6, 2024

Thanks for helping. I misspoke earlier, this is the one I wanted to point out - #2604

CC @FGrose

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

Successfully merging a pull request may close this issue.

3 participants