Partition operations with Fdisk on Linux
Create a new disk in VirtualBox, log in to the system, perform fdisk-l (requires root access) to view the disk information.
[Email protected]:~# fdisk -ldisk /dev/sda: 8 gib, 8589934592 bytes, 16777216 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/ Optimal): 512 bytes / 512 bytesdisklabel type: dosdisk identifier: 0x7845e939Device Boot Start End Sectors Size Id Type/dev/sda1 * 2048 999423 997376 487m 82 linux swap / Solaris/dev/sda2 1001470 16775167 15773698 7.5g 5 extended/dev/sda5 1001472 16775167 15773696 7.5g 83 linuxdisk /dev/sdb: 8 gib, 8589934592 bytes, 16777216 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/ Optimal): 512 bytes / 512 bytes
Two disk information is listed, SDA and SDB, respectively, with 8G of disk space, and you can see that SDB is a newly created disk.
Partition operations for SDB. By executing the FDISK/DEV/SDB command
[Email protected]:~# fdisk/dev/sdb Welcome to fdisk (Util-linux 2.25.1). Changes'll remain in memory only, until the decide to write them. Be careful before using the Write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x0bbd6176.command (M-help):
Go to command mode and enter M to view Help (the Ubuntu system displays the information below)
command (m for help): mhelp: dos (MBR) a toggle a bootable flag b edit nested bsd disklabel c toggle the dos compatibility flag Generic d delete a partition l list known partition types n add a new partition p print the partition table T change a partition type v verify the partition table Misc m print this menu u change display/entry units x extra functionality (expErts only) save & exit w write table to disk and exit q quit without saving changes create a new label g create a New empty gpt partition table g create a new empty SGI (IRIX) partition table o create a new empty dos partition table s create a new empty Sun partition tableCommand (M FOR HELP):
N creates a new partition, p views the partition information, and T modifies the partition type. Perform the following steps: N to create a new partition, p to create the primary partition, p to view the partition information just now.
command (m for help): npartition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) select (default p): ppartition number (1-4, default 1): 1first sector (2048-16777215, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-16777215, default 16777215): =^h+2gcreated a new partition 1 of type ' Linux ' and of size 2 GiB.Command (m for help):p Disk /dev/sdb: 8 gib, 8589934592 bytes, 16777216 sectorsunits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/opTimal): 512 bytes / 512 bytesdisklabel type: dosdisk identifier: 0x0bbd6176device boot start end sectors Size Id Type/dev/sdb1 2048 4196351 4194304 2g 83 linuxcommand (M&NBSP;FOR&NBSP;HELP): n partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) select (default p): epartition number (2-4, default 2): 2first sector (4196352-16777215, default 4196352): last sector, +sectors or +size{K,M,G,T,P} (4196352-16777215, default 16777215): created a new partition 2 of type ' Extended ' and of size 6 GiB.Command (m for help): npartition type p primary (1 primary, 1 extended, 2 free) l logical (numbered from 5) select ( default p): ladding logical partition 5first sector (4198400-16777215, default 4198400): last sector, +sectors or +size{k,m,g,t,p} ( 4198400-16777215, default 16777215): +2gcreated a new partition 5 of type ' Linux ' and of size 2 GiB.Command (m for help): pdisk /dev/sdb: 8 gib, 8589934592 bytes, 16777216 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (Minimum/optimal): 512 bytes / 512 bytesdisklabel type: dosdisk identifier: 0x0bbd6176device boot start End Sectors Size Id Type/dev/sdb1 2048 4196351 4194304 2g 83 linux/dev/sdb2 4196352 16777215 12580864 6g 5 extended/dev/sdb5 4198400 8392703 4194304 2G 83 LinuxCommand (m for Help): tpartition number (1,2,5, default 5): 1hex code (Type L to list all codes): l 0 empty 24 nec dos 81 minix / old lin bf solaris 1 Fat12 27 hidden ntfs win 82 Linux swap / So c1 DRDOS/sec (fat- 2 xenix root 39 plan 9 83 Linux c4 DRDOS/sec (fat- 3 xenix usr 3c PartitionMagic 84 OS/2 hidden C: c6 drdos/sec (fat- 4 fat16 <32m 40 Venix 80286 85 linux extended c7 syrinx 5 extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 ntfs volume set db cp/m / ctos / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e qnx4.x 2nd part 8e linux lvm df bootit 9 AIX bootable 4f qnx4.x 3rd part 93 amoeba e1 dos access a os/2 boot manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O B w95 fat32 51 ontrack dm6 aux 9f bsd/os e4 speedstor c W95 FAT32 (LBA) 52 CP/M a0 ibm thinkpad hi eb beos fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee gpt f w95 ext ' d (LBA) 54 ontrackdm6 a6 OpenBSD ef EFI (FAT-12/16/10 opus 55 ez-drive a7 NeXTSTEP f0 Linux/PA-RISC b11 Hidden FAT12 56 golden bow a8 darwin ufs f1 speedstor 12 compaq diagnost 5c priam edisk a9 netbsd f4 speedstor 14 hidden fat16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden hpfs/ntf 64 novell netware b7 bsdi fs fc vmware vmkcore 18 ast smartsleep 65 novell Netware b8 bsdi swap fd linux raid auto1b hidden w95 fat3 70 disksecure mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT 1e hidden w95 fat1 80 Old Minix Hex code (type l to list all codes): 83changed type of partition ' Linux ' to ' Linux '. command (m for help): Wthe partition table has been altered. Calling ioctl () to re-read partition table. Syncing disks.
Finally, through W to save the above operation to the hard disk, you can also use the Q command to discard the above partition operation.
Finally, by executing ls/dev/sdb* to see the operation, the Partprobe command updates the hard drive information.
[Email protected]:~# partprobe [email protected]:~# ls/dev/sdb*/dev/sdb/dev/sdb1/dev/sdb2/dev/sdb5
[Email protected]:~# fdisk -ldisk /dev/sda: 8 gib, 8589934592 bytes, 16777216 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/ Optimal): 512 bytes / 512 bytesdisklabel type: dosdisk identifier: 0x7845e939Device Boot Start End Sectors Size Id Type/dev/sda1 * 2048 999423 997376 487m 82 linux swap / Solaris/dev/sda2 1001470 16775167 15773698 7.5g 5 extended/dev/sda5 1001472 16775167 15773696 7.5g 83 linuxdisk /dev/sdb: 8 gib, 8589934592 bytes, 16777216 sectorsunits: sectors of 1 * 512 = 512 bytessector size (logical/physical): 512 bytes / 512 bytesi/o size (minimum/ Optimal): 512 bytes / 512 bytesdisklabel type: dosdisk identifier: 0x0bbd6176Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 4196351 4194304 2g 83 linux/dev/sdb2 4196352 16777215 12580864 6g 5 extended/dev/sdb5 4198400 8392703 4194304 2g 83&nBsp Linux
[Email protected]:~# cat/proc/partitions Major minor #blocks name 0 1048575 sr0 8 0 8388608 s Da 8 1 498688 sda1 8 5 7886848 sda5 8 8388608 SDB 8 2097152 sdb1 8 2097152 SDB5
You can see the results of the partitioning operation from the above 3 commands.
This article from the "7743530" blog, reproduced please contact the author!
Partition operations with Fdisk on Linux