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 01-10-2005, 03:47 PM   #1
jobesd
LQ Newbie
 
Registered: Nov 2001
Posts: 29

Rep: Reputation: 15
sfdisk problem


I have been trying to use sfdisk using the cmd

sfdisk /dev/hdb < Test.data

However it doesn't seam to work as advertized in my reading everywhere.



My Test.data file

;;83;*;


My Result

root@xxxxxxxx: /www: sfdisk /dev/hdb < Test.data
Checking that no-one is using this disk right now ...
OK

Disk /dev/hdb: 2097 cylinders, 16 heads, 63 sectors/track
Old situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/hdb1 * 0+ 2091 2092- 1054336+ 6 FAT16
/dev/hdb2 0 - 0 0 0 Empty
/dev/hdb3 0 - 0 0 0 Empty
/dev/hdb4 0 - 0 0 0 Empty
partial c,h,s specification?

sfdisk: bad input



So what am I doing wrong?

Last edited by jobesd; 01-10-2005 at 03:51 PM.
 
Old 01-10-2005, 04:10 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 267Reputation: 267Reputation: 267
What is this Test.data file or what is in it? Are you trying to direct the output of the sfdisk command to a file?
 
Old 01-10-2005, 04:20 PM   #3
jobesd
LQ Newbie
 
Registered: Nov 2001
Posts: 29

Original Poster
Rep: Reputation: 15
This is all thats in my Test.data file.

;;83;*;



I read this on the net:

How to use Sfdisk to create or repartition your hard drive.
Well, one powerful feature of sfdisk is to repartition your hard drive or create new partitions. Create a file called "Test.data" which has entries in the following format, one per line, and the fields are comma delimited:
Start, Size, ID, Bootable

Start = cylinder to start at (first available cylinder if left blank), Size = number of cylinders (all if left blank), ID = type of partition (Linux, Swap, MSDOS, or other), and Bootable = if this partition is bootable. There are other options, but we won't get into them in this article.

To make it so you have 1 partition of 136 cylinders, a second partition with 254 cylinders of the SWAP ID (82), and a third Linux partition bootable that grabs the rest of the space (ID = 83), make a file list this,


1,136
101,254,82
201,,83,*

and then issue this command to take this configuration and execute it on your slave hard drive on your secondary controller

/sbin/sfdisk /dev/hdd << Test.data

and then issue this command to see what you did
/sbin/sfdisk /dev/hdd
 
Old 01-10-2005, 04:25 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
I works ok for me. Maybe that little diddy on the end needs to be used for your situation....

Code:
# sfdisk /dev/hda < file.txt
Checking that no-one is using this disk right now ...
OK

Disk /dev/hda: 155061 cylinders, 16 heads, 63 sectors/track
Old situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1          0+  20317   20318-  10240240+   7  HPFS/NTFS
/dev/hda2          0       -       0          0    0  Empty
/dev/hda3          0       -       0          0    0  Empty
/dev/hda4          0       -       0          0    0  Empty
New situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1   *      0+ 155060  155061-  78150743+  83  Linux
/dev/hda2          0       -       0          0    0  Empty
/dev/hda3          0       -       0          0    0  Empty
/dev/hda4          0       -       0          0    0  Empty
Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
 
Old 01-10-2005, 04:29 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 267Reputation: 267Reputation: 267
Are you just trying to partition your new drive with one big Linux partition?
 
Old 01-10-2005, 04:47 PM   #6
jobesd
LQ Newbie
 
Registered: Nov 2001
Posts: 29

Original Poster
Rep: Reputation: 15
This is not a new drive. but it should still work

what version are you using?
mine: sfdisk version 3.07 (aeb@cwi.nl, 990908)

does your file look like mine?

Ok if I use this in my file:

;;83;*

I get this:

Code:
root@xxxxxx: /www: sfdisk  /dev/hdb < Test.data
Checking that no-one is using this disk right now ...
OK

Disk /dev/hdb: 2097 cylinders, 16 heads, 63 sectors/track
Old situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hdb1   *      0+   2091    2092-   1054336+   6  FAT16
/dev/hdb2          0       -       0          0    0  Empty
/dev/hdb3          0       -       0          0    0  Empty
/dev/hdb4          0       -       0          0    0  Empty
unrecognized bootable flag - choose - or *

sfdisk: bad input
root@xxxxxx: /www:
so I added the ; at the end.

;;83;*;


then I got this


Code:
root@xxxxxxxx: /www: sfdisk /dev/hdb < Test.data
Checking that no-one is using this disk right now ...
OK

Disk /dev/hdb: 2097 cylinders, 16 heads, 63 sectors/track
Old situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/hdb1 * 0+ 2091 2092- 1054336+ 6 FAT16
/dev/hdb2 0 - 0 0 0 Empty
/dev/hdb3 0 - 0 0 0 Empty
/dev/hdb4 0 - 0 0 0 Empty
partial c,h,s specification?

sfdisk: bad input

Last edited by jobesd; 01-10-2005 at 04:48 PM.
 
Old 01-10-2005, 05:12 PM   #7
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
# sfdisk -v
sfdisk version 3.07 (aeb@cwi.nl, 990908)

I think the problem is coming from the file editor. When I used kwrite, I got the error.
When I used the vi editor ( vi test.txt ) to put the data in, then the error doesn't exist.

Code:
# kwrite test.txt
# sfdisk /dev/hda < test.txt
Checking that no-one is using this disk right now ...
OK

