reboot PC

How can I reboot a PC from the kernel? My driver performs some work during OS boot and I need to reboot so my modifications take effect.

Thanks,
Roman

First you cannot reboot safely from the kernel, if you do you bypass all the
user space environment handling, so can corrupt things. Secondly, this is a
lousy idea to begin with, Microsoft has been hammiering people for more than
five years now to get rid of required reboots, what are you doing that make
you think this is needed or justified.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

“Roman Kudinov” wrote in message news:xxxxx@ntdev…
How can I reboot a PC from the kernel? My driver performs some work during
OS boot and I need to reboot so my modifications take effect.

Thanks,
Roman

Hello Burn,

We modify partition table and the modifications are not applied until we
reboot Windows. We use IoWritePartitionTable routine to write the partition
table but it doesn’t have effect.

As soon as user space is not loaded and even file systems are not loaded
(except the boot FS of course) at the moment when I want to reboot I think
that nothing will be corrupted.

Thank you,
Roman

“Don Burn” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:xxxxx@ntdev…
> First you cannot reboot safely from the kernel, if you do you bypass all
the
> user space environment handling, so can corrupt things. Secondly, this is
a
> lousy idea to begin with, Microsoft has been hammiering people for more
than
> five years now to get rid of required reboots, what are you doing that
make
> you think this is needed or justified.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
>
>
> “Roman Kudinov” wrote in message news:xxxxx@ntdev…
> How can I reboot a PC from the kernel? My driver performs some work during
> OS boot and I need to reboot so my modifications take effect.
>
>
> Thanks,
> Roman
>
>
>

Roman,

I agree with Don - avoid reboots if at all possible and never reboot from kernel mode. You’ll end up corrupting data or system state. I looked at doing this once - it’s just plain ugly.

However, if you can’t avoid the issue (*), you can reboot from user-mode by writing a simple service that sends an IRP to and waits for your driver to reply. Then have your service obtain the SE_SHUTDOWN_NAME privilege and call InitiateSystemShutdown() or InitiateSystemShutdownEx() system services. Longer term look at what you can do to eliminate the reboot entirely.

Mike

(*) Note: I couldn’t due avoid this issue once due to a hardware bug that infrequently appeared on a cold boot and required a warm reboot / PCI bus reset to clear the condition.
“Roman Kudinov” wrote in message news:xxxxx@ntdev…
How can I reboot a PC from the kernel? My driver performs some work during OS boot and I need to reboot so my modifications take effect.

Thanks,
Roman

Roman,
Sorry, I was posting my previous reply while you were posting yours. I’m
not sure my suggestion will work given how early in system initialization
you plan to reboot. I.e. there won’t be any user-mode services running at
this instant.

Perhaps two other comments for others who might consider the user-mode
shutdown approach:
(1) dwTimeout should be be on the order of 30 to 60 seconds in case you
want to abort the shutdown for some reason. (2) One can abort a system
shutdown from a command window with the incantation “shutdown /a”.

Mike

“Roman Kudinov” wrote in message news:xxxxx@ntdev…
> Hello Burn,
>
> We modify partition table and the modifications are not applied until we
> reboot Windows. We use IoWritePartitionTable routine to write the
> partition
> table but it doesn’t have effect.
>
> As soon as user space is not loaded and even file systems are not loaded
> (except the boot FS of course) at the moment when I want to reboot I think
> that nothing will be corrupted.
>
>
> Thank you,
> Roman
>
>
> “Don Burn” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
> news:xxxxx@ntdev…
>> First you cannot reboot safely from the kernel, if you do you bypass all
> the
>> user space environment handling, so can corrupt things. Secondly, this
>> is
> a
>> lousy idea to begin with, Microsoft has been hammiering people for more
> than
>> five years now to get rid of required reboots, what are you doing that
> make
>> you think this is needed or justified.
>>
>>
>> –
>> Don Burn (MVP, Windows DDK)
>> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> Remove StopSpam from the email to reply
>>
>>
>>
>> “Roman Kudinov” wrote in message news:xxxxx@ntdev…
>> How can I reboot a PC from the kernel? My driver performs some work
>> during
>> OS boot and I need to reboot so my modifications take effect.
>>
>>
>> Thanks,
>> Roman
>>
>>
>>
>
>
>

The undocumented NtShutdownSystem syscall.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Roman Kudinov”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Monday, December 19, 2005 4:42 PM
Subject: [ntdev] reboot PC

How can I reboot a PC from the kernel? My driver performs some work during OS
boot and I need to reboot so my modifications take effect.

Thanks,
Roman

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

> We modify partition table and the modifications are not applied until we

reboot Windows. We use IoWritePartitionTable routine

Wrong, use IOCTL_DISK_SET_DRIVE_LAYOUT. Disk.sys itself is the only valid
caller of IoWritePartitionTable.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Thank you, I wonder if IoWritePartitionTable works directly with the sectors

“Maxim S. Shatskih” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
ÓÌÅÄÕÀÝÅÅ: news:xxxxx@ntdev…
> > We modify partition table and the modifications are not applied until we
> > reboot Windows. We use IoWritePartitionTable routine
>
> Wrong, use IOCTL_DISK_SET_DRIVE_LAYOUT. Disk.sys itself is the only valid
> caller of IoWritePartitionTable.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>

IoWritePartitionTable does the following:

  • converts DRIVE_LAYOUT_INFORMATION to MBR sectors
  • writes these sectors

This is provided for Disk.sys only. The partitioning tools should do
IOCTL_DISK_SET_DRIVE_LAYOUT.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Roman Kudinov”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Thursday, December 22, 2005 7:51 PM
Subject: Re:[ntdev] Re:reboot PC

> Thank you, I wonder if IoWritePartitionTable works directly with the sectors
>
>
> “Maxim S. Shatskih” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
> ÓÌÅÄÕÀÝÅÅ: news:xxxxx@ntdev…
> > > We modify partition table and the modifications are not applied until we
> > > reboot Windows. We use IoWritePartitionTable routine
> >
> > Wrong, use IOCTL_DISK_SET_DRIVE_LAYOUT. Disk.sys itself is the only valid
> > caller of IoWritePartitionTable.
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
> >
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com