Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to find block device of mount point?

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Hypex
Posts: 25
Joined: 2016-09-23 04:39
Location: Southern Aussieland

How to find block device of mount point?

#1 Post by Hypex »

Hi guys. Okay so this is new twist on an old problem. I just found out. :-)

I was using "df" to find the device of a mount, but found a flaw as a long device name can split the result into two lines. Or it could be mounted as a label so doesn't point directly to a device. In my case both of these together corrupted my script which was grabbing the device from the output.

So I have a device mounted at a point. But it isn't always a straight block device. It could be a UUID or label mount.

Like so:
/dev/disk/by-label/boot on /target/boot

Let's say that "/dev/disk/by-label/boot" actually points to "/dev/sda1". So how to I take "/dev/disk/by-label/boot" and determine if it is an actual block device? And if not how do I find that actual device it points to?

From experimenting I've noticed that the label points are links that go back to the actual device. Not exactly directly but through a "../../". So it seems obvious I need to see if its a link and follow it through.

But before I muck around like that. Is there a better way? Some mash of mount, df or blkid or anything to tell me what I need to know? :-)

User avatar
dasein
Posts: 7680
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: How to find block device of mount point?

#2 Post by dasein »

This is a problem whose solution can be discovered with just a little tiny bit of effort/exploration on your part...

Spend some time exploring /dev/disk/

Hypex
Posts: 25
Joined: 2016-09-23 04:39
Location: Southern Aussieland

Re: How to find block device of mount point?

#3 Post by Hypex »

Well I have been exploring "/dev/disk" as that's how I found out about the links. ;-)

From what you imply a simple command won't do it and it has to found from the device point.

Segfault
Posts: 993
Joined: 2005-09-24 12:24
Has thanked: 5 times
Been thanked: 17 times

Re: How to find block device of mount point?

#4 Post by Segfault »

Without digging deep into your problem, does findmnt command help?

Hypex
Posts: 25
Joined: 2016-09-23 04:39
Location: Southern Aussieland

Re: How to find block device of mount point?

#5 Post by Hypex »

Thanks, findmnt looks useful. Now, my problem is the installer doesn't have it included, since I need to use it in the installer. If I could chroot and apt-get a udeb of util-linux where I build my installer that will be useful. :-)

User avatar
kiyop
Posts: 3983
Joined: 2011-05-05 15:16
Location: Where persons without desire to improve themselves fear to tread, in Japan
Been thanked: 3 times

Re: How to find block device of mount point?

#6 Post by kiyop »

2 commands: "realpath" and "readlink" may be useful.

If you want to use in initramfs a command which is not in initramfs, you can extract the initramfs file and add the command to the extracted directory and regenerate an initramfs file from the directory.
An example to include /usr/bin/dialog into a directory /usr/bin in the initramfs:

Code: Select all

mkdir initrd
cd initrd
gzip -dc /boot/initrd.img-$(uname -r) | cpio -i
mkdir -p usr/bin
cp -L /usr/bin/dialog usr/bin/
find .|cpio -H newc -o|gzip -9 > ../initrd.img-new
Openbox, JWM: Jessie, Sid, Arch / Win XP (on VirtualBox), 10
http://kiyoandkei.bbs.fc2.com/

Hypex
Posts: 25
Joined: 2016-09-23 04:39
Location: Southern Aussieland

Re: How to find block device of mount point?

#7 Post by Hypex »

Thanks kiyop. That's almost what I was doing. Yes those commands look useful. I also need tune2fs. But my problem there is that I need to also add depends. And then extract it out. At this point an initrd builder looks good. Be useful to apt-get from a chroot. Closest I got is downloading a package and pointing dpkg to where I wanted it. :-)

Post Reply