Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
The ONE Campaign to make poverty history

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Glossary
MoreInfo
Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
FAQ
Copyright Info
Terms of Use
Privacy Info
Disclaimer
WorkBoard
Thanks
Donations
Advertising
Masthead / Impressum
Your Account

Communication
Feedback
Forums
Private Messages
Surveys

Features
HOWTOs
News Archive
Submit News
Topics
User Articles
Web Links

Google
Google


The Web
linux-tutorial.info

Who's Online
There are currently, 80 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

  

sfdisk



SYNOPSIS

       sfdisk [options] device
       sfdisk -s [partition]


DESCRIPTION

       sfdisk has four (main) uses: list the size of a partition,
       list the partitions on a device, check the partitions on a
       device, and - very dangerous - repartition a device.

   List Sizes
       sfdisk -s partition gives the size of partition in blocks.
       This may be useful in connection with programs like mkswap
       or  so. Here partition is usually something like /dev/hda1
       or /dev/sdb12, but  may  also  be  an  entire  disk,  like
       /dev/xda.
              % sfdisk -s /dev/hda9
              81599
              %
       If the partition argument is omitted, sfdisk will list the
       sizes of all disks, and the total:
              % sfdisk -s
              /dev/hda: 208896
              /dev/hdb: 1025136
              /dev/hdc: 1031063
              /dev/sda: 8877895
              /dev/sdb: 1758927
              total: 12901917 blocks
              %

   List Partitions
       The second type of invocation: sfdisk -l [options]  device
       will  list  the  partitions on this device.  If the device
       argument is omitted, the partitions on all hard disks  are
       listed.
       % sfdisk -l /dev/hdc

       Disk /dev/hdc: 16 heads, 63 sectors, 2045 cylinders
       Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

          Device Boot Start     End   #cyls   #blocks   Id  System
       /dev/hdc1          0+    406     407-   205096+  83  Linux native
       /dev/hdc2        407     813     407    205128   83  Linux native
       /dev/hdc3        814    2044    1231    620424   83  Linux native
       /dev/hdc4          0       -       0         0    0  Empty
       %
       The  trailing  -  and  +  signs indicate that rounding has
       taken place, and that the actual value  is  slightly  less
       (more).   To  see the exact values, ask for a listing with
       sectors as unit.

       sible to use sfdisk  from  a  shell  script.  When  sfdisk
       determines  that its standard input is a terminal, it will
       be conversational; otherwise it will abort on any error.

       BE EXTREMELY CAREFUL - ONE TYPING  MISTAKE  AND  ALL  YOUR
       DATA IS LOST

       As  a  precaution,  one  can  save  the sectors changed by
       sfdisk:
              % sfdisk /dev/hdd -O hdd-partition-sectors.save
              ...
              %

       Then, if you discover that you did something stupid before
       anything else has been written to disk, it may be possible
       to recover the old situation with
              % sfdisk /dev/hdd -I hdd-partition-sectors.save
              %

       (This is not the same as saving the old partition table: a
       readable  version  of the old partition table can be saved
       using the -d option. However, if you create logical parti­
       tions,  the  sectors describing them are located somewhere
       on disk, possibly on sectors that were  not  part  of  the
       partition  table  before.  Thus,  the  information  the -O
       option saves is not a binary version of the output of -d.)

       There are many options.


OPTIONS

       -v or --version
              Print  version  number  of  sfdisk and exit immedi­
              ately.

       -? or --help
              Print a usage message and exit immediately.

       -T or --list-types
              Print the recognized types (system Id's).

       -s or --show-size
              List the size of a partition.

       -g or --show-geometry
              List the kernel's idea of the geometry of the indi­
              cated disk(s).

       -l or --list
              List the partitions of a device.

       -d     Dump  the partitions of a device in a format useful
              example:
                  % sfdisk /dev/hdb -N5
                  ,,,*
                  %
              will make the fifth partition on /dev/hdb  bootable
              (`active')  and change nothing else. (Probably this
              fifth partition is called /dev/hdb5,  but  you  are
              free  to  call  it something else, like `/my_equip­
              ment/disks/2/5' or so).

       -Anumber
              Make the indicated  partition(s)  active,  and  all
              others inactive.

       -c or --id number [Id]
              If  no Id argument given: print the partition Id of
              the indicated partition. If an Id argument is  pre­
              sent:  change the type (Id) of the indicated parti­
              tion to the given value.  This option has  the  two
              very  long  forms  --print-id and --change-id.  For
              example:
                  % sfdisk --print-id /dev/hdb 5
                  6
                  % sfdisk --change-id /dev/hdb 5 83
                  OK
              first reports that /dev/hdb5 has  Id  6,  and  then
              changes that into 83.

       -uS or -uB or -uC or -uM
              Accept  or  report  in  units  of  sectors (blocks,
              cylinders, megabytes, respectively). The default is
              cylinders, at least when the geometry is known.

       -x or --show-extended
              Also  list  non-primary extended partitions on out­
              put, and expect descriptors for them on input.

       -C cylinders
              Specify the number of cylinders, possibly  overrid­
              ing what the kernel thinks.

       -H heads
              Specify  the  number  of heads, possibly overriding
              what the kernel thinks.

       -S sectors
              Specify the number of sectors, possibly  overriding
              what the kernel thinks.

       -f or --force
              Do what I say, even if it is stupid.

              sectors  (in  case  of 34 sectors/track), just like
              certain versions of DOS do.)  Certain Disk Managers
              and boot loaders (such as OSBS, but not LILO or the
              OS/2 Boot Manager) also live in this  empty  space,
              so maybe you want this option if you use one.

       -E or --DOS-extended
              Take   the   starting  sector  numbers  of  "inner"
              extended partitions to be relative to the  starting
              cylinder boundary of the outer one, (like some ver­
              sions of DOS do) rather than to the starting sector
              (like  Linux does).  (The fact that there is a dif­
              ference here  means  that  one  should  always  let
              extended partitions start at cylinder boundaries if
              DOS and Linux should interpret the partition  table
              in the same way.  Of course one can only know where
              cylinder boundaries are when one knows what  geome­
              try DOS will use for this disk.)

       --IBM or --leave-last
              Certain  IBM  diagnostic  programs assume that they
              can use the last cylinder on a disk for  disk-test­
              ing  purposes. If you think you might ever run such
              programs, use this option to tell  sfdisk  that  it
              should  not  allocate the last cylinder.  Sometimes
              the last cylinder contains a bad sector table.

       -n     Go through all the motions,  but  do  not  actually
              write to disk.

       -R     Only  execute the BLKRRPART ioctl (to make the ker­
              nel re-read the partition table). This can be  use­
              ful  for  checking  in advance that the final BLKR­
              RPART will be successful, and also when you changed
              the  partition table `by hand' (e.g., using dd from
              a backup).  If the kernel complains  (`device  busy
              for revalidation (usage = 2)') then something still
              uses the device, and you still have to unmount some
              file system, or say swapoff to some swap partition.

       --no-reread
              When starting a repartitioning of  a  disk,  sfdisk
              checks  that this disk is not mounted, or in use as
              a swap device, and refuses to continue  if  it  is.
              This  option  suppresses  the  test.  (On the other
              hand, the -f option would force sfdisk to  continue
              even when this test fails.)

       -O file
              Just  before  writing the new partition, output the
              sectors that are going to be  overwritten  to  file
              (where  hopefully  file resides on another disk, or

       A partition descriptor has 6 fields:
              struct partition {
                  unsigned char bootable;        /* 0 or 0x80 */
                  hsc begin_hsc;
                  unsigned char id;
                  hsc end_hsc;
                  unsigned int starting_sector;
                  unsigned int nr_of_sectors;
              }

       The  two  hsc fields indicate head, sector and cylinder of
       the begin and the end of the  partition.  Since  each  hsc
       field  only  takes  3  bytes,  only 24 bits are available,
       which does not suffice for big disks (say > 8GB). In fact,
       due  to  the wasteful representation (that uses a byte for
       the number of heads,  which  is  typically  16),  problems
       already  start  with  0.5GB.   However  Linux does not use
       these fields, and problems can arise only  at  boot  time,
       before  Linux  has been started. For more details, see the
       lilo documentation.

       Each partition has a type, its `Id', and if this type is 5
       or  f  (`extended  partition')  the starting sector of the
       partition again contains 4  partition  descriptors.  MSDOS
       only  uses the first two of these: the first one an actual
       data partition, and the second one again an extended  par­
       tition  (or  empty).   In  this  way  one  gets a chain of
       extended  partitions.   Other   operating   systems   have
       slightly  different  conventions.  Linux also accepts type
       85 as equivalent to 5 and f - this can be  useful  if  one
       wants  to  have  extended  partitions under Linux past the
       1024 cylinder boundary, without DOS  FDISK  hanging.   (If
       there  is  no good reason, you should just use 5, which is
       understood by other systems.)

       Partitions that are not primary  or  extended  are  called
       logical.   Often,  one cannot boot from logical partitions
       (because the process of finding them is more involved than
       just looking at the MBR).  Note that of an extended parti­
       tion only the Id and the start are used. There are various
       conventions  about  what to write in the other fields. One
       should not try to use extended partitions for data storage
       or swap.


INPUT FORMAT

       sfdisk reads lines of the form
              <start> <size> <id> <bootable> <c,h,s> <c,h,s>
       where each line fills one partition descriptor.

       Fields  are separated by whitespace, or comma or semicolon
       possibly followed  by  whitespace;  initial  and  trailing
       primary  DOS partitions, DOS assigns C: to the first among
       these that is bootable.)

       Id  is  given  in  hex,  without  the  0x  prefix,  or  is
       [E|S|L|X],  where  L (LINUX_NATIVE (83)) is the default, S
       is LINUX_SWAP (82), E is EXTENDED_PARTITION (5), and X  is
       LINUX_EXTENDED (85).

       The  default  value of start is the first nonassigned sec­
       tor/cylinder/...

       The default value of size is as much  as  possible  (until
       next partition or end-of-disk).

       However, for the four partitions inside an extended parti­
       tion, the defaults are: Linux partition,  Extended  parti­
       tion, Empty, Empty.

       But when the -N option (change a single partition only) is
       given, the default for each field is its previous value.


EXAMPLE

       The command
              sfdisk /dev/hdc << EOF
              0,407
              ,407
              ;
              ;
              EOF
       will partition /dev/hdc just as indicated above.

       With the -x option, the number of input lines  must  be  a
       multiple  of  4: you have to list the two empty partitions
       that you never want using two blank lines. Without the  -x
       option,  you  give  one  line  for the partitions inside a
       extended partition, instead of four,  and  terminate  with
       end-of-file (^D).  (And sfdisk will assume that your input
       line represents the first of four, that the second one  is
       extended, and the 3rd and 4th are empty.)


DOS 6.x WARNING

       The  DOS  6.x FORMAT command looks for some information in
       the first sector of the data area of  the  partition,  and
       treats this information as more reliable than the informa­
       tion in the partition table.  DOS FORMAT expects DOS FDISK
       to  clear the first 512 bytes of the data area of a parti­
       tion whenever a size change occurs.  DOS FORMAT will  look
       at  this extra information even if the /U flag is given --
       we consider this a bug in DOS FORMAT and DOS FDISK.

       partition table program.  For example, you should make DOS
       partitions with the DOS FDISK program and Linux partitions
       with the Linux sfdisk program.


DRDOS WARNINGS

       Stephen  Tweedie  reported  (930515):  `Most  reports   of
       superblock corruption turn out to be due to bad partition­
       ing, with one filesystem overrunning the start of the next
       and corrupting its superblock.  I have even had this prob­
       lem with the supposedly-reliable DRDOS.   This  was  quite
       possibly  due to DRDOS-6.0's FDISK command.  Unless I cre­
       ated a blank track or cylinder between the DRDOS partition
       and  the  immediately  following  one, DRDOS would happily
       stamp all over the start of the next partition.  Mind you,
       as long as I keep a little free disk space after any DRDOS
       partition, I don't have any other problems  with  the  two
       coexisting on the one drive.'

       A.  V.  Le Blanc writes in README.efdisk: `Dr. DOS 5.0 and
       6.0 has been reported to have  problems  cooperating  with
       Linux,  and  with  this  version  of efdisk in particular.
       This efdisk sets the system type to hexadecimal  81.   Dr.
       DOS  seems to confuse this with hexadecimal 1, a DOS code.
       If you use Dr. DOS, use the efdisk command 't'  to  change
       the  system  code  of  any Linux partitions to some number
       less than hexadecimal 80; I suggest  41  and  42  for  the
       moment.'

       A. V. Le Blanc writes in his README.fdisk: `DR-DOS 5.0 and
       6.0 are reported to have difficulties  with  partition  ID
       codes  of  80  or more.  The Linux `fdisk' used to set the
       system type of new partitions to hexadecimal  81.   DR-DOS
       seems to confuse this with hexadecimal 1, a DOS code.  The
       values 82 for swap and 83  for  file  systems  should  not
       cause  problems  with DR-DOS.  If they do, you may use the
       `fdisk' command `t' to change the system code of any Linux
       partitions to some number less than hexadecimal 80; I sug­
       gest 42 and 43 for the moment.'

       In fact, it seems that only 4 bits are significant for the
       DRDOS  FDISK,  so that for example 11 and 21 are listed as
       DOS 2.0. However, DRDOS itself seems to use the full byte.
       I  have  not  been  able  to reproduce any corruption with
       DRDOS or its fdisk.


BUGS

       A corresponding interactive cfdisk (with curses interface)
       is still lacking.

       There are too many options.
  

The Linux Tutorial is always looking for new contributors.


Login
Nickname

Password

Security Code
Security Code
Type Security Code


Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!


Amazon Wish List

Did You Know?
You can help in many different ways.


Friends



Tell a Friend About Us

Bookmark and Share



Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.09 Seconds