LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-07-2009, 09:26 AM   #1
leniviy
Member
 
Registered: Jul 2009
Distribution: Archlinux
Posts: 37

Rep: Reputation: 2
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
 
Old 08-01-2009, 06:10 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,118
Blog Entries: 54

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
encrypted partition locked...dev/mapper does not exist goswamiyashwant Linux - Newbie 4 03-01-2009 12:06 AM
What is /dev/mapper/VolGroup00-LogVol00 and what does it stands for ? ytd Linux - Newbie 13 01-22-2009 05:29 AM
Where is /dev/mapper? Swift&Smart Fedora 1 12-08-2007 02:09 AM
newbie question /dev/mapper/lfs-cd echnat0n Linux From Scratch 2 03-05-2007 07:05 AM
/dev/mapper directory joshnya Linux - Newbie 11 09-15-2005 03:09 AM


All times are GMT -5. The time now is 01:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration