"Fossies" - the Fresh Open Source Software Archive

Member "sfdisk-3.07/sfdisk.examples" (17 May 1998, 10904 Bytes) of package /linux/misc/old/sfdisk-3.07.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 Examples of the use of sfdisk 3.0 (to partition a disk)
    2 Input lines have fields <start>,<size>,<type>... - see sfdisk.8.
    3 Usually no <start> is given, and input lines start with a comma.
    4 
    5 Before doing anything with a disk, make sure it is not in use;
    6 unmount all its file systems, and say swapoff to its swap partitions.
    7 (The final BLKRRPART ioctl will fail if anything else still uses
    8 the disk, and you will have to reboot. It is easier to first make
    9 sure that nothing uses the disk, e.g., by testing:
   10 	% umount /dev/sdb1
   11 	% sfdisk -R /dev/sdb
   12 	BLKRRPART: Device or resource busy
   13       * Device busy for revalidation (usage=2)
   14 	% swapoff /dev/sdb3
   15 	% sfdisk -R /dev/sdb
   16       * sdb: sdb1 < sdb5 sdb6 > sdb3
   17 	%
   18 Note that the starred messages are kernel messages, that may be
   19 logged somewhere, or written to some other console.
   20 In sfdisk 3.01 sfdisk automatically does this check, unless told not to.)
   21 
   22 1. One big partition:
   23 	sfdisk /dev/hda << EOF
   24 	;
   25 	EOF
   26 
   27 (If there was garbage on the disk before, you may get error messages
   28 like: `ERROR: sector 0 does not have an msdos signature'
   29 and `/dev/hda: unrecognized partition'. This does not matter
   30 if you write an entirely fresh partition table anyway.)
   31 
   32 The output will be:
   33 -----------------------------------------------------------------------
   34 Old situation:
   35 ...
   36 New situation:
   37 Units = cylinders of 208896 bytes, blocks of 1024 bytes, counting from 0
   38 
   39    Device Boot Start     End   #cyls   #blocks   Id  System
   40 /dev/hda1          0+   1023    1024-   208895+  83  Linux native
   41 Successfully wrote the new partition table
   42   hda: hda1
   43 -----------------------------------------------------------------------
   44 Writing and rereading the partition table takes a few seconds -
   45 don't be alarmed if nothing happens for six seconds or so.
   46 
   47 
   48 2. Three primary partitions: two of size 50MB and the rest:
   49 	sfdisk /dev/hda -uM << EOF
   50 	,50
   51 	,50
   52 	;
   53 	EOF
   54 -----------------------------------------------------------------------
   55 New situation:
   56 Units = megabytes of 1048576 bytes, blocks of 1024 bytes, counting from 0
   57 
   58    Device Boot Start   End     MB   #blocks   Id  System
   59 /dev/hda1         0+    50-    51-    51203+  83  Linux native
   60 /dev/hda2        50+   100-    51-    51204   83  Linux native
   61 /dev/hda3       100+   203    104-   106488   83  Linux native
   62 Successfully wrote the new partition table
   63   hda: hda1 hda2 hda3
   64 -----------------------------------------------------------------------
   65 /dev/hda1 is one block (in fact only half a block) shorter than
   66 /dev/hda2 because its start had to be shifted away from zero in
   67 order to leave room for the Master Boot Record (MBR).
   68 
   69 
   70 3. A 1MB OS2 Boot Manager partition, a 50MB DOS partition,
   71    and three extended partitions (DOS D:, Linux swap, Linux):
   72 	sfdisk /dev/hda -uM << EOF
   73 	,1,a
   74 	,50,6
   75 	,,E
   76 	;
   77 	,20,4
   78 	,16,S
   79 	;
   80 	EOF
   81 -----------------------------------------------------------------------
   82    Device Boot Start   End     MB   #blocks   Id  System
   83 /dev/hda1         0+     1-     2-     1223+   a  OS/2 Boot Manager
   84 /dev/hda2         1+    51-    51-    51204    6  DOS 16-bit FAT >=32M
   85 /dev/hda3        51+   203    153-   156468    5  Extended
   86 /dev/hda4         0      -      0         0    0  Empty
   87 /dev/hda5        51+    71-    21-    20603+   4  DOS 16-bit FAT <32M
   88 /dev/hda6        71+    87-    17-    16523+  82  Linux swap
   89 /dev/hda7        87+   203    117-   119339+  83  Linux native
   90 Successfully wrote the new partition table
   91   hda: hda1 hda2 hda3 < hda5 hda6 hda7 >
   92 -----------------------------------------------------------------------
   93 All these rounded numbers look better in cylinder units:
   94 	% sfdisk -l /dev/hda
   95 -----------------------------------------------------------------------
   96    Device Boot Start     End   #cyls   #blocks   Id  System
   97 /dev/hda1          0+      5       6-     1223+   a  OS/2 Boot Manager
   98 /dev/hda2          6     256     251     51204    6  DOS 16-bit FAT >=32M
   99 /dev/hda3        257    1023     767    156468    5  Extended
  100 /dev/hda4          0       -       0         0    0  Empty
  101 /dev/hda5        257+    357     101-    20603+   4  DOS 16-bit FAT <32M
  102 /dev/hda6        358+    438      81-    16523+  82  Linux swap
  103 /dev/hda7        439+   1023     585-   119339+  83  Linux native
  104 -----------------------------------------------------------------------
  105 But still - why does /dev/hda5 not start on a cylinder boundary?
  106 Because it is contained in an extended partition that does.
  107 Of the chain of extended partitions, usually only the first is
  108 shown. (The others have no name under Linux anyway.) But
  109 these additional extended partitions can be made visible:
  110 	% sfdisk -l -x /dev/hda
  111 -----------------------------------------------------------------------
  112    Device Boot Start     End   #cyls   #blocks   Id  System
  113 /dev/hda1          0+      5       6-     1223+   a  OS/2 Boot Manager
  114 /dev/hda2          6     256     251     51204    6  DOS 16-bit FAT >=32M
  115 /dev/hda3        257    1023     767    156468    5  Extended
  116 /dev/hda4          0       -       0         0    0  Empty
  117 
  118 /dev/hda5        257+    357     101-    20603+   4  DOS 16-bit FAT <32M
  119     -            358    1023     666    135864    5  Extended
  120     -            257     256       0         0    0  Empty
  121     -            257     256       0         0    0  Empty
  122 
  123 /dev/hda6        358+    438      81-    16523+  82  Linux swap
  124     -            439    1023     585    119340    5  Extended
  125     -            358     357       0         0    0  Empty
  126     -            358     357       0         0    0  Empty
  127 
  128 /dev/hda7        439+   1023     585-   119339+  83  Linux native
  129     -            439     438       0         0    0  Empty
  130     -            439     438       0         0    0  Empty
  131     -            439     438       0         0    0  Empty
  132 -----------------------------------------------------------------------
  133 
  134 Why the empty 4th input line? The description of the extended partitions
  135 starts after that of the four primary partitions.
  136 You force an empty partition with a ",0" input line, but here all
  137 space was divided already, so the fourth partition became empty
  138 automatically.
  139 
  140 How did I know about 4,6,a,E,S? Well, E,S,L stand for Extended,
  141 Swap and Linux. The other values are hexadecimal and come from
  142 the table:
  143 	% sfdisk -T
  144 	Id  Name
  145 	
  146 	 0  Empty
  147 	 1  DOS 12-bit FAT
  148 	 2  XENIX root
  149 	 3  XENIX usr
  150 	 4  DOS 16-bit FAT <32M
  151 	 5  Extended
  152 	 6  DOS 16-bit FAT >=32M
  153 	 7  OS/2 HPFS or QNX or Advanced UNIX
  154 	 8  AIX data
  155 	 9  AIX boot or Coherent
  156 	 a  OS/2 Boot Manager
  157 	...
  158 
  159 
  160 4. Preserving the sectors changed by sfdisk.
  161 	% sfdisk -O save-hdd-partition-sectors /dev/hda
  162         ...
  163    will write the sectors overwritten by sfdisk to file.
  164    If you notice that you trashed some partition, you may
  165    be able to restore things by
  166 	% sfdisk -I save-hdd-partition-sectors /dev/hda
  167 	%
  168 
  169 5. Preserving some old partitions.
  170 	% sfdisk -N2 /dev/hda
  171 	...
  172    will only change the partition /dev/hda2, and leave the rest
  173    unchanged. The most obvious application is to change an Id:
  174 	% sfdisk -N7 /dev/hda
  175 	,,63
  176 	%
  177 -----------------------------------------------------------------------
  178 Old situation:
  179 
  180    Device Boot Start     End   #cyls   #blocks   Id  System
  181 /dev/hda1          0+      5       6-     1223+   a  OS/2 Boot Manager
  182 ...
  183 /dev/hda6        358+    438      81-    16523+  82  Linux swap
  184 /dev/hda7        439+   1023     585-   119339+  83  Linux native
  185 
  186 New situation:
  187 
  188    Device Boot Start     End   #cyls   #blocks   Id  System
  189 /dev/hda1          0+      5       6-     1223+   a  OS/2 Boot Manager
  190 ...
  191 /dev/hda6        358+    438      81-    16523+  82  Linux swap
  192 /dev/hda7        439+   1023     585-   119339+  63  GNU HURD
  193 -----------------------------------------------------------------------
  194    Note that changing a logical partition into an empty partition
  195    will decrease the number of all subsequent logical partitions.   
  196 
  197 6. Deleting a partition.
  198 At first I thought of having an option -X# for deleting partitions,
  199 but there are several ways in which a partition can be deleted, and
  200 it is probably better to handle this just as a general change.
  201 	% sfdisk -d /dev/hda > ohda
  202 will write the current tables on the file `ohda'.
  203 -----------------------------------------------------------------------
  204 % cat ohda
  205 # partition table of /dev/hda
  206 unit: sectors
  207 
  208 /dev/hda1 : start=        1, size=   40799, Id= 5
  209 /dev/hda2 : start=    40800, size=   40800, Id=83
  210 /dev/hda3 : start=    81600, size=  336192, Id=83
  211 /dev/hda4 : start=        0, size=       0, Id= 0
  212 /dev/hda5 : start=        2, size=   40798, Id=83
  213 -----------------------------------------------------------------------
  214 In order to delete the partition on /dev/hda3, edit this file
  215 and feed the result to sfdisk again.
  216 -----------------------------------------------------------------------
  217 % emacs ohda
  218 % cat ohda
  219 # partition table of /dev/hda
  220 unit: sectors
  221 
  222 /dev/hda1 : start=        1, size=   40799, Id= 5
  223 /dev/hda2 : start=    40800, size=   40800, Id=83
  224 /dev/hda3 : start=        0, size=       0, Id= 0
  225 /dev/hda4 : start=        0, size=       0, Id= 0
  226 /dev/hda5 : start=        2, size=   40798, Id=83
  227 % sfdisk /dev/hda < ohda
  228 Old situation:
  229 Units = cylinders of 208896 bytes, blocks of 1024 bytes, counting from 0
  230 
  231    Device Boot Start     End   #cyls   #blocks   Id  System
  232 /dev/hda1          0+     99     100-    20399+   5  Extended
  233 /dev/hda2        100     199     100     20400   83  Linux native
  234 /dev/hda3        200    1023     824    168096   83  Linux native
  235 /dev/hda4          0       -       0         0    0  Empty
  236 /dev/hda5          0+     99     100-    20399   83  Linux native
  237 New situation:
  238 Units = sectors of 512 bytes, counting from 0
  239 
  240    Device Boot    Start       End  #sectors  Id  System
  241 /dev/hda1             1     40799     40799   5  Extended
  242 /dev/hda2         40800     81599     40800  83  Linux native
  243 /dev/hda3             0         -         0   0  Empty
  244 /dev/hda4             0         -         0   0  Empty
  245 /dev/hda5             2     40799     40798  83  Linux native
  246 Successfully wrote the new partition table
  247 % sfdisk -l -V /dev/hda
  248 
  249 Disk /dev/hda: 12 heads, 34 sectors, 1024 cylinders
  250 Units = cylinders of 208896 bytes, blocks of 1024 bytes, counting from 0
  251 
  252    Device Boot Start     End   #cyls   #blocks   Id  System
  253 /dev/hda1          0+     99     100-    20399+   5  Extended
  254 /dev/hda2        100     199     100     20400   83  Linux native
  255 /dev/hda3          0       -       0         0    0  Empty
  256 /dev/hda4          0       -       0         0    0  Empty
  257 /dev/hda5          0+     99     100-    20399   83  Linux native
  258 /dev/hda: OK
  259 -----------------------------------------------------------------------
  260 This is a good way of making changes: dump the current status
  261 to file, edit the file, and feed it to sfdisk.
  262 Preserving the file on some other disk could be useful:
  263 if ever the MBR gets thrashed it can be used to restore
  264 the old situation.