Visit Our UNIX and Linux User Community

Automating partitioning setup of /dev/sda on /dev/sdc

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automating partitioning setup of /dev/sda on /dev/sdc
# 1  
Old 05-21-2015
Automating partitioning setup of /dev/sda on /dev/sdc

Objective: To recreate the partitioning setup of /dev/sda on /dev/sdc

How would I parse the below information and initialize variables
(an array?) that can be used to build sgdisk commands in a script, regardless of the number of partitions?

Something along the lines of:
sgdisk -n $partnum:$startsec:$endsec -t $partnum:$parttype -c $partnum:$name /dev/sdc

for each partition listed in text produced by an sgdisk - i command.

I am thinking that I can save this text to a file in the backup process and then use it in the restoration process...

Thank you vey much in advance for any time and effort expended in answering my
question! Smilie

root@redbrick /: sgdisk -p /dev/sda
Disk /dev/sda: 1465149168 sectors, 698.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 3A4C6201-749A-4B13-93E0-A94B52349823
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1465149134
Partitions will be aligned on 2048-sector boundaries
Total free space is 749229 sectors (365.8 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          411647   200.0 MiB   EF00  EFI System Partition
   2          411648         1435647   500.0 MiB   8300  
   3         1435648      1464401919   697.6 GiB   8300

Last edited by RogerBaran; 05-21-2015 at 03:52 PM.. Reason: clarification
# 2  
Old 05-21-2015
As this is crucial (and possibly dangerous, e.g. disk structures differ), and as it's a one off exercise, I'd do it manually and not by script/automated parsing.
# 3  
Old 05-21-2015
I agree. This is for a home project on expendable resources. This is part of a Crashed Disk Recovery project that I am working on. Lots of hard disks here to experiment with! 😄

---------- Post updated at 12:15 PM ---------- Previous update was at 12:13 PM ----------

Can you help with the scripting?

Last edited by RogerBaran; 05-21-2015 at 03:50 PM.. Reason: Clarity
# 4  
Old 05-21-2015
Please don't bump posts.

It would take a great deal of trial and error to get what you want. I'm not sure sgdisk -p is printing all the info you really need, and there's often more to it than just plugging in the right numbers.

I take it your goal is to reorganize partitions into some known-good configuration? have you considered dd?

What exactly is your "crashed disk recovery project"?
# 5  
Old 05-21-2015
Yes DD will not work because the cylinders value on the other drive is not the same as the originating drive. so my only approach would be to recreate the partitions manually that match the original drive, format them out, and then replace the file structure in each one of those partitions. In this case it's a single partition for EFI, one for Boot and a LUKS partition... Any other method seems to result in a corrupted partition table.

sgdisk is providing just enough info to recreate the partition structure. I'm just not sure how to pull that info and what "for" loops I would need.
# 6  
Old 05-21-2015
Originally Posted by RogerBaran
Yes DD will not work because the cylinders value on the other drive is not the same as the originating drive.
Just how old are these hard drives? "cylinders" is completely meaningless on any drive newer than 1996, and a partition table with primary partition starting at sector 2048 looks pretty modern too.

Having not seen what you were doing, I can't say why your other methods resulted in a corrupted partition table.
# 7  
Old 05-21-2015
The first time I used the DD to copy the first 2048 sectors off the drive and then I used dd to also copy both of the other partitions. At that point gdisk would complain that I had a corrupt GPT table and that my partition was over running X number of sectors into the next partition. I read somewhere that that's because the way that the drive handles writing the information to the disc is based upon the geometry of the cylinders heads and sectors ...

---------- Post updated at 02:22 PM ---------- Previous update was at 02:19 PM ----------

That's why I decided trying to copy the partition information over to another drive was not a good idea and that what I should actually do is just go ahead and zap a disc get a brand new GPT on there and then format it out one partition at a time and then copy the data into it

Previous Thread | Next Thread
Test Your Knowledge in Computers #740
Difficulty: Medium
FORTRAN II first appeared in 1958.
True or False?

9 More Discussions You Might Find Interesting

1. HP-UX

Dev/urandom and dev/random missing in HP-UX

Hi, In our HP-UX B.11.11. I could not find dev/urandom and dev/random Are all pseudo-devices implemented as device drivers, or in need to run /configure some package to install the package to have dev/urandom. Please help (4 Replies)
Discussion started by: rashi
4 Replies

2. Red Hat

Changing grub from /dev/sda to /dev/sdb

Hi, Please suggest steps to change grub from /dev/sda to /dev/sdb, (1 Reply)
Discussion started by: manoj.solaris
1 Replies

3. AIX

Problem in /dev/hd1 and /dev/hd9var

Hello AIXians, I can't boot my AIX, it hangs and stops at the code error: 0518 After searching google, I knew the problem is due to problems in File Systems. So the solution is booting from any bootable media, then run these commands in maintenance mode: #fsck -y /dev/hd4 #fsck -y... (3 Replies)
Discussion started by: Mohannad
3 Replies

4. AIX

Difference between /dev/hdisk and /dev/rhdisk

Hi, How can i check that i am using RAW devices for storage in my AIX machine... Also after adding a LUN from storage to a aix host, when i check /dev in the host, i can see both rhdisk and hdisk with same number eg: dcback1(root):/dev>ls -lrt | grep disk12 crw------- 1 root ... (4 Replies)
Discussion started by: jibujacob
4 Replies

5. Solaris

Lun remove, stuck in /dev/dsk and /dev/rdsk

So, we removed a LUN from the SAN and the system is refusing to remove the references to it in the /dev folder. I've done the following: devfsadm -Cv powermt -q luxadm -e offline <drive path> luxadm probe All those commands failed to remove the path. The drive stills shows up as <drive... (13 Replies)
Discussion started by: DustinT
13 Replies

6. Slackware

CUPS setup / dev/lp0 perms. ... Slow printing.

Hello, Ive got an HP LaserJet 2100 / parallel interface. I had some troubles getting going due to non-working cups drivers. Updated cups and also used a .ppd.gz file from something HP provided. found the files here... Anyways.... (1 Reply)
Discussion started by: agentrnge
1 Replies

7. UNIX for Dummies Questions & Answers

Sending alt-n to /dev/pts/1 from process bound to /dev/pts/2

Hello, i am using finch (unix commandline instant messaging client using libgnt) which is running connected to /dev/pts/1 Now I would like to "remote control" the program by sending the key combinations normally typed on the keyboard from a programm in another shell. So I tried:... (0 Replies)
Discussion started by: mentos
0 Replies

8. Solaris

What is /dev/tty /dev/null and /dev/console

Hi, Anyone can help My solaris 8 system has the following /dev/null , /dev/tty and /dev/console All permission are lrwxrwxrwx Can this be change to a non-world write ?? any impact ?? (12 Replies)
Discussion started by: civic2005
12 Replies

9. Solaris

URGENT - setup port and dump all output to /dev/null or a file

Please help urgently. I need to setup up some sort of service on a solaris server on a port. I dont need it do anything special, anything that is sent to this port from an external server should be dump to /dev/null or a flat file.. Can you help urgently? (1 Reply)
Discussion started by: frustrated1
1 Replies

Featured Tech Videos