6

I have a minimalist busybox system that I was recently trying to use, and I found a small problem: it has no lsblk command. Is there another command to list disks, partitions, and sizes like lsblk?

Some that also don't work:

  • lsblk
  • lsusb
  • fdisk -l
  • cfdisk
  • well. Looking at the manuals it should provide you the fdisk utility - man.he.net/man1/busybox - could you please run /bin/busybox --help to see the list of the available commands? – user34720 Apr 30 '14 at 1:25
  • df is not working? – Ramesh Apr 30 '14 at 1:27
6

Seeing through the wiki page of busybox, I see it supports df command to find disk usage.

You can try the below command.

df -h - Show free space on mounted file systems.

From the man page of busybox, they have provided examples of how to use the df command.

However, as @nwildner pointed out, the df will show storage on a mounted filesystem and not the schemes related to partitions. To find it out, you can check the below file.

cat /proc/partitions

As you had mentioned fdisk -l is not working the above file might contain the partition information.

Testing

fdisk -l produced the below output in my system.

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        9726    78019672+  8e  Linux LVM

Now, I can get the partition information if I use cat /proc/partitions. The output is,

major minor  #blocks  name

   8     0   78125000 sda
   8     1     104391 sda1
   8     2   78019672 sda2
 253     0   78019156 dm-0
 253     1   72581120 dm-1
 253     2    5406720 dm-2

The major number is 8 that indicates it to be a disk device. The minor ones are your partitions on the same device. 0 is the entire disk, 1 is the primary, 2 is extended and 5 is logical partition. The rest is of course block size and name of disk/partition.

Not sure if an intelligent suggestion, but did you try sudo fdisk -l to see if it is working?

EDIT#1

You can also run $ df -T. This is another command that does not require super user privileges to execute. However, this will report for every mount point.

Another command that can come handy is # file -sL /dev/sdXY. This has one downside in that it does not work with the full block device. Requires the exact device to be passed. The output is quite neat though:

References

How to determine the filesystem of an unmounted device?

  • 2
    But df will show storage usage on a mounted filesystem, not schemes related to partitions. – user34720 Apr 30 '14 at 1:39
  • 1
    @nwildner, updated the answer. Please check and let me know :) – Ramesh Apr 30 '14 at 1:41
  • I am logged in as root. Will /proc/partitions show unmounted partitions? – TheDoctor Apr 30 '14 at 2:50
  • @TheDoctor, I am afraid it won't show the unmounted partitions. – Ramesh Apr 30 '14 at 3:16
  • 1
    No, df -T doesn't seem to work either. It only says i can use options -p, -k, -m, -h – TheDoctor Apr 30 '14 at 21:25
3

Looks like the other answerers didn't actually test on BusyBox. Here are the only commands that worked on the BusyBox in my initramfs:

  • cat /proc/partitions shows the disk and partition sizes in blocks (KiB)

  • blkid shows the partition labels, UUIDs, and types (EXT4, NTFS, etc)

0

the busy box commands are typically a bit more limited then full versions included in bigger distros and the previous answer has not quite addressed this as I found out when I had the same problem.

I found the info I needed (and a lot more) for ext file systems using tune2fs which was available on the embedded Linux that I am using at the moment. No sure how to do this for other types of unmounted file systems.

tune2fs -l /dev/sdbXY | grep 'Block' | tr -s ' ' | cut -f3 -d' '
488378112
4096
group:

This will give you this output because tr -s strips repeated spaces and cut -f3 -d ' ' gives you the third field of output. Simply remove successive pipes to learn a bit more about what's going on.

The first number is the amount of blocks and the second is the block size. Multiply them together to get your answer in bytes. The word group: is just an anomaly of the filtering and can be ignored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.