Disk /dev/hda: 155061 cylinders, 16 heads, 63 sectors/track
Old situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1          0+  20317   20318-  10240240+   7  HPFS/NTFS
/dev/hda2          0       -       0          0    0  Empty
/dev/hda3          0       -       0          0    0  Empty
/dev/hda4          0       -       0          0    0  Empty

sfdisk: long or incomplete input line - quitting
Code:
# vi test.txt
# sfdisk /dev/hda < test.txt
Checking that no-one is using this disk right now ...
OK

Disk /dev/hda: 155061 cylinders, 16 heads, 63 sectors/track
Old situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1          0+  20317   20318-  10240240+   7  HPFS/NTFS
/dev/hda2          0       -       0          0    0  Empty
/dev/hda3          0       -       0          0    0  Empty
/dev/hda4          0       -       0          0    0  Empty
New situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1   *      0+ 155060  155061-  78150743+  83  Linux
/dev/hda2          0       -       0          0    0  Empty
/dev/hda3          0       -       0          0    0  Empty
/dev/hda4          0       -       0          0    0  Empty
Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
 
Old 01-10-2005, 05:15 PM   #8
jobesd
LQ Newbie
 
Registered: Nov 2001
Posts: 29

Original Poster
Rep: Reputation: 15
Now if I do it manually it works.

So why can't I use a file

Code:
root@xxxxxx: ~: sfdisk /dev/hdb << EOF
> ,,83,*
> EOF
Checking that no-one is using this disk right now ...
OK

Disk /dev/hdb: 2097 cylinders, 16 heads, 63 sectors/track
Old situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hdb1   *      0+   2091    2092-   1054336+   6  FAT16
/dev/hdb2          0       -       0          0    0  Empty
/dev/hdb3          0       -       0          0    0  Empty
/dev/hdb4          0       -       0          0    0  Empty
New situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hdb1   *      0+   2096    2097-   1056887+  83  Linux
/dev/hdb2          0       -       0          0    0  Empty
/dev/hdb3          0       -       0          0    0  Empty
/dev/hdb4          0       -       0          0    0  Empty
Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
 
Old 01-10-2005, 05:22 PM   #9
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Quote:
So why can't I use a file
Did you see my note about using a different editor?
 
Old 01-10-2005, 06:03 PM   #10
jobesd
LQ Newbie
 
Registered: Nov 2001
Posts: 29

Original Poster
Rep: Reputation: 15
Well YOU WHERE 100% right

I was uploading a file created on windoz and telneted in to use the cmd.

So I went and used vi on the box directly and walla it worked.



I really appreciate it. I've been running in circles for hours.



Jobesd
 
Old 01-10-2005, 06:19 PM   #11
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
You're welcome!
There is a command to strip newline stuff off of files which are created with some editors like notepad, can't remember exactly what that command is right now.
 
Old 01-10-2005, 06:25 PM   #12
jobesd
LQ Newbie
 
Registered: Nov 2001
Posts: 29

Original Poster
Rep: Reputation: 15
I should have been on the linux box to begin with instead of using telnet. lesson learned.

Thanks again
 
Old 05-04-2020, 09:22 AM   #13
ab1jx
Member
 
Registered: Feb 2017
Posts: 68

Rep: Reputation: Disabled
Read the man page (yes, this is a confusing one) or see https://www.computerhope.com/unix/sfdisk.htm

You can get an example perfect input file by doing sfdisk --dump on a working device:
Code:
 sfdisk --dump /dev/sda > sda.dump
or reverse that:
 sfdisk /dev/sda < sda.dump
That will let you modify an existing layout or make one that's close with something like Gparted, dump it to a file, modify it, put it back. Or email it or publish it, etc. You can always practice on any blank device but an SD card in a reader is especially cheap and expendable. If you need to do sector math apcalc is especially good, you can use big integers like 1024209543168 and it doesn't put them into scientific notation.

And don't use anything but true text editors on these files. It can be in Windows (like Notepad) but then FTP the file back to Linux as text, not binary, so the line ends get converted.

What I'm searching for and not finding is whether you can put comments in there. Guess I should try it. OK, you can use # at the beginning of a line it seems, I didn't try it in the middle of a line. So you can do stuff like:
Code:
label: dos
unit: sectors
device: /dev/sdb
first-lba: 64

# to use:  sfdisk /dev/sdb < try1

# dummy uboot area
/dev/sdb1 : start=      64, size=      4000, type=  6
# stick in an extended
/dev/sdb2 : start=    4064, size=  62329888, type= 85
# now 10 gb swap start 2048 into the extended @ 6112 (wasted space?)
/dev/sdb5 : start=    6112, size=  19531250, type= 82
# now close with a main OS partition
/dev/sdb6 : start= 1953736, size=  60380216, type= 83

# 62333952  sectors in the full sd (32 gb)
# "parted /dev/sdb unit s print" to print sectors

Last edited by ab1jx; 05-04-2020 at 01:52 PM. Reason: tried a #
 
  


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
how to execute sfdisk command quietly kushalkoolwal Programming 4 09-16-2005 02:19 PM
fstab settings and sfdisk etc. zappos Linux - Newbie 2 03-02-2005 01:48 PM
sfdisk and scripting lockejr Linux - General 0 05-29-2003 02:18 PM
fdisk and sfdisk devinWhalen Linux - Distributions 5 04-08-2003 12:20 PM
sfdisk problem A-dummy Linux - General 0 08-09-2002 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:47 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration