Skip to contentSkip to conversation

Discovering current MTD partition

DISCUSSION Umar Qureshey 6 participants 18 messages Apr 26, 2011 – Apr 29, 2011 1 message not in the archive Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

Hi,

I searched this list's archive but did not see anything pertinent.

I was wondering if there is a way to find out what the currently active mtd partition is. In my system, I have a few flash partitions for my file system and the kernel boots with the partition that is specified on the kernel command line. Aside from scanning /proc/cmdline, is there a way to programmatically ascertain which mtd partition is active *now*. I need to find this information within a Python script but really if it can be done in C (perhaps a syscall?), it's all I need.

Regards,
Umar

#1 lore raw
Quoted 11 lines · Umar Qureshey

Hi,

I searched this list's archive but did not see anything pertinent.

I was wondering if there is a way to find out what the currently active mtd partition is. In my system, I have a few flash partitions for my file system and the kernel boots with the partition that is specified on the kernel command line. Aside from scanning /proc/cmdline, is there a way to programmatically ascertain which mtd partition is active *now*. I need to find this information within a Python script but really if it can be done in C (perhaps a syscall?), it's all I need.

What does active mean? Anyway, there is /proc/mtd at your disposal.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#2 lore raw
Quoted 8 lines · Artem Bityutskiy
Quoted 6 lines · Umar Qureshey

Hi,

I searched this list's archive but did not see anything pertinent.

Quoted 8 lines
Quoted 6 lines

I was wondering if there is a way to find out what the currently active mtd
partition is. In my system, I have a few flash partitions for my file
system and the kernel boots with the partition that is specified on the
kernel command line. Aside from scanning /proc/cmdline, is there a way to
programmatically ascertain which mtd partition is active *now*. I need to find this information within a Python script but really if it can be done in C (perhaps a syscall?), it's all I need.

What does active mean? Anyway, there is /proc/mtd at your disposal.

If you want to find out which partition is mounted as root you could look at /proc/mounts .

/Ricard

Signature · 3 lines
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30
#3 lore raw
Quoted 18 lines
Quoted 18 lines · Artem Bityutskiy
Quoted 7 lines · Umar Qureshey

Hi,

I searched this list's archive but did not see anything pertinent.

I was wondering if there is a way to find out what the currently

active mtd

Quoted 2 lines

partition is. In my system, I have a few flash partitions for my file system and the kernel boots with the partition that is specified on

the

Quoted 1 line

kernel command line. Aside from scanning /proc/cmdline, is there a

way to

Quoted 2 lines

programmatically ascertain which mtd partition is active *now*. I need to find this information within a Python script but really if

it can

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

be done in C (perhaps a syscall?), it's all I need.

What does active mean? Anyway, there is /proc/mtd at your disposal.

If you want to find out which partition is mounted as root you could look at /proc/mounts .

/Ricard

Hi,
/proc/mtd simply gives me a list of partition on the mtd device. It doesn't tell me which one we currently have booted from.

/proc/mounts as well doesn't relay any info about /dev/mtdXX.

~Umar

#4 lore raw
Quoted 3 lines · On Wed, 27 Apr 2011, [email protected] wrote:

Hi,

/proc/mounts as well doesn't relay any info about /dev/mtdXX.

Sorry, you are right of course. It just seems to say /dev/root on my system.

The df command however seems to figure out which mtd device is mounted on / . I don't know exactly how it finds this out though. I'm pretty sure it uses /proc/mounts, because if /proc/mounts is missing it doesn't output anything, but it must be getting extra information from somewhere.

/Ricard

Signature · 3 lines
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30
#5 lore raw
Quoted 9 lines · Ricard Wanderlof
Quoted 3 lines · On Wed, 27 Apr 2011, [email protected] wrote:

Hi,

/proc/mounts as well doesn't relay any info about /dev/mtdXX.

Sorry, you are right of course. It just seems to say /dev/root on my system.

Quoted 6 lines

