LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   discower partitions in /dev/mapper (https://www.linuxquestions.org/questions/linux-general-1/discower-partitions-in-dev-mapper-738325/)

leniviy 07-07-2009 09:26 AM

discower partitions in /dev/mapper
 
Hi. I've manually created a block device in /dev/mapper/ with command "dmsetup create"
Now, is there a program to discower partitions on it? I tried partprobe, it prints the partitions, but then complains that it can't inform the kernel and new nodes are also not created.
Code:

Error: Error informing the kernel about modifications to partition /dev/mapper/_dev_sdb_cow1 -- Invalid argument.  This means Linux won't know about any changes you made to /dev/mapper/_dev_sdb_cow1 until you reboot -- so you shouldn't mount it or use it in any way before rebooting.
I know that dmraid program can detect software RAIDs, detect partitions on them and create corresponding nodes in /dev/mapper/. Can I re-use partition detection part for non-raids?

Currently I workaround that by parsin fdisk output:
Code:

cow_partitions_discower() {
 echo "discovering partitions on $1... " >&2
 if [ "$2" = "remove" ]; then REMOVE=1; else REMOVE=0; fi
 (export LC_ALL="C"; fdisk -l -u "$1" 2>&1 ) | awk \
  -v "dev=$1" -v "numfound=0" \
  -v "remove=$REMOVE" \
  -v "failmarker=This doesn't look like a partition table|doesn't contain a valid partition table" \
  '{
    if (0<match($0,failmarker)) { system("echo \"ERROR: " $0 "\" >&2"); error = 1; exit 1; }
    if (substr($0, 1, length(dev)) == dev) {
      numfound = numfound + 1;
      $0=substr($0,length(dev)+1); sub("\\*"," ");
      shortdev=dev;sub(".*/","",shortdev);
      if (remove) {
      print "dmsetup remove \"" shortdev $1 "\""
      } else {
      print "echo \"0 " $3-$2+1 " linear " dev " " $2 "\" | dmsetup create \"" shortdev $1 "\" || exit 1;"
      }
    }
  }
  END {
    if (NR==0) { system("echo \"ERROR: fdisk could not open device: " dev "\" >&2"); error = 1; exit 1; }
    if (error != 1) { if (remove==1) s = "remove"; else s = "add"; system("echo \"partitions to " s ": " numfound "\" >&2"); } }
  '
}

[root@myhost dev]# cow_partitions_discower /dev/sdb
discovering partitions on /dev/sdb...
echo "0 4192902 linear /dev/sdb 63" | dmsetup create "sdb1" || exit 1;
echo "0 36804915 linear /dev/sdb 4192965" | dmsetup create "sdb2" || exit 1;
echo "0 719792325 linear /dev/sdb 40997880" | dmsetup create "sdb3" || exit 1;
partitions to add: 3
[root@myhost dev]# cow_partitions_discower /dev/sdb | sh
discovering partitions on /dev/sdb...
partitions to add: 3
[root@myhost dev]# ls /dev/mapper/
control  sdb1  sdb2  sdb3


unSpawn 08-01-2009 06:10 AM

Could try 'kpartx' as in 'kpartx -va /dev/sdb' and verify by running 'dmsetup status' or listing contents of /dev/mapper.


All times are GMT -5. The time now is 04:20 PM.