Skip to contentSkip to conversation

Updating the root partition

DISCUSSION Chris AtLee 5 participants 9 messages Jun 19, 2002 – Jun 20, 2002 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

Hi,

I've got linux booting off of a cramfs partition sitting on mtdblock1. Is it possible to overwrite the mtdblock1 partition while linux is running? The kernel itself isn't located on the root partition. I've tried just copying a new cramfs image to /dev/mtd1 but I get errors on decompressing next time I try and boot.

Cheers,
Chris

#1 lore raw
Quoted 5 lines · Chris AtLee

I've got linux booting off of a cramfs partition sitting on mtdblock1. Is it possible to overwrite the mtdblock1 partition while linux is running? The kernel itself isn't located on the root partition. I've tried just copying a new cramfs image to /dev/mtd1 but I get errors on decompressing next time I try and boot.

- Use /dev/mtdblock1. The char device does not erase any blocks, so you end up ||ing the old and new data.
- Do the flashing soon after reboot and make sure, all necessary binaries are in RAM. Power-cycle afterwards, as you sure don't want to load good-as-random code and execute it, albeit it is only the userspace.

Jörn

Signature · 2 lines
Premature optimization is the root of all evil.
-- Donald Knuth
#2 lore raw
Quoted 7 lines · Jörn Engel
Quoted 5 lines · Chris AtLee

I've got linux booting off of a cramfs partition sitting on mtdblock1. Is it possible to overwrite the mtdblock1 partition while linux is running? The kernel itself isn't located on the root partition. I've tried just copying a new cramfs image to /dev/mtd1 but I get errors on decompressing next time I try and boot.

Quoted 6 lines

- Use /dev/mtdblock1. The char device does not erase any blocks, so you end up ||ing the old and new data.
- Do the flashing soon after reboot and make sure, all necessary binaries are in RAM. Power-cycle afterwards, as you sure don't want to load good-as-random code and execute it, albeit it is only the userspace.

if you are using busybox init, you can signal it to kill everything, and exec run the respawn entry in inittab. Your respawn entry can copy a statiacly linked copy of whatever you are using to flash to a ramfs, chroot/piviot_root to the ramfs and exec the program. once there, umount the cramfs, and you can safely do whatever you want.

#3 lore raw

Going into a pseudo single user mode to flash is not acceptable. You need to be able to flash from any tty. From any web interface. From any command. My unit will flash with a simple flash command while the system is running.

Chris

Quoted 27 lines · Russ Dill
Quoted 7 lines · Jörn Engel
Quoted 5 lines · Chris AtLee

I've got linux booting off of a cramfs partition sitting on mtdblock1. Is it possible to overwrite the mtdblock1 partition while linux is running? The kernel itself isn't located on the root partition. I've tried just copying a new cramfs image to /dev/mtd1 but I get errors on decompressing next time I try and boot.

Quoted 6 lines

- Use /dev/mtdblock1. The char device does not erase any blocks, so you end up ||ing the old and new data.
- Do the flashing soon after reboot and make sure, all necessary binaries are in RAM. Power-cycle afterwards, as you sure don't want to load good-as-random code and execute it, albeit it is only the userspace.

if you are using busybox init, you can signal it to kill everything, and exec run the respawn entry in inittab. Your respawn entry can copy a statiacly linked copy of whatever you are using to flash to a ramfs, chroot/piviot_root to the ramfs and exec the program. once there, umount the cramfs, and you can safely do whatever you want.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#4 lore raw
Quoted 4 lines · Christopher Fowler

Going into a pseudo single user mode to flash is not acceptable. You need to be able to flash from any tty. From any web interface. From any command. My unit will flash with a simple flash command while the system is running.

right, you have a program that accepts a flash image, authenicates it, and copies it to a flash partition, once this is done, *then* you signal init.

#5 lore raw

In a way. On my system you have to restart to run on the new software. I have implemented a pseudo single user mode in init that will umount the rootfs and then dump the new software into memory. Ths keeps you from having to do a restart. However, this is not possible from remote locations. You must be on serial console to do this. That is why single user mode is not acceptable.

Chris

Quoted 16 lines · Russ Dill
Quoted 4 lines · Christopher Fowler

Going into a pseudo single user mode to flash is not acceptable. You need to be able to flash from any tty. From any web interface. From any command. My unit will flash with a simple flash command while the system is running.

right, you have a program that accepts a flash image, authenicates it, and copies it to a flash partition, once this is done, *then* you signal init.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#6 lore raw
Quoted 6 lines · Christopher Fowler

In a way. On my system you have to restart to run on the new software. I have implemented a pseudo single user mode in init that will umount the rootfs and then dump the new software into memory. Ths keeps you from having to do a restart. However, this is not possible from remote locations. You must be on serial console to do this. That is why single user mode is not acceptable.

I think you are a little confused on what is going on here, so I'll explain in detail.