The df command however seems to figure out which mtd device is mounted on / . I don't know exactly how it finds this out though. I'm pretty sure it uses /proc/mounts, because if /proc/mounts is missing it doesn't output anything, but it must be getting extra information from somewhere.

/Ricard

Well, the best it to look at df sources. But here is my guess:

/dev/root must have come from the kernel command line, if I'm not mistaken. You can find out what is your /dev/root from /proc/cmdline - find rootfs=<xxx> there, and xxx is your device.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#6 lore raw
Quoted 15 lines · Artem Bityutskiy
Quoted 14 lines · Ricard Wanderlof
Quoted 3 lines · On Wed, 27 Apr 2011, [email protected] wrote:

Hi,

/proc/mounts as well doesn't relay any info about /dev/mtdXX.

Sorry, you are right of course. It just seems to say /dev/root on my system.

The df command however seems to figure out which mtd device is mounted on / . I don't know exactly how it finds this out though. I'm pretty sure it uses /proc/mounts, because if /proc/mounts is missing it doesn't output anything, but it must be getting extra information from somewhere.

Quoted 7 lines
Quoted 1 line

/Ricard

Well, the best it to look at df sources. But here is my guess:

/dev/root must have come from the kernel command line, if I'm not mistaken. You can find out what is your /dev/root from /proc/cmdline - find rootfs=<xxx> there, and xxx is your device.

Well, in this case /dev/cmdline says

console=ttyS0 root=/dev/mtdblock3 rw rootfstype=jffs2 init=/linuxrc

so no mention of /dev/root there.

/Ricard

Signature · 3 lines
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30
#7 lore raw
Quoted 25 lines · Ricard Wanderlof
Quoted 15 lines · Artem Bityutskiy
Quoted 14 lines · Ricard Wanderlof
Quoted 3 lines · On Wed, 27 Apr 2011, [email protected] wrote:

Hi,

/proc/mounts as well doesn't relay any info about /dev/mtdXX.

Sorry, you are right of course. It just seems to say /dev/root on my system.

The df command however seems to figure out which mtd device is mounted on / . I don't know exactly how it finds this out though. I'm pretty sure it uses /proc/mounts, because if /proc/mounts is missing it doesn't output anything, but it must be getting extra information from somewhere.

Quoted 7 lines
Quoted 1 line

/Ricard

Well, the best it to look at df sources. But here is my guess:

/dev/root must have come from the kernel command line, if I'm not mistaken. You can find out what is your /dev/root from /proc/cmdline - find rootfs=<xxx> there, and xxx is your device.

Quoted 5 lines

Well, in this case /dev/cmdline says

console=ttyS0 root=/dev/mtdblock3 rw rootfstype=jffs2 init=/linuxrc

so no mention of /dev/root there.

/dev/root is the alias for whatever is in root=, so in your case /dev/root = /dev/mtdblock3

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#8 lore raw
Quoted 8 lines · Artem Bityutskiy
Quoted 5 lines

Well, in this case /dev/cmdline says

console=ttyS0 root=/dev/mtdblock3 rw rootfstype=jffs2 init=/linuxrc

so no mention of /dev/root there.

/dev/root is the alias for whatever is in root=, so in your case /dev/root = /dev/mtdblock3

Yes, I understand that, I was just mentioning the fact that it was not necessarily possible to determine the root file system partition from /proc/mounts as it uses the /dev/root alias there.

/Ricard

Signature · 3 lines
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30
#9 lore raw
In reply to Artem Bityutskiy
Quoted 16 lines · Umar Qureshey
Quoted 4 lines

Hi,

I searched this list's archive but did not see anything pertinent.

Quoted 10 lines

I was wondering if there is a way to find out what the currently active mtd
partition is. In my system, I have a few flash partitions for my file system and the kernel boots with the partition that is specified on the kernel command line. Aside from scanning /proc/cmdline, is there a way to
programmatically ascertain which mtd partition is active *now*. I need to find this information within a Python script but really if it can
be done in C (perhaps a syscall?), it's all I need.

Quoted 7 lines

What does active mean? Anyway, there is /proc/mtd at your disposal.

--
Best Regards,
Artem Bityutskiy (�ртём Битюцкий)

Hi,
I have multiple redundant partitions on the flash chip. Each of these partitions has been flashed with a file system. The kernel resides in yet another partition. The bootloader loads the kernel into RAM, passes it the kernel command line, and passes control to the kernel. The kernel boots and mounts the partition it was told to do so via the command line.

So, for instance, I may have this scheme:

/dev/mtd2 ---> kernel
/dev/mtd3 -----> FS #1
/dev/mtd4 -----> FS #2

The kernel can boot and mount either /dev/mtd3 or /dev/mtd4 depending on what command line the bootloader passed to the kernel.
What I'd like is to detect from userspace is which /dev/mtdX partition is the currently executing program running on because that is the partition that has been obviously booted.

My fallback idea is to just bite the bullet and parse /proc/cmdline to see which partition is being passed to the kernel. This should work fine. But I was curious if there is a "cleaner" more programmatic method of determining this information without resorting to clever regular expressions in parsing /proc/cmdline.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw
Quoted 11 lines · On 04/27/2011 09:25 AM, [email protected] wrote:
Quoted 6 lines

Hi,
[...]
What I'd like is to detect from userspace is which /dev/mtdX partition is
the currently executing program running on because that is the partition that has been obviously booted.

I think you might want to take a look at getmntent (3) : it is a libc function for getting the /etc/mtab entries. It also seems to be portable.

Quoted 8 lines

Cheers,
David.

--
David Wagner, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

This will give me the same info as /proc/mtab. I cannot figure out how I can infer which /dev/mtdXX was booted from with this information.

#12 lore raw
Quoted 14 lines · On Thu, 28 Apr 2011 03:14:36 [email protected] wrote:
Quoted 14 lines · On 04/27/2011 09:25 AM, [email protected] wrote:
Quoted 6 lines

Hi,
[...]
What I'd like is to detect from userspace is which /dev/mtdX partition is
the currently executing program running on because that is the partition that has been obviously booted.

I think you might want to take a look at getmntent (3) : it is a libc function for getting the /etc/mtab entries. It also seems to be portable.

Cheers,
David.

Quoted 9 lines
Quoted 5 lines

--
David Wagner, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

This will give me the same info as /proc/mtab. I cannot figure out how I can infer which /dev/mtdXX was booted from with this information.

Here is an example from the embedded system I have on my desk right now:

root:/proc# cat /proc/mounts
rootfs / rootfs rw 0 0
mtd:rfs / jffs2 rw,relatime 0 0
proc /proc proc rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,mode=600 0 0
etc.

From this we can see that the current root file system is mtd:rfs

root:/proc# cat mtd
dev:    size   erasesize  name
mtd0: 00100000 00020000 "S1S2EN"
mtd1: 00400000 00020000 "rkern"
mtd2: 00b00000 00020000 "rfs"
mtd3: 00400000 00020000 "kernel"
mtd4: 02000000 00020000 "root"
etc.

This tells us that mtd:rfs corresponds to mtd2, which should be accessible under /dev/mtd2, /dev/mtdblock2, etc.

Best regards,

Iwo

This communication contains information which may be confidential or privileged. The information is intended solely for the use of the individual or entity named above. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this communication in error, please notify me by telephone immediately.

#13 lore raw
Quoted 7 lines · Iwo Mergler
Quoted 3 lines

This will give me the same info as /proc/mtab. I cannot figure out how I can infer which /dev/mtdXX was booted from with this information.

Here is an example from the embedded system I have on my desk right now:

Quoted 6 lines
root:/proc# cat /proc/mounts
rootfs / rootfs rw 0 0
mtd:rfs / jffs2 rw,relatime 0 0
proc /proc proc rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,mode=600 0 0
etc.

