0

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?

Mureinik
  • 297,002
  • 52
  • 306
  • 350
hy0shi
  • 271
  • 4
  • 12
  • This is a duplicate of https://unix.stackexchange.com/questions/38870/how-to-check-if-a-filesystem-is-mounted-with-a-script – AK_ Jun 03 '14 at 10:09
  • nah this doesnt help me.. – hy0shi Jun 03 '14 at 10:26
  • 1
    @AK_, I don't see how the linked question is related to this one. – Rahul Jun 03 '14 at 10:30
  • what do you exactly mean by `which partition is used`? – Rahul Jun 03 '14 at 10:32
  • Which partition i'm in? I want to know so that when I execute some script in this specific partition I save it in the other partition (rootfs2 or rootfs1). For exemple I'm in Kernel 1, then I know I can do stuff on Kernel 2. I'm sorry it's not very understanding but I just want to find a way to see in what partition i'm currently. – hy0shi Jun 03 '14 at 10:41

1 Answers1

1

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!

julienc
  • 19,087
  • 17
  • 82
  • 82
  • Sorry i'm kinda new to partitioning in linux but what is sda1? I mean, compared to Kernel1, Rootfs, etc.. Maybe I need to mount sda1 or something? – hy0shi Jun 03 '14 at 12:15
  • Actually, I don't know how did you get these partition names. What was the command you used? – julienc Jun 03 '14 at 12:25
  • It's when I reboot my SBC6845 card, it shows many informations like this. Maybe it's too specific :/ but df returns me as first line /dev/root, does it mean it's the partition used? – hy0shi Jun 03 '14 at 12:29
  • Yes it does, according to `man df`. – julienc Jun 03 '14 at 12:32