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