Check what partition is used?

459 Views Asked by At

I'm working on a SBC6845 card with Linux on it: I have 4 partitions installed:

Creating 5 MTD partitions on "atmel_nand":
0x000000000000-0x000000100000 : "Factory"
0x000000100000-0x000000300000 : "Kernel1"
0x000000300000-0x000000500000 : "Kernel2"
0x000000500000-0x000008280000 : "Rootfs1"
0x000008280000-0x000010000000 : "Rootfs2"

I want to make a shell script that display which partition is currently used but I don't see how.

the command "df -h" returns:

# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               178.8G     65.4G    104.3G  39% /
tmpfs                    61.7M         0     61.7M   0% /dev/shm
tmpfs                    61.7M     36.0K     61.7M   0% /tmp

and also fdisk doesn't work on this system.

Anyone have an idea how to resolve this?

1

There are 1 best solutions below

4
On BEST ANSWER

So you want to know on which partition your script is currently located ? df can help you with this! You just have to give it the path to your script as an argument:

#!/bin/sh
df $0  | tail -1 | awk '{print $1}'

And sh myscript.sh gives me: /dev/sda1

Explanations:

  • df $0 outputs the partition in which myscript.sh is
  • tail -1 ignores the first line of df (name of the columns)
  • awk '{print $1}' returns the first column of df, which is the partition

I hope this is what you expected!