]> git.ipfire.org Git - thirdparty/util-linux.git/blob - fdisk/sfdisk.8
Imported from util-linux-2.12 tarball.
[thirdparty/util-linux.git] / fdisk / sfdisk.8
1 .\" Copyright 1995 Andries E. Brouwer (aeb@cwi.nl)
2 .\" May be distributed under the GNU General Public License
3 .\" The `DOS 6.x Warning' was taken from the old fdisk.8, which says
4 .\" -- Copyright 1992, 1993 Rickard E. Faith (faith@cs.unc.edu)
5 .\" -- May be distributed under the GNU General Public License
6 .\" The `DRDOS Warning' was taken from a net post by Stephen Tweedie.
7 .\"
8 .TH SFDISK 8 "1 September 1995" "Linux" "Linux Programmer's Manual"
9 .SH NAME
10 sfdisk \- Partition table manipulator for Linux
11 .SH SYNOPSIS
12 .BR sfdisk " [options] device"
13 .br
14 .BR "sfdisk \-s " [partition]
15 .SH DESCRIPTION
16 .B sfdisk
17 has four (main) uses: list the size of a partition, list the partitions
18 on a device, check the partitions on a device, and - very dangerous -
19 repartition a device.
20
21 .SS "List Sizes"
22 .BI "sfdisk \-s " partition
23 gives the size of
24 .I partition
25 in blocks. This may be useful in connection with programs like
26 .B mkswap
27 or so. Here
28 .I partition
29 is usually something like
30 .I /dev/hda1
31 or
32 .IR /dev/sdb12 ,
33 but may also be an entire disk, like
34 .IR /dev/xda .
35 .br
36 .RS
37 .nf
38 .if t .ft CW
39 % sfdisk \-s /dev/hda9
40 81599
41 %
42 .if t .ft R
43 .fi
44 .RE
45 If the partition argument is omitted,
46 .B sfdisk
47 will list the sizes of all disks, and the total:
48 .br
49 .RS
50 .nf
51 .if t .ft CW
52 % sfdisk \-s
53 /dev/hda: 208896
54 /dev/hdb: 1025136
55 /dev/hdc: 1031063
56 /dev/sda: 8877895
57 /dev/sdb: 1758927
58 total: 12901917 blocks
59 %
60 .if t .ft R
61 .fi
62 .RE
63
64 .SS "List Partitions"
65 The second type of invocation:
66 .BI "sfdisk \-l " "[options] device"
67 will list the partitions on this device.
68 If the device argument is omitted, the partitions on all hard disks
69 are listed.
70 .br
71 .nf
72 .if t .ft CW
73 % sfdisk \-l /dev/hdc
74
75 Disk /dev/hdc: 16 heads, 63 sectors, 2045 cylinders
76 Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0
77
78 Device Boot Start End #cyls #blocks Id System
79 /dev/hdc1 0+ 406 407\- 205096+ 83 Linux native
80 /dev/hdc2 407 813 407 205128 83 Linux native
81 /dev/hdc3 814 2044 1231 620424 83 Linux native
82 /dev/hdc4 0 \- 0 0 0 Empty
83 %
84 .if t .ft R
85 .fi
86 The trailing \- and + signs indicate that rounding has taken place,
87 and that the actual value is slightly less (more).
88 To see the exact values, ask for a listing with sectors as unit.
89
90 .SS "Check partitions"
91 The third type of invocation:
92 .BI "sfdisk \-V " device
93 will apply various consistency checks to the partition tables on
94 .IR device .
95 It prints `OK' or complains. The \-V option can be used together
96 with \-l. In a shell script one might use
97 .BI "sfdisk \-V \-q " device
98 which only returns a status.
99
100 .SS "Create partitions"
101 The fourth type of invocation:
102 .BI "sfdisk " device
103 will cause
104 .B sfdisk
105 to read the specification for the desired partitioning of
106 .I device
107 from its standard input, and then to change the partition tables
108 on that disk. Thus, it is possible to use
109 .B sfdisk
110 from a shell script. When
111 .B sfdisk
112 determines that its standard input is a terminal, it will be
113 conversational; otherwise it will abort on any error.
114 .LP
115 BE EXTREMELY CAREFUL - ONE TYPING MISTAKE AND ALL YOUR DATA IS LOST
116 .LP
117 As a precaution, one can save the sectors changed by
118 .BR sfdisk :
119 .RS
120 .nf
121 .if t .ft CW
122 % sfdisk /dev/hdd \-O hdd-partition-sectors.save
123 \&...
124 %
125 .if t .ft R
126 .fi
127 .RE
128 .LP
129 Then, if you discover that you did something stupid before anything
130 else has been written to disk, it may be possible to recover
131 the old situation with
132 .RS
133 .nf
134 .if t .ft CW
135 % sfdisk /dev/hdd \-I hdd-partition-sectors.save
136 %
137 .if t .ft R
138 .fi
139 .RE
140 .LP
141 (This is not the same as saving the old partition table:
142 a readable version of the old partition table can be saved
143 using the \-d option. However, if you create logical partitions,
144 the sectors describing them are located somewhere on disk,
145 possibly on sectors that were not part of the partition table
146 before. Thus, the information the \-O option saves is not a binary
147 version of the output of \-d.)
148
149 There are many options.
150
151 .SH OPTIONS
152 .TP
153 .BR \-v " or " \-\-version
154 Print version number of
155 .B sfdisk
156 and exit immediately.
157 .TP
158 .BR \-? " or " \-\-help
159 Print a usage message and exit immediately.
160 .TP
161 .BR \-T " or " \-\-list\-types
162 Print the recognized types (system Id's).
163 .TP
164 .BR \-s " or " \-\-show\-size
165 List the size of a partition.
166 .TP
167 .BR \-g " or " \-\-show\-geometry
168 List the kernel's idea of the geometry of the indicated disk(s).
169 .TP
170 .BR \-l " or " \-\-list
171 List the partitions of a device.
172 .TP
173 .BR \-d
174 Dump the partitions of a device in a format useful as input
175 to sfdisk. For example,
176 .br
177 .nf
178 .if t .ft CW
179 % sfdisk -d /dev/hda > hda.out
180 % sfdisk /dev/hda < hda.out
181 .if t .ft R
182 .fi
183 will correct the bad last extended partition that the OS/2
184 fdisk creates.
185 .TP
186 .BR \-V " or " \-\-verify
187 Test whether partitions seem correct. (See above.)
188 .TP
189 .BR \-i " or " \-\-increment
190 Number cylinders etc. starting from 1 instead of 0.
191 .TP
192 .BI \-N " number"
193 Change only the single partition indicated. For example:
194 .br
195 .nf
196 .if t .ft CW
197 % sfdisk /dev/hdb \-N5
198 ,,,*
199 %
200 .if t .ft R
201 .fi
202 will make the fifth partition on /dev/hdb bootable (`active')
203 and change nothing else. (Probably this fifth partition
204 is called /dev/hdb5, but you are free to call it something else,
205 like `/my_equipment/disks/2/5' or so).
206 .TP
207 .BI \-A "number"
208 Make the indicated partition(s) active, and all others inactive.
209 .TP
210 .BI \-c "\fR or " \-\-id " number [Id]"
211 If no Id argument given: print the partition Id of the indicated
212 partition. If an Id argument is present: change the type (Id) of
213 the indicated partition to the given value.
214 This option has the two very long forms \-\-print\-id and \-\-change\-id.
215 For example:
216 .br
217 .nf
218 .if t .ft CW
219 % sfdisk --print-id /dev/hdb 5
220 6
221 % sfdisk --change-id /dev/hdb 5 83
222 OK
223 .if t .ft R
224 .fi
225 first reports that /dev/hdb5 has Id 6, and then changes that into 83.
226 .TP
227 .BR \-uS " or " \-uB " or " \-uC " or " \-uM
228 Accept or report in units of sectors (blocks, cylinders, megabytes,
229 respectively). The default is cylinders, at least when the geometry
230 is known.
231 .TP
232 .BR \-x " or " \-\-show\-extended
233 Also list non-primary extended partitions on output,
234 and expect descriptors for them on input.
235 .TP
236 .BI \-C " cylinders"
237 Specify the number of cylinders, possibly overriding what the kernel thinks.
238 .TP
239 .BI \-H " heads"
240 Specify the number of heads, possibly overriding what the kernel thinks.
241 .TP
242 .BI \-S " sectors"
243 Specify the number of sectors, possibly overriding what the kernel thinks.
244 .TP
245 .BR \-f " or " \-\-force
246 Do what I say, even if it is stupid.
247 .TP
248 .BR \-q " or " \-\-quiet
249 Suppress warning messages.
250 .TP
251 .BR \-L " or " \-\-Linux
252 Do not complain about things irrelevant for Linux.
253 .TP
254 .BR \-D " or " \-\-DOS
255 For DOS-compatibility: waste a little space.
256 (More precisely: if a partition cannot contain sector 0,
257 e.g. because that is the MBR of the device, or contains
258 the partition table of an extended partition, then
259 .B sfdisk
260 would make it start the next sector. However, when this
261 option is given it skips to the start of the next track,
262 wasting for example 33 sectors (in case of 34 sectors/track),
263 just like certain versions of DOS do.)
264 Certain Disk Managers and boot loaders (such as OSBS, but not
265 LILO or the OS/2 Boot Manager) also live in this empty space,
266 so maybe you want this option if you use one.
267 .TP
268 .BR \-E " or " \-\-DOS\-extended
269 Take the starting sector numbers of "inner" extended partitions
270 to be relative to the starting cylinder boundary of the outer one,
271 (like some versions of DOS do) rather than to the starting sector
272 (like Linux does).
273 (The fact that there is a difference here means that one should
274 always let extended partitions start at cylinder boundaries if
275 DOS and Linux should interpret the partition table in the same way.
276 Of course one can only know where cylinder boundaries are when
277 one knows what geometry DOS will use for this disk.)
278 .TP
279 .BR \-\-IBM " or " \-\-leave\-last
280 Certain IBM diagnostic programs assume that they can use the
281 last cylinder on a disk for disk-testing purposes. If you think
282 you might ever run such programs, use this option to tell
283 .B sfdisk
284 that it should not allocate the last cylinder.
285 Sometimes the last cylinder contains a bad sector table.
286 .TP
287 .B \-n
288 Go through all the motions, but do not actually write to disk.
289 .TP
290 .B \-R
291 Only execute the BLKRRPART ioctl (to make the kernel re-read
292 the partition table). This can be useful for checking in advance
293 that the final BLKRRPART will be successful, and also when you
294 changed the partition table `by hand' (e.g., using dd from a backup).
295 If the kernel complains (`device busy for revalidation (usage = 2)')
296 then something still uses the device, and you still have to unmount
297 some file system, or say swapoff to some swap partition.
298 .TP
299 .B \-\-no\-reread
300 When starting a repartitioning of a disk, sfdisk checks that this disk
301 is not mounted, or in use as a swap device, and refuses to continue
302 if it is. This option suppresses the test. (On the other hand, the \-f
303 option would force sfdisk to continue even when this test fails.)
304 .TP
305 .BI \-O " file"
306 Just before writing the new partition, output the sectors
307 that are going to be overwritten to
308 .I file
309 (where hopefully
310 .I file
311 resides on another disk, or on a floppy).
312 .TP
313 .BI \-I " file"
314 After destroying your filesystems with an unfortunate
315 .B sfdisk
316 command, you would have been able to restore the old situation
317 if only you had preserved it using the \-O flag.
318
319 .SH THEORY
320 Block 0 of a disk (the Master Boot Record) contains among
321 other things four partition descriptors. The partitions
322 described here are called
323 .I primary
324 partitions.
325 .LP
326 A partition descriptor has 6 fields:
327 .br
328 .nf
329 .RS
330 struct partition {
331 unsigned char bootable; /* 0 or 0x80 */
332 hsc begin_hsc;
333 unsigned char id;
334 hsc end_hsc;
335 unsigned int starting_sector;
336 unsigned int nr_of_sectors;
337 }
338 .RE
339 .fi
340 .LP
341 The two hsc fields indicate head, sector and cylinder of the
342 begin and the end of the partition. Since each hsc field only
343 takes 3 bytes, only 24 bits are available, which does not
344 suffice for big disks (say > 8GB). In fact, due to the wasteful
345 representation (that uses a byte for the number of heads, which
346 is typically 16), problems already start with 0.5GB.
347 However Linux does not use these fields, and problems can arise
348 only at boot time, before Linux has been started. For more
349 details, see the
350 .B lilo
351 documentation.
352 .LP
353 Each partition has a type, its `Id', and if this type is 5 or f
354 .IR "" "(`" "extended partition" "')"
355 the starting sector of the partition
356 again contains 4 partition descriptors. MSDOS only uses the
357 first two of these: the first one an actual data partition,
358 and the second one again an extended partition (or empty).
359 In this way one gets a chain of extended partitions.
360 Other operating systems have slightly different conventions.
361 Linux also accepts type 85 as equivalent to 5 and f - this can be
362 useful if one wants to have extended partitions under Linux past
363 the 1024 cylinder boundary, without DOS FDISK hanging.
364 (If there is no good reason, you should just use 5, which is
365 understood by other systems.)
366 .LP
367 Partitions that are not primary or extended are called
368 .IR logical .
369 Often, one cannot boot from logical partitions (because the
370 process of finding them is more involved than just looking
371 at the MBR).
372 Note that of an extended partition only the Id and the start
373 are used. There are various conventions about what to write
374 in the other fields. One should not try to use extended partitions
375 for data storage or swap.
376
377 .SH "INPUT FORMAT"
378 .B sfdisk
379 reads lines of the form
380 .br
381 .RS
382 <start> <size> <id> <bootable> <c,h,s> <c,h,s>
383 .RE
384 where each line fills one partition descriptor.
385 .LP
386 Fields are separated by whitespace, or comma or semicolon possibly
387 followed by whitespace; initial and trailing whitespace is ignored.
388 Numbers can be octal, decimal or hexadecimal, decimal is default.
389 When a field is absent or empty, a default value is used.
390 .LP
391 The <c,h,s> parts can (and probably should) be omitted -
392 .B sfdisk
393 computes them from <start> and <size> and the disk geometry
394 as given by the kernel or specified using the \-H, \-S, \-C flags.
395 .LP
396 Bootable is specified as [*|\-], with as default not-bootable.
397 (The value of this field is irrelevant for Linux - when Linux
398 runs it has been booted already - but might play a role for
399 certain boot loaders and for other operating systems.
400 For example, when there are several primary DOS partitions,
401 DOS assigns C: to the first among these that is bootable.)
402 .LP
403 Id is given in hex, without the 0x prefix, or is [E|S|L|X], where
404 L (LINUX_NATIVE (83)) is the default, S is LINUX_SWAP (82), E
405 is EXTENDED_PARTITION (5), and X is LINUX_EXTENDED (85).
406 .LP
407 The default value of start is the first nonassigned sector/cylinder/...
408 .LP
409 The default value of size is as much as possible (until next
410 partition or end-of-disk).
411 .LP
412 However, for the four partitions inside an extended partition,
413 the defaults are: Linux partition, Extended partition, Empty, Empty.
414 .LP
415 But when the \-N option (change a single partition only) is given,
416 the default for each field is its previous value.
417
418 .SH EXAMPLE
419 The command
420 .RS
421 .nf
422 .if t .ft CW
423 sfdisk /dev/hdc << EOF
424 0,407
425 ,407
426 ;
427 ;
428 EOF
429 .if t .ft R
430 .fi
431 .RE
432 will partition /dev/hdc just as indicated above.
433
434 The command
435 .RS
436 .nf
437 .if t .ft CW
438 sfdisk /dev/hdb << EOF
439 ,3,L
440 ,60,L
441 ,19,S
442 ,,E
443 ,130,L
444 ,130,L
445 ,130,L
446 ,,L
447 EOF
448 .if t .ft R
449 .fi
450 .RE
451 will partition /dev/hdb into two Linux partitions of 3 and 60
452 cylinders, a swap space of 19 cylinders, and an extended partition
453 covering the rest. Inside the extended partition there are four
454 Linux logical partitions, three of 130 cylinders and one
455 covering the rest.
456
457 With the \-x option, the number of input lines must be a multiple of 4:
458 you have to list the two empty partitions that you never want
459 using two blank lines. Without the \-x option, you give one line
460 for the partitions inside a extended partition, instead of four,
461 and terminate with end-of-file (^D).
462 (And
463 .B sfdisk
464 will assume that your input line represents the first of four,
465 that the second one is extended, and the 3rd and 4th are empty.)
466
467 .SH "DOS 6.x WARNING"
468
469 The DOS 6.x FORMAT command looks for some information in the first
470 sector of the data area of the partition, and treats this information
471 as more reliable than the information in the partition table. DOS
472 FORMAT expects DOS FDISK to clear the first 512 bytes of the data area
473 of a partition whenever a size change occurs. DOS FORMAT will look at
474 this extra information even if the /U flag is given -- we consider
475 this a bug in DOS FORMAT and DOS FDISK.
476 .LP
477 The bottom line is that if you use sfdisk to change the size of a
478 DOS partition table entry, then you must also use
479 .B dd
480 to zero the first 512 bytes of that partition before using DOS FORMAT to
481 format the partition. For example, if you were using sfdisk to make a DOS
482 partition table entry for /dev/hda1, then (after exiting sfdisk and
483 rebooting Linux so that the partition table information is valid) you
484 would use the command "dd if=/dev/zero of=/dev/hda1 bs=512 count=1" to zero
485 the first 512 bytes of the partition.
486 .B BE EXTREMELY CAREFUL
487 if you use the
488 .B dd
489 command, since a small typo can make all of the data on your disk useless.
490
491 For best results, you should always use an OS-specific partition table
492 program. For example, you should make DOS partitions with the DOS FDISK
493 program and Linux partitions with the Linux sfdisk program.
494
495 .SH "DRDOS WARNINGS"
496
497 Stephen Tweedie reported (930515): `Most reports of superblock
498 corruption turn out to be due to bad partitioning, with one filesystem
499 overrunning the start of the next and corrupting its superblock.
500 I have even had this problem with the supposedly-reliable DRDOS. This
501 was quite possibly due to DRDOS-6.0's FDISK command. Unless I created
502 a blank track or cylinder between the DRDOS partition and the
503 immediately following one, DRDOS would happily stamp all over the
504 start of the next partition. Mind you, as long as I keep a little
505 free disk space after any DRDOS partition, I don't have any other
506 problems with the two coexisting on the one drive.'
507
508 A. V. Le Blanc writes in README.efdisk: `Dr. DOS 5.0 and 6.0 has been
509 reported to have problems cooperating with Linux, and with this version
510 of efdisk in particular. This efdisk sets the system type
511 to hexadecimal 81. Dr. DOS seems to confuse
512 this with hexadecimal 1, a DOS code. If you use Dr. DOS, use the
513 efdisk command 't' to change the system code of any Linux partitions
514 to some number less than hexadecimal 80; I suggest 41 and 42 for
515 the moment.'
516
517 A. V. Le Blanc writes in his README.fdisk: `DR-DOS 5.0 and 6.0
518 are reported to have difficulties with partition ID codes of 80 or more.
519 The Linux `fdisk' used to set the system type
520 of new partitions to hexadecimal 81. DR-DOS seems to confuse this with
521 hexadecimal 1, a DOS code. The values 82 for swap and 83 for file
522 systems should not cause problems with DR-DOS. If they do, you may use
523 the `fdisk' command `t' to change the system code of any Linux
524 partitions to some number less than hexadecimal 80; I suggest 42 and 43
525 for the moment.'
526
527 In fact, it seems that only 4 bits are significant for the DRDOS FDISK,
528 so that for example 11 and 21 are listed as DOS 2.0. However, DRDOS
529 itself seems to use the full byte. I have not been able to reproduce
530 any corruption with DRDOS or its fdisk.
531
532 .SH BUGS
533 A corresponding interactive
534 .B cfdisk
535 (with curses interface) is still lacking.
536 .LP
537 There are too many options.
538 .LP
539 There is no support for non-DOS partition types.
540
541 .SH AUTHOR
542 A. E. Brouwer (aeb@cwi.nl)
543
544 .SH "SEE ALSO"
545 .BR cfdisk (8),
546 .BR fdisk (8),
547 .BR mkfs (8),
548 .BR parted (8)