On the other hand, here's another example from a system on my desk:

# cat  /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / jffs2 rw,relatime 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
udev /dev tmpfs rw,relatime 0 0
tmpfs /dev/shm tmpfs rw,relatime 0 0
/dev/part/rwfsblock /mnt/flash jffs2 rw,relatime 0 0
tmpfs /var tmpfs rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,mode=600 0 0

The root partition is just listed as /dev/root without any information about what that refers to. The system doesn't even have a /dev/root so it's just some sort of placeholder.

On the other hand, on the same system, df says:

# df
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/mtdblock3           28672     22384      6288  78% /
udev                     66588         4     66584   0% /dev
tmpfs                    66588         0     66588   0% /dev/shm
/dev/part/rwfsblock     228864      5456    223408   2% /mnt/flash
tmpfs                    66588     25660     40928  39% /var

which tells exactly where the root file system is. Don't know exactly how it obtains the information though.

The system is running busybox so a quick look in the code for the df command should explain how its done.

/Ricard

Signature · 3 lines
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30
#14 lore raw
In reply to Iwo Mergler
Quoted 51 lines · On Thu, 28 Apr 2011 03:14:36 [email protected] wrote:
Quoted 23 lines
Quoted 4 lines · On 04/27/2011 09:25 AM, [email protected] wrote:
Quoted 3 lines

Hi,
[...]
What I'd like is to detect from userspace is which /dev/mtdX

partition

Quoted 2 lines
Quoted 2 lines

is
the currently executing program running on because that is the

partition

Quoted 4 lines
Quoted 1 line

that has been obviously booted.

I think you might want to take a look at getmntent (3) : it is a libc function for getting the /etc/mtab entries. It also seems to be

portable.

Quoted 9 lines

Cheers,
David.

--
David Wagner, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

Quoted 4 lines

This will give me the same info as /proc/mtab. I cannot figure out how I
can infer which /dev/mtdXX was booted from with this information.

Here is an example from the embedded system I have on my desk right now:

root:/proc# cat /proc/mounts
rootfs / rootfs rw 0 0
mtd:rfs / jffs2 rw,relatime 0 0
proc /proc proc rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,mode=600 0 0
etc.

From this we can see that the current root file system is mtd:rfs

root:/proc# cat mtd
dev:    size   erasesize  name
mtd0: 00100000 00020000 "S1S2EN"
mtd1: 00400000 00020000 "rkern"
mtd2: 00b00000 00020000 "rfs"
mtd3: 00400000 00020000 "kernel"
mtd4: 02000000 00020000 "root"
etc.
Quoted 9 lines

This tells us that mtd:rfs corresponds to mtd2, which should be accessible under /dev/mtd2, /dev/mtdblock2, etc.

Best regards,

Iwo

# cat /proc/mounts
rootfs / rootfs rw 0 0
ubi0:rootfs / ubifs rw,sync,relatime 0 0
proc /proc proc rw,relatime 0 0
tmpfs /tmp tmpfs rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620 0 0
sysfs /sys sysfs rw,relatime 0 0
debugfs /debug debugfs rw,relatime 0 0
tmpfs /webSvr/logs tmpfs rw,relatime 0 0
# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00020000 00020000 "bst"
mtd1: 00500000 00020000 "ptb"
mtd2: 00500000 00020000 "bld"
mtd3: 00500000 00020000 "hal"
mtd4: 00500000 00020000 "pba"
mtd5: 00800000 00020000 "pri"
mtd6: 00800000 00020000 "sec"
mtd7: 03c00000 00020000 "bak"
mtd8: 03c00000 00020000 "rmd"
mtd9: 03c00000 00020000 "rom"
mtd10: 00300000 00020000 "dsp"
mtd11: 03c00000 00020000 "lnx"
# df
Filesystem                Size      Used Available Use% Mounted on
ubi0:rootfs              52.7M     35.1M     17.5M  67% /
tmpfs                    65.4M     32.0K     65.4M   0% /tmp
tmpfs                    65.4M     32.0K     65.4M   0% /webSvr/logs

There's nothing above I can use to infer about which /dev/mtdXX is currently booted - at least on this system.
I have resorted to my backup strategy of parsing /proc/cmdline within Python to determine which partition is booted. *sigh*

#15 lore raw
Quoted 31 lines · On Thu, 2011-04-28 at 13:26 -0400, [email protected] wrote:
# cat /proc/mounts
rootfs / rootfs rw 0 0
ubi0:rootfs / ubifs rw,sync,relatime 0 0
proc /proc proc rw,relatime 0 0
tmpfs /tmp tmpfs rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620 0 0
sysfs /sys sysfs rw,relatime 0 0
debugfs /debug debugfs rw,relatime 0 0
tmpfs /webSvr/logs tmpfs rw,relatime 0 0
# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00020000 00020000 "bst"
mtd1: 00500000 00020000 "ptb"
mtd2: 00500000 00020000 "bld"
mtd3: 00500000 00020000 "hal"
mtd4: 00500000 00020000 "pba"
mtd5: 00800000 00020000 "pri"
mtd6: 00800000 00020000 "sec"
mtd7: 03c00000 00020000 "bak"
mtd8: 03c00000 00020000 "rmd"
mtd9: 03c00000 00020000 "rom"
mtd10: 00300000 00020000 "dsp"
mtd11: 03c00000 00020000 "lnx"
# df
Filesystem                Size      Used Available Use% Mounted on
ubi0:rootfs              52.7M     35.1M     17.5M  67% /
tmpfs                    65.4M     32.0K     65.4M   0% /tmp
tmpfs                    65.4M     32.0K     65.4M   0% /webSvr/logs
Quoted 4 lines

There's nothing above I can use to infer about which /dev/mtdXX is currently booted - at least on this system.
I have resorted to my backup strategy of parsing /proc/cmdline within Python to determine which partition is booted. *sigh*

Yes, this is a bit messy and complex. Anyway, here is the algorithm for you, in short. Ask specific questions if it is not clear, I do not have time right now to write long mails. Anyway, you need to spend some time and understand the relations between all these mtdX, ubiY, ubiY_Z, ubiY:name...

So, in your case you know your rootfs is "ubi0:rootfs". This means that
a) your rootfs is an UBI volume
b) this UBI volume belongs to the UBI device 0 (there may be several of them - ubi1, ubi2, etc). This is the typical case, I do not know if anyone really has more than one UBI device ever.
c) You know that the volume name is "rootfs".

You also should know that there is 1-1 correspondence between MTD and UBI devices - one UBI device sits on top (and fully controls) one MTD device. To find out the MTD device number you look
at: /sys/class/ubi/ubi0/mtd_num

There you see the number X, this means your MTD device is mtdX

P.S. If you had set-up similar to Ricard's, you' also need to look at /proc/cmdline to translate "rootfs" or "/dev/rootfs" to "ubi0:rootfs". Not, in this case it is just co-incidence that you named your volume "rootfs", if you named it "pussy_cat", you' have the following in your /proc/mounts:

rootfs / rootfs rw 0 0
ubi0:pussy_cat / ubifs rw,sync,relatime 0 0

