[klibc] Custom kinit to find device by "label"

maximilian attems max at stro.at
Tue Aug 14 12:46:19 PDT 2007


On Tue, 24 Jul 2007, noneya biz wrote:

> function FindRootDeviceByLabel(const RootFSLabel: string): boolean;
> const
>   DEV_MAJOR: dev_t = 8;
>   DEV_MODE: mode_t = S_IFBLK or &0660;
> var
>   ActualFSLabel: string;
>   FileDescriptor: cint;
>   ReadBytes: TsSize;
>   DeviceFound: boolean;
>   dev_minor: dev_t;
> begin
>   Result := False;
>   SetLength(ActualFSLabel, Length(RootFSLabel));
> 
>   //loop through all devices that might have our root filesystem sda2 to sdp2
>   dev_minor := 2;
>   while dev_minor < 243 do begin // last one is 242
>     if mknod(DEVICENAME, DEV_MODE, (DEV_MAJOR shl 8) or dev_minor) = 0 then
>     begin
>       WriteLn('Created device node "', DEVICENAME, '". dev_minor = ',
> dev_minor);
>     end
>     else begin
>       WriteError('mknod with dev_minor:  ' + IntToStr(dev_minor));
>       EXIT; //exit w/ error
>     end;
>     dev_minor := dev_minor + 16;
> 
>     FileDescriptor := FpOpen(DEVICENAME, 0, 0);
>     if FileDescriptor >= 0 then begin
>       WriteLn('Opened device:  ', DEVICENAME);
>       ReadBytes := FpPRead(FileDescriptor,
>         PChar(ActualFSLabel), Length(ActualFSLabel), $478);
>       if (ReadBytes = Length(ActualFSLabel)) then begin
>         if (ActualFSLabel = RootFSLabel) then begin
>           Result := True;
>           DeviceFound := True;
>         end;
>       end

that can be done easier vol_id from udev will print your the UUID
or the LABEL of the fs. also udev directly sets up the symlinks
under /dev/disk/. :)

i don't have a big kinit love so i don't know where it fails,
but from the resume binary irc it would be in name_to_dev_t()
need to dig anyway if we support resume with boot_arg UUID=$fun_hash, ah

case $resume in
        LABEL=*)
        resume="/dev/disk/by-label/${resume#LABEL=}"
        ;;
        UUID=*)
        resume="/dev/disk/by-uuid/${resume#UUID=}"
        ;;
esac
..
/bin/resume ${resume}

need to check if that really works.


>       else WriteError('Reading from device:  ' + DEVICENAME);
> 
>       WriteLn('Closing device:  ', DEVICENAME);
>       if FpClose(FileDescriptor) <> 0 then
>         WriteError('Closing device:  ' + DEVICENAME);
> 
>       if DeviceFound then BREAK;
>     end
>     else WriteError('Opening device:  ' + DEVICENAME);
> 
>     //Delete the device so we can try again
>     WriteLn('Deleting device we created:  ', DEVICENAME);
>     if Fpunlink(DEVICENAME) <> 0 then
>       WriteError('Deleting device:  ' + DEVICENAME);
>   end; // while dev_minor < 243
> end;


regards

-- 
maks



More information about the klibc mailing list