0

I need to find the best approach that search the unused disk in my linux OS

for example from the following ouput we can see that sde is not mounted and seems to be free disk ( we need free disk in order to create on him FS and then mount to some folder )

please advice what is the best approach to find the free disk ? with command line or command line with awk / sed / perl etc , in order to capture the unused disk

sda is for the OS

lsblk | grep disk | grep -v fd0 
sda                8:0    0   150G  0 disk
sdb                8:16   0    20G  0 disk /jeded
sdc                8:32   0    20G  0 disk /var/mmn
sdd                8:48   0    20G  0 disk /var/nrdd
sde                8:64   0    20G  0 disk

expected output should be sde

  • there are some other command to view the disk as sfdisk -s , or fdisk -l , but what we want to find is which disk is a free disk ( without FS / mounted )
  • 1
    if you can use presence of / to indicate not-free disk, try lsblk | awk '/disk/ && !/fd0|^sda |\//{print $1}' – Sundeep Jul 25 '17 at 15:31
  • lsblk | awk '/disk/ && !/fd0|^sda |\//{print $1}' this command print --> sde – yael Jul 25 '17 at 15:33
  • but we need to check also if this disk is mount according to the last field – yael Jul 25 '17 at 15:34
  • from the example - expected output should be sde – yael Jul 25 '17 at 15:37
  • that is what you get from my suggestion.. so what is the issue? am not able to follow – Sundeep Jul 25 '17 at 15:38
0

Try this:

lsblk  --noheadings --raw | awk '$1~/s.*[[:digit:]]/ && $7==""'

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.