HTH.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#16 lore raw
Quoted 63 lines · On Thu, 2011-04-28 at 13:26 -0400, [email protected] wrote:
Quoted 31 lines
# cat /proc/mounts
rootfs / rootfs rw 0 0
ubi0:rootfs / ubifs rw,sync,relatime 0 0
proc /proc proc rw,relatime 0 0
tmpfs /tmp tmpfs rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620 0 0
sysfs /sys sysfs rw,relatime 0 0
debugfs /debug debugfs rw,relatime 0 0
tmpfs /webSvr/logs tmpfs rw,relatime 0 0
# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00020000 00020000 "bst"
mtd1: 00500000 00020000 "ptb"
mtd2: 00500000 00020000 "bld"
mtd3: 00500000 00020000 "hal"
mtd4: 00500000 00020000 "pba"
mtd5: 00800000 00020000 "pri"
mtd6: 00800000 00020000 "sec"
mtd7: 03c00000 00020000 "bak"
mtd8: 03c00000 00020000 "rmd"
mtd9: 03c00000 00020000 "rom"
mtd10: 00300000 00020000 "dsp"
mtd11: 03c00000 00020000 "lnx"
# df
Filesystem                Size      Used Available Use% Mounted on
ubi0:rootfs              52.7M     35.1M     17.5M  67% /
tmpfs                    65.4M     32.0K     65.4M   0% /tmp
tmpfs                    65.4M     32.0K     65.4M   0% /webSvr/logs
Quoted 4 lines

There's nothing above I can use to infer about which /dev/mtdXX is currently booted - at least on this system.
I have resorted to my backup strategy of parsing /proc/cmdline within Python to determine which partition is booted. *sigh*

Yes, this is a bit messy and complex. Anyway, here is the algorithm for you, in short. Ask specific questions if it is not clear, I do not have time right now to write long mails. Anyway, you need to spend some time and understand the relations between all these mtdX, ubiY, ubiY_Z, ubiY:name...

So, in your case you know your rootfs is "ubi0:rootfs". This means that
a) your rootfs is an UBI volume
b) this UBI volume belongs to the UBI device 0 (there may be several of them - ubi1, ubi2, etc). This is the typical case, I do not know if anyone really has more than one UBI device ever.
c) You know that the volume name is "rootfs".

You also should know that there is 1-1 correspondence between MTD and UBI devices - one UBI device sits on top (and fully controls) one MTD device. To find out the MTD device number you look
at: /sys/class/ubi/ubi0/mtd_num

There you see the number X, this means your MTD device is mtdX

P.S. If you had set-up similar to Ricard's, you' also need to look at /proc/cmdline to translate "rootfs" or "/dev/rootfs" to "ubi0:rootfs". Not, in this case it is just co-incidence that you named your volume "rootfs", if you named it "pussy_cat", you' have the following in your /proc/mounts:

Quoted 5 lines

rootfs / rootfs rw 0 0
ubi0:pussy_cat / ubifs rw,sync,relatime 0 0

HTH.

Yes, that definitely helps!

# cat /sys/class/ubi/ubi0/mtd_num
11

Thanks :)

#17 lore raw
In reply to Umar Qureshey
Quoted 5 lines · Umar Qureshey

[...]
Aside from scanning /proc/cmdline, is there a way to programmatically ascertain which mtd partition is active *now*. I need to find this information within a Python script but really if it can be done in C (perhaps a syscall?), it's all I need.

Busybox has a command called 'rdev' that looks up the block device that is mounted on /.

$ busybox rdev
/dev/sda1 /

Look in busybox/util-linux/rdev.c and busybox/libbb/find_root_device.c for the implementation details.

Best regards,
Bjørn Forsman

#18 lore raw

Bjørn:

Quoted 2 lines
$ busybox rdev
/dev/sda1 /

Just FYI: This doesn't work on my particular
Embedded Linux system (running on UBIfs).
That command produces no result.

Atlant

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Bjørn Forsman
Sent: Thursday, April 28, 2011 14:08
To: Umar Qureshey
Cc: [email protected]
Subject: Re: Discovering current MTD partition

Quoted 5 lines · Umar Qureshey

[...]
Aside from scanning /proc/cmdline, is there a way to programmatically ascertain which mtd partition is active *now*. I need to find this information within a Python script but really if it can be done in C (perhaps a syscall?), it's all I need.

Busybox has a command called 'rdev' that looks up the block device that is mounted on /.

$ busybox rdev
/dev/sda1 /

Look in busybox/util-linux/rdev.c and busybox/libbb/find_root_device.c for the implementation details.

Best regards,
Bjørn Forsman

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

This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.