Raspberry Pi_Eng_15.1.1 Partition Management


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


15.1   Management of Logical Storage Device

 

15.1.1  Partition Management

 

A disk can be divided into partitions that are spaces managed independently and divided logically. Partitions are also called "disk slices" or "disklabel". The result of partitioning is managed by partition table in sector 0 of disk.

 

15.1.1.1    "fdisk" Command Manage Partition

 

You can use the "fdisk" command to manage partition on a disk that is installed on your system.

 

[Command Format]

fdisk  [ options ]   [ device ]

 

[Command Overview]

   This processes partition management task for the disk installed in the system.

   User privilege          -- Super user. 

                                    

[Detail Description]

   The device usually has the form of "/dev/sda" or "/dev/sdb". The device name must refer to the entire disk.

   The "fdisk" command can be used as a menu-driven program.

   The "fdisk" command is compatible with DOS-type partition tables, BSD-type disklabels or SUN-type disklabels.

 

[Main Option]

-h

Print help and then exit.

-l

List the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that exists) are used.

-s partition...

Print the size (in blocks) of each given partition.

-C cyls

 

Specify the number of cylinders of the disk. I have no idea why anybody would want to do so.

-S sects

 

Specify the number of sectors per track of the disk. (Not the physical number, of course, but the number used for partition tables.) A reasonable value is 63.

 

 

[Used Example]

Here is to check the current status of the disk in the system. You can check the disk and partition.

 

pi@raspberrypi ~ $ sudo fdisk -l

Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes

4 heads, 16 sectors/track, 486192 cylinders, total 31116288 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0009e011

 

        Device Boot      Start         End      Blocks   Id  System

/dev/mmcblk0p1            8192     1673828      832818+   e  W95 FAT16 (LBA)

/dev/mmcblk0p2         1679360    31050751    14685696   85  Linux extended

/dev/mmcblk0p3        31050752    31116287       32768   83  Linux

/dev/mmcblk0p5         1687552     1810431       61440    c  W95 FAT32 (LBA)

/dev/mmcblk0p6         1818624    17571839     7876608   83  Linux

/dev/mmcblk0p7        17580032    17743871       81920    c  W95 FAT32 (LBA)

/dev/mmcblk0p8        17752064    31047679     6647808   83  Linux

 

Disk /dev/sda: 1000 MB, 1000341504 bytes

16 heads, 32 sectors/track, 3816 cylinders, total 1953792 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *          32     1953791      976880    6  FAT16

 

The following shows that the "fdisk" command for device "/dev/mmcblk0" can proceed with the menu method. Several internal commands can be used to perform partition management task or query the current state.

 

pi@raspberrypi ~ $ sudo fdisk /dev/mmcblk0

Command (m for help):

Command (m for help): m

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partition's system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)

Command (m for help): p

Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes

4 heads, 16 sectors/track, 486192 cylinders, total 31116288 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0009e011

 

        Device Boot      Start         End      Blocks   Id  System

/dev/mmcblk0p1            8192     1673828      832818+   e  W95 FAT16 (LBA)

/dev/mmcblk0p2         1679360    31050751    14685696   85  Linux extended

/dev/mmcblk0p3        31050752    31116287       32768   83  Linux

/dev/mmcblk0p5         1687552     1810431       61440    c  W95 FAT32 (LBA)

/dev/mmcblk0p6         1818624    17571839     7876608   83  Linux

/dev/mmcblk0p7        17580032    17743871       81920    c  W95 FAT32 (LBA)

/dev/mmcblk0p8        17752064    31047679     6647808   83  Linux


 

15.1.1.2    "cfdisk" Command - Menu-Based Disk Operation

 

You can use the "cfdisk" command to perform partition management operation on a disk in your system.

 

[Command Format]

cfdisk  [ options ]   [ /dev/disk ]

 

[Command Overview]

   This performs partition dividing operation of the disk installed in the system.

   User privilege          -- Super user.

 

[Detail Description]

   The "cfdisk" command displays or adjusts information about the disk partition table.

 

[Main Option]

-a

Use an arrow cursor instead of reverse video for highlighting

the current partition.

-z

Start with zeroed partition table. This option is useful when

you want to repartition your entire disk.  Note: this option

does not zero the partition table on the disk; rather, it simply

starts the program without reading the existing partition table.

 

[Used Example]

Here is to run the command on disk "/dev/sda" on your system. The disk Information and partition information in the current state are displayed. You can do the work you need by using the menus at the bottom of the screen.

 

pi@raspberrypi ~ $ sudo cfdisk /dev/sda