tiny-initramfs icon indicating copy to clipboard operation
tiny-initramfs copied to clipboard

Add run_hook for root LABEL using blkid (without udev)

Open mibodhi opened this issue 2 years ago • 0 comments

Hi Chris,

Any chance that booting with root LABEL can be added to run_hook() in /usr/share/tiny-initramfs/functions?

Here is a quite robust method using blkid (no udev involved).

https://unix.stackexchange.com/questions/352381/how-to-boot-into-root-btrfs-file-system-with-minimal-initramfs-without-udev-hook/352932#answer-352932

run_hook () {
    local dev timeout sleepval device=$root
    # if udev is running then exit
    [ "$udevd_running" -eq 1 ] && return
    # try for (timeout * sleepval =) 10 seconds to handle slow (USB) devices
    timeout=1000
    sleepval=0.01

    case $device in
        # label to resolve, when resolved the kernel block device also exists
        UUID=*|LABEL=*|PARTUUID=*|PARTLABEL=*)
            while [ $timeout -gt 0 ]; do
                timeout=$((timeout - 1))
                dev=$(blkid -lt "$device" -o device)
                [ -n "$dev" ] && timeout=0 || sleep $sleepval
            done
            ;;
        # kernel named block device, poll for existence
        /dev/*)
            while [ $timeout -gt 0 ]; do
                timeout=$((timeout -1))
                if [ -b "$device" ]; then
                    dev=$device
                    timeout=0
                else
                    sleep $sleepval
                fi
            done
            ;;
    esac
}

Thanks, bodhi

mibodhi avatar Jul 25 '22 03:07 mibodhi