How do you completely switch the root files system on Linux?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I am running my rootfs on a flash device (MTD device with UBIFS) - Note: it's a bitbake system so its not full-blown ubuntu or anything.
I want to be able to format that device and write a new rootfs to it, and so I need to ubidetach
this device, which I can do, but in order to do that I have to kill off every process/shell/app, etc... that ever lived - i.e. a similar list to if you do:
fuser -vm /dev
.
So my attempt so far (that does work to a degree) is using pivot_root where I do the following:
- Copy the bin, sbin, lib etc... into my new /tmp_root/ folder
- Mount/bind /proc, /sys, dev, run into /tmp_root/
- Call pivot_root
- Unmount everything from oldroot
- Kill of all processes that are related to oldroot/dev
- unmount oldroot
This works ok - and at this point I can detatch the UBIFS an flash the MTD device. However I have had to kill off all the apps that are runnings - which is not very useful!
So, what I want to do is (at least as a trial) instead of pivot_root
do a switch_root
, or some such, and then I can run up all my apps AND (hopfully) flash the MTD device. Normally this is initramtfs
(or so I have read), but in my case I just want to do some testing and switch file system on an already running rootfs.
With the same /tmp_root
folder that I created I have tried:
exec switch_root /tmp_root /sbin/init
exec -c /dev/console switch_root /tmp_root /sbin/init
But I always get the same sort of result somthing like:
old root filesystem is not an initramfs: invalid argument
I am a bit stuck, is it even possible to completely switch the rootfs once the system is up and running?
note: running linux kernel 4.1.x
linux initramfs root-filesystem ubifs
add a comment |Â
up vote
2
down vote
favorite
I am running my rootfs on a flash device (MTD device with UBIFS) - Note: it's a bitbake system so its not full-blown ubuntu or anything.
I want to be able to format that device and write a new rootfs to it, and so I need to ubidetach
this device, which I can do, but in order to do that I have to kill off every process/shell/app, etc... that ever lived - i.e. a similar list to if you do:
fuser -vm /dev
.
So my attempt so far (that does work to a degree) is using pivot_root where I do the following:
- Copy the bin, sbin, lib etc... into my new /tmp_root/ folder
- Mount/bind /proc, /sys, dev, run into /tmp_root/
- Call pivot_root
- Unmount everything from oldroot
- Kill of all processes that are related to oldroot/dev
- unmount oldroot
This works ok - and at this point I can detatch the UBIFS an flash the MTD device. However I have had to kill off all the apps that are runnings - which is not very useful!
So, what I want to do is (at least as a trial) instead of pivot_root
do a switch_root
, or some such, and then I can run up all my apps AND (hopfully) flash the MTD device. Normally this is initramtfs
(or so I have read), but in my case I just want to do some testing and switch file system on an already running rootfs.
With the same /tmp_root
folder that I created I have tried:
exec switch_root /tmp_root /sbin/init
exec -c /dev/console switch_root /tmp_root /sbin/init
But I always get the same sort of result somthing like:
old root filesystem is not an initramfs: invalid argument
I am a bit stuck, is it even possible to completely switch the rootfs once the system is up and running?
note: running linux kernel 4.1.x
linux initramfs root-filesystem ubifs
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am running my rootfs on a flash device (MTD device with UBIFS) - Note: it's a bitbake system so its not full-blown ubuntu or anything.
I want to be able to format that device and write a new rootfs to it, and so I need to ubidetach
this device, which I can do, but in order to do that I have to kill off every process/shell/app, etc... that ever lived - i.e. a similar list to if you do:
fuser -vm /dev
.
So my attempt so far (that does work to a degree) is using pivot_root where I do the following:
- Copy the bin, sbin, lib etc... into my new /tmp_root/ folder
- Mount/bind /proc, /sys, dev, run into /tmp_root/
- Call pivot_root
- Unmount everything from oldroot
- Kill of all processes that are related to oldroot/dev
- unmount oldroot
This works ok - and at this point I can detatch the UBIFS an flash the MTD device. However I have had to kill off all the apps that are runnings - which is not very useful!
So, what I want to do is (at least as a trial) instead of pivot_root
do a switch_root
, or some such, and then I can run up all my apps AND (hopfully) flash the MTD device. Normally this is initramtfs
(or so I have read), but in my case I just want to do some testing and switch file system on an already running rootfs.
With the same /tmp_root
folder that I created I have tried:
exec switch_root /tmp_root /sbin/init
exec -c /dev/console switch_root /tmp_root /sbin/init
But I always get the same sort of result somthing like:
old root filesystem is not an initramfs: invalid argument
I am a bit stuck, is it even possible to completely switch the rootfs once the system is up and running?
note: running linux kernel 4.1.x
linux initramfs root-filesystem ubifs
I am running my rootfs on a flash device (MTD device with UBIFS) - Note: it's a bitbake system so its not full-blown ubuntu or anything.
I want to be able to format that device and write a new rootfs to it, and so I need to ubidetach
this device, which I can do, but in order to do that I have to kill off every process/shell/app, etc... that ever lived - i.e. a similar list to if you do:
fuser -vm /dev
.
So my attempt so far (that does work to a degree) is using pivot_root where I do the following:
- Copy the bin, sbin, lib etc... into my new /tmp_root/ folder
- Mount/bind /proc, /sys, dev, run into /tmp_root/
- Call pivot_root
- Unmount everything from oldroot
- Kill of all processes that are related to oldroot/dev
- unmount oldroot
This works ok - and at this point I can detatch the UBIFS an flash the MTD device. However I have had to kill off all the apps that are runnings - which is not very useful!
So, what I want to do is (at least as a trial) instead of pivot_root
do a switch_root
, or some such, and then I can run up all my apps AND (hopfully) flash the MTD device. Normally this is initramtfs
(or so I have read), but in my case I just want to do some testing and switch file system on an already running rootfs.
With the same /tmp_root
folder that I created I have tried:
exec switch_root /tmp_root /sbin/init
exec -c /dev/console switch_root /tmp_root /sbin/init
But I always get the same sort of result somthing like:
old root filesystem is not an initramfs: invalid argument
I am a bit stuck, is it even possible to completely switch the rootfs once the system is up and running?
note: running linux kernel 4.1.x
linux initramfs root-filesystem ubifs
linux initramfs root-filesystem ubifs
edited Oct 4 at 11:17
asked Oct 4 at 10:24
code_fodder
1235
1235
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
INFO:
switch_root
switch_root moves already mounted /proc, /dev, /sys and /run to
newroot and makes newroot the new root filesystem and starts init
process.
init
The program init is the process with process ID 1. It is responsible
for initializing the system in the required way. init is started
directly by the kernel and resists signal 9, which normally kills
processes. All other programs are either started directly by init or
by one of its child processes.
Any programs, daemons, modules (?) started before switch_root
is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.
You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.
"I want to be able to format that device and write a new rootfs to it"
Assume you have the new rootfs built already and ready to "install".
After you format how will you boot into this? Is this why you want to switch_root because it is already booted?
If yes switch_root may not be the tool you need.
Other tools that may allow you to format and copy your new rootfs.
- Your boot loader.
- A live linux distro installed on a bootable USB.
- A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.
- Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.
- Network boot ether PXE or even a NFS.
Does this help at all?
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
INFO:
switch_root
switch_root moves already mounted /proc, /dev, /sys and /run to
newroot and makes newroot the new root filesystem and starts init
process.
init
The program init is the process with process ID 1. It is responsible
for initializing the system in the required way. init is started
directly by the kernel and resists signal 9, which normally kills
processes. All other programs are either started directly by init or
by one of its child processes.
Any programs, daemons, modules (?) started before switch_root
is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.
You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.
"I want to be able to format that device and write a new rootfs to it"
Assume you have the new rootfs built already and ready to "install".
After you format how will you boot into this? Is this why you want to switch_root because it is already booted?
If yes switch_root may not be the tool you need.
Other tools that may allow you to format and copy your new rootfs.
- Your boot loader.
- A live linux distro installed on a bootable USB.
- A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.
- Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.
- Network boot ether PXE or even a NFS.
Does this help at all?
add a comment |Â
up vote
0
down vote
INFO:
switch_root
switch_root moves already mounted /proc, /dev, /sys and /run to
newroot and makes newroot the new root filesystem and starts init
process.
init
The program init is the process with process ID 1. It is responsible
for initializing the system in the required way. init is started
directly by the kernel and resists signal 9, which normally kills
processes. All other programs are either started directly by init or
by one of its child processes.
Any programs, daemons, modules (?) started before switch_root
is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.
You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.
"I want to be able to format that device and write a new rootfs to it"
Assume you have the new rootfs built already and ready to "install".
After you format how will you boot into this? Is this why you want to switch_root because it is already booted?
If yes switch_root may not be the tool you need.
Other tools that may allow you to format and copy your new rootfs.
- Your boot loader.
- A live linux distro installed on a bootable USB.
- A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.
- Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.
- Network boot ether PXE or even a NFS.
Does this help at all?
add a comment |Â
up vote
0
down vote
up vote
0
down vote
INFO:
switch_root
switch_root moves already mounted /proc, /dev, /sys and /run to
newroot and makes newroot the new root filesystem and starts init
process.
init
The program init is the process with process ID 1. It is responsible
for initializing the system in the required way. init is started
directly by the kernel and resists signal 9, which normally kills
processes. All other programs are either started directly by init or
by one of its child processes.
Any programs, daemons, modules (?) started before switch_root
is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.
You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.
"I want to be able to format that device and write a new rootfs to it"
Assume you have the new rootfs built already and ready to "install".
After you format how will you boot into this? Is this why you want to switch_root because it is already booted?
If yes switch_root may not be the tool you need.
Other tools that may allow you to format and copy your new rootfs.
- Your boot loader.
- A live linux distro installed on a bootable USB.
- A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.
- Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.
- Network boot ether PXE or even a NFS.
Does this help at all?
INFO:
switch_root
switch_root moves already mounted /proc, /dev, /sys and /run to
newroot and makes newroot the new root filesystem and starts init
process.
init
The program init is the process with process ID 1. It is responsible
for initializing the system in the required way. init is started
directly by the kernel and resists signal 9, which normally kills
processes. All other programs are either started directly by init or
by one of its child processes.
Any programs, daemons, modules (?) started before switch_root
is started by init process 1. switch_root will kill that init therefore all started after init is killed, gone.
You new rootfs must have the modules (?), programs, daemons for the new init to start. It is the new process 1 that will reload modules (?), restart daemons, and spawn user programs.
"I want to be able to format that device and write a new rootfs to it"
Assume you have the new rootfs built already and ready to "install".
After you format how will you boot into this? Is this why you want to switch_root because it is already booted?
If yes switch_root may not be the tool you need.
Other tools that may allow you to format and copy your new rootfs.
- Your boot loader.
- A live linux distro installed on a bootable USB.
- A custom bitbaked filesystem with only the bare minimum need to boot the system and tools (programs) need to partition, format and copy. This will ether be on another 'drive' a different partition on the MTD or even on a USB or a memory only initramfs that is part of the bzImage.
- Your new rootfs that is temporally on another partition like an USB. Must adjust your boot loader to boot from it in place of the current kernel and rootfs.
- Network boot ether PXE or even a NFS.
Does this help at all?
edited Oct 4 at 15:50
answered Oct 4 at 15:34
jc__
1,338517
1,338517
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473192%2fhow-do-you-completely-switch-the-root-files-system-on-linux%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password