Is there a way of booting into single-user mode? Or disabling init.d startup scripts during boot? I've installed a hastily-written script on a Pi running Debian Wheezy which is stopping me getting to the login prompt. Alternatively... is it easy to mount an SD card on a USB reader, I can fix it that way.
any ideas appreciated!
thanks
Re: single-user mode on pi + debian wheezy?
Probably the easiest way is to edit cmdline.txt and add the following parameter
This tells the kernel that once its loaded instead of running /sbin/init as usual you should run /bin/sh. You will get a shell with no services configured, just straight from kernel to shell. This can be done on any computer with a SD card reader as you are only modifying a file in the /boot partition (Fat32). Very simple.
Your userid will be 0 so you will have root permissions, just none of the initd scripts have run. This means you can change passwords, undo modifications that broke your system, etc.
Code: Select all
init=/bin/sh
Your userid will be 0 so you will have root permissions, just none of the initd scripts have run. This means you can change passwords, undo modifications that broke your system, etc.
xmpp: [email protected]
Blog: http://jecxjo.motd.org/code
Blog: http://jecxjo.motd.org/code
Re: single-user mode on pi + debian wheezy?
that's great, I got my pi back! thanks
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
is there a way to disable this?
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
Re: single-user mode on pi + debian wheezy?
How about removing "init=/bin/sh" from cmdline.txt?
(basically undoing what the second post in this topic suggested)
(basically undoing what the second post in this topic suggested)
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
Haha I know that. What I meant is: is it possible to disable single user mode so someone cannot gain access this way.buja wrote:How about removing "init=/bin/sh" from cmdline.txt?
(basically undoing what the second post in this topic suggested)
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
- DougieLawson
- Posts: 42760
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: single-user mode on pi + debian wheezy?
No. If I can pull your SDCard and update it in another system I can break in to your Raspberry Pi and you CAN NOT stop me.electronicsguy wrote:Haha I know that. What I meant is: is it possible to disable single user mode so someone cannot gain access this way.buja wrote:How about removing "init=/bin/sh" from cmdline.txt?
(basically undoing what the second post in this topic suggested)
Lock the RPi in a cage, fix the SDCard in the RPi with a hot glue gun.
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
Thanks Dougie. Is there a reason why linux keeps this single user logon? Since you're from a systems background I'm guessing you know a lot about this. Yes I know, if someone has physical access to a machine, they can do whatever they want with the data. But this just seems to make it easier for them, isn't it?
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
- DougieLawson
- Posts: 42760
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: single-user mode on pi + debian wheezy?
The RPi is unique, you can easily pull the primary data storage device without opening the case. On a secure system you'd a) keep the machine in a secure room, b) not let anyone loose on hardware and c) have a hard drive controller that trashes the data if any tampering occurs.
Remember these things came from the 1960s and 1970s when computers were kept in sealed rooms and "ordinary" users fed their data in on cards, tape or paper tape and came back the next day for the printout when their job had run.
Remember these things came from the 1960s and 1970s when computers were kept in sealed rooms and "ordinary" users fed their data in on cards, tape or paper tape and came back the next day for the printout when their job had run.
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
I understand. My curiosity is: why continue having this in the modern linux architecture. Will a large segment of users be affected if single user mode is disabled today?DougieLawson wrote:The RPi is unique, you can easily pull the primary data storage device without opening the case. On a secure system you'd a) keep the machine in a secure room, b) not let anyone loose on hardware and c) have a hard drive controller that trashes the data if any tampering occurs.
Remember these things came from the 1960s and 1970s when computers were kept in sealed rooms and "ordinary" users fed their data in on cards, tape or paper tape and came back the next day for the printout when their job had run.
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
Re: single-user mode on pi + debian wheezy?
Is there any reason to disable it? Most proper servers are still kept in a secure (or fairly secure) environment. Single user mode is still useful (I use it on a regular basis on one system) for some administration work.electronicsguy wrote:I understand. My curiosity is: why continue having this in the modern linux architecture. Will a large segment of users be affected if single user mode is disabled today?
Oh and i have to disagree with:
because of the number of systems that I have worked with that had drives that could be just pulled out (ok, not when they were running, but you wouldn't normally get away with doing that on a Pi either) and put in another machine to hack settings - if you had physical access to them.DougieLawson wrote:The RPi is unique, you can easily pull the primary data storage device without opening the case.
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
Well if its useful, those sys admins can enable it right? Why have it enabled by default?rpdom wrote:Is there any reason to disable it? Most proper servers are still kept in a secure (or fairly secure) environment. Single user mode is still useful (I use it on a regular basis on one system) for some administration work.electronicsguy wrote:I understand. My curiosity is: why continue having this in the modern linux architecture. Will a large segment of users be affected if single user mode is disabled today?
Oh and i have to disagree with:because of the number of systems that I have worked with that had drives that could be just pulled out (ok, not when they were running, but you wouldn't normally get away with doing that on a Pi either) and put in another machine to hack settings - if you had physical access to them.DougieLawson wrote:The RPi is unique, you can easily pull the primary data storage device without opening the case.
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
- DougieLawson
- Posts: 42760
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: single-user mode on pi + debian wheezy?
It isn't enabled by default, you have to update cmdline.txt to change the init= parm that's passed to the kernel. You need some form of physical security to prevent unauthorised changes to kernel parameters.
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
Sorry that's not what I meant. I meant the ability to use this particular kernel parameter is enabled by default, even if you have to make the manual change to the kernel parameters.DougieLawson wrote:It isn't enabled by default, you have to update cmdline.txt to change the init= parm that's passed to the kernel. You need some form of physical security to prevent unauthorised changes to kernel parameters.
At some point in the kernel code, the kernel looks at these parameters and runs the shell with root privileges instead of init correct? What exactly would break if those lines of code in the kernel were to be commented out?
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
- DougieLawson
- Posts: 42760
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: single-user mode on pi + debian wheezy?
Being able to override the init program is essential. The fact that you can use init=/bin/sh to breach security is an unfortunate side-effect.
It's the least of your problems if you're trying to harden a RPi.
It's the least of your problems if you're trying to harden a RPi.
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
thanksDougieLawson wrote:Being able to override the init program is essential. The fact that you can use init=/bin/sh to breach security is an unfortunate side-effect.
It's the least of your problems if you're trying to harden a RPi.

Now, who exactly is init override beneficial for? If we were to write the linux kernel today, would be still have the option to override it ON by default?
If the benefits are for a large segment of people, noobs and high-end IT sysads included, then it makes sense to continue having it.
If its only beneficial to a small group of people, is it impossible for them to uncomment out those lines and re-compile the kernel for their use? I am assuming that these people can do that, and probably do compile their own kernels all the time for many reasons correct?
btw: for someone wanting to improve security and make it harder to break in, I found this write-up:
http://www.tecmint.com/how-to-hack-your ... ux-system/
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
- DougieLawson
- Posts: 42760
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: single-user mode on pi + debian wheezy?
The trouble is that it's a lifeline, it's the thing you use when the filesystem needs to be fsck'd to recover the system. When you have a system that you can't install a new kernel on but you need it back in a hurry.
The RPF kernel also has the magic SysReq key enabled. You'll probably consider that as another thing you'd like to remove.
It's not ideal, but that's the design for how the kernel passes control to process id #1 which is the first program to run in userland rather than as a kernel driver/module.
The RPF kernel also has the magic SysReq key enabled. You'll probably consider that as another thing you'd like to remove.
It's not ideal, but that's the design for how the kernel passes control to process id #1 which is the first program to run in userland rather than as a kernel driver/module.
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
Thanks again for the explanation. I still don't see why someone like me would need it and why someone like you couldn't have it by compiling your own kernelDougieLawson wrote:The trouble is that it's a lifeline, it's the thing you use when the filesystem needs to be fsck'd to recover the system. When you have a system that you can't install a new kernel on but you need it back in a hurry.
The RPF kernel also has the magic SysReq key enabled. You'll probably consider that as another thing you'd like to remove.
It's not ideal, but that's the design for how the kernel passes control to process id #1 which is the first program to run in userland rather than as a kernel driver/module.

AFAIK, for screwed up partitions/disks, I can fsck by installing it in another machine and we don't need root password of the target disk to fsck it. So IMHO, that part is redundant, unless you want to run fsck on that machine itself, without removing the disk. Which is also possible, by booting through a USB stick containing system rescue cd?
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
Re: single-user mode on pi + debian wheezy?
The Pi can only boot from SD cards initially. The rootfs might be an USB harddrive , but you still need the SD card for bootup.
ghans
ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
Ya, so? I don't think this has anything to do with boot time security.ghans wrote:The Pi can only boot from SD cards initially. The rootfs might be an USB harddrive , but you still need the SD card for bootup.
ghans
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
Re: single-user mode on pi + debian wheezy?
The recovery kernel needs already to be on the SD card if
the Pi is my only Linux machine.
ghans
the Pi is my only Linux machine.
ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
again, so what? btw, it can be on an USB stick too.
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
- ragnarjensen
- Posts: 332
- Joined: Wed May 15, 2013 6:13 pm
- Location: Stockholm, Sweden
Re: single-user mode on pi + debian wheezy?
In my case, the 2.3 million users of the system I oversee. If it goes belly-up, I need to be able to fix it double-quick.electronicsguy wrote:Now, who exactly is init override beneficial for?
I sincerely hope so.If we were to write the linux kernel today, would be still have the option to override it ON by default?
I'm glad you've seen the lightIf the benefits are for a large segment of people, noobs and high-end IT sysads included, then it makes sense to continue having it.

In the corporate world, when you buy a complete system, it's fairly common that you're not allowed to touch the OS.If its only beneficial to a small group of people, is it impossible for them to uncomment out those lines and re-compile the kernel for their use? I am assuming that these people can do that, and probably do compile their own kernels all the time for many reasons correct?
"Oh, you rolled your own kernel? Sorry, then you're not running our distribution any more. Your support contract is now null and void."
Very true. And sometimes it's the other way around. More than once, I have faced the situation where the disks were healthy but the computer itself had died. I plugged the disks into very dissimilar hardware and thanks to single-user mode I was able to reconfigure the systems, to make them able to go multiuser at all on the new hardware.DougieLawson wrote:The trouble is that it's a lifeline, it's the thing you use when the filesystem needs to be fsck'd to recover the system. When you have a system that you can't install a new kernel on but you need it back in a hurry."
Being able to boot to single-user is not a security problem in itself. If I can lay my hands on your console, you have no security.
--
Ragnar
- electronicsguy
- Posts: 156
- Joined: Wed Jan 21, 2015 11:20 pm
Re: single-user mode on pi + debian wheezy?
All points taken. and thanks for highlighting the business side scenarios, of which I have little knowledge.
but at the end of the day, the 'Raspbian' is not a business oriented OS, bound by contracts where you cannot modify the OS. If it is a customized OS designed from Debian by the foundation, why can't we have this implemented as far as Raspbian is concerned. For all business folks bound by contracts, there's always red-hat.
Let me put it this way - what specific purpose is being served by having the capability to modify kernel parameters already baked in, in the Raspbian distro, for its users?
Yes you could lay my hands on my console and get all the data. But AFAIU, isn't it making it easier for you to lay your hands on my Pi, when you may not have your own computer to insert the sd-card into? If this is false, then I rest my case.
but at the end of the day, the 'Raspbian' is not a business oriented OS, bound by contracts where you cannot modify the OS. If it is a customized OS designed from Debian by the foundation, why can't we have this implemented as far as Raspbian is concerned. For all business folks bound by contracts, there's always red-hat.
Let me put it this way - what specific purpose is being served by having the capability to modify kernel parameters already baked in, in the Raspbian distro, for its users?
Yes you could lay my hands on my console and get all the data. But AFAIU, isn't it making it easier for you to lay your hands on my Pi, when you may not have your own computer to insert the sd-card into? If this is false, then I rest my case.
blog: https://electronicsguy.wordpress.com
github: https://github.com/electronicsguy
github: https://github.com/electronicsguy
- ragnarjensen
- Posts: 332
- Joined: Wed May 15, 2013 6:13 pm
- Location: Stockholm, Sweden
Re: single-user mode on pi + debian wheezy?
You're welcomeelectronicsguy wrote:All points taken. and thanks for highlighting the business side scenarios, of which I have little knowledge.

"Oh, you rolled your own kernel? Sorry, then you're not running our distribution any more. Your support contract is now null and void."For all business folks bound by contracts, there's always red-hat.
That is a real quote from a RedHat representative...
The first post in this thread is an excellent example. A simple mistake made the system inaccessible to its owner. Single-user mode made it easy to get control back.Let me put it this way - what specific purpose is being served by having the capability to modify kernel parameters already baked in, in the Raspbian distro, for its users?
Yes, it makes it easier, but not by much, there are other ways in. The SysReq key that Dougie mentions is one. If I'm only after your data and not looking to take control of your computer, I don't need to bring a computer of my own, I'll just steal the SD card and look at it at my leisure afterwards. Or, seeing that your computer is a tiny Pi that fits in my pocket, I'll steal that tooYes you could lay my hands on my console and get all the data. But AFAIU, isn't it making it easier for you to lay your hands on my Pi, when you may not have your own computer to insert the sd-card into?

--
Ragnar