on my system, when it is normally up and running, an ftpd daemon is running

when the ftpd daemon receives an upload, it verifies the integrity, and saves it in /var

The ftpd daemon then sends a HUP signal to init

because inittab contains the line: ::restart:/linuxex, init kills all running processes and exec's /linuxex

linuxex now runs, and is the only running process on the system, linuxex is a shell script:

/bin/umount /tmp
/bin/umount /etc
/bin/umount /proc
/bin/cp /usr/sbin/flash /var
/bin/cp -a /dev/nftla /var/out
/bin/cp -a /dev/ttyS0 /var
cd /var
/bin/ln -s flash chroot
/bin/mkdir old
echo pivot root to var...
pivot_root . old
exec ./chroot . ./flash

so now flash is the only program running, and its statiacally linked, so there are no more references to the cramfs root, and it can be umounted by flash. flash ten proceeds to flash the image, and reset the machine.

------

so as you can see, there is no pseudo single user mode required, and the flash image is received while the system is up and fully operational. As soon as the image is received and verified, the system basically goes down for a reboot, during which the new image is flashed.

#7 lore raw

Hi, I'm trying to this whith a jffs2 partition and have some questions regarding this.

Quoted 3 lines · Russ Dill

The ftpd daemon then sends a HUP signal to init

Doesn't init only reread the inittab on a HUP?

Quoted 3 lines

because inittab contains the line: ::restart:/linuxex, init kills all running processes and exec's /linuxex

Its not like going to runlevel 1, is it?

restart, is this a special function in BB init? Could not find any info on this one,
is it like a reboot? Or does it get executed everytime I starts?

Quoted 4 lines

linuxex now runs, and is the only running process on the system, linuxex is a shell script:

Quoted 12 lines

/bin/umount /tmp
/bin/umount /etc
/bin/umount /proc
/bin/cp /usr/sbin/flash /var
/bin/cp -a /dev/nftla /var/out
/bin/cp -a /dev/ttyS0 /var
cd /var
/bin/ln -s flash chroot
/bin/mkdir old
echo pivot root to var...
pivot_root . old
exec ./chroot . ./flash

Why are you running chroot symlinked to flash, unless its multi function...

Quoted 11 lines

so now flash is the only program running, and its statiacally linked, so there are no more references to the cramfs root, and it can be umounted by flash. flash ten proceeds to flash the image, and reset the machine.

------

so as you can see, there is no pseudo single user mode required, and the flash image is received while the system is up and fully operational. As soon as the image is received and verified, the system basically goes down for a reboot, during which the new image is flashed.

Is this done for every reboot?

#8 lore raw
Quoted 10 lines · Stefan Thomasson

Hi, I'm trying to this whith a jffs2 partition and have some questions regarding this.

Quoted 3 lines · Russ Dill

The ftpd daemon then sends a HUP signal to init

Doesn't init only reread the inittab on a HUP?

Not mine. Busybox and SysV does. but I wrote my own.

Quoted 6 lines
Quoted 4 lines

because inittab contains the line: ::restart:/linuxex, init kills all running processes and exec's /linuxex

Its not like going to runlevel 1, is it?

pseudo like. I guess. There are no runlevels in my machine

Quoted 4 lines

restart, is this a special function in BB init? Could not find any info on this one,
is it like a reboot? Or does it get executed everytime I starts?

I wrote my own restart. You see when I want to restart, I tell the kernel to toggle the line that restarts the CPU. I do not want to shutdown. I do not care about data in memory.

         // Tell every USER_PROCESS we are restarting.
         wall_all();

        printf("Restarting System...\n");

        log_info("system restarting");
        /* Sleep 1 second to give the message time */

        /* Flush any Buffers */

        // This is here to flush output on tty lines.  No disk
        // is concerened.
        sync();
        /* Take the system down */
        reboot(0x01234567);

Russ and My desgins are differernt. He may give you some comments too.

Quoted 40 lines
Quoted 5 lines

linuxex now runs, and is the only running process on the system, linuxex is a shell script:

Quoted 12 lines

/bin/umount /tmp
/bin/umount /etc
/bin/umount /proc
/bin/cp /usr/sbin/flash /var
/bin/cp -a /dev/nftla /var/out
/bin/cp -a /dev/ttyS0 /var
cd /var
/bin/ln -s flash chroot
/bin/mkdir old
echo pivot root to var...
pivot_root . old
exec ./chroot . ./flash

Why are you running chroot symlinked to flash, unless its multi function...

Quoted 11 lines

so now flash is the only program running, and its statiacally linked, so there are no more references to the cramfs root, and it can be umounted by flash. flash ten proceeds to flash the image, and reset the machine.

------

so as you can see, there is no pseudo single user mode required, and the flash image is received while the system is up and fully operational. As soon as the image is received and verified, the system basically goes down for a reboot, during which the new image is flashed.

Is this done for every reboot?

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/