For details about partitions in Linux-Fdisk 1. For details about system partitions through Fdisk: Fdisk-l: [root @ jetsenLin ~] # Fdisk-l www.2cto.com Disk/dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065*512 = 8225280 bytes
Note: The size of this hard disk is 10.7 GB, with 255 magnetic surfaces, 63 sectors, 1305 magnetic bars (cylinders) and each cylinder (magnetic column) the capacity is 8225280 bytes = 8225.280 K (about) = 8.225280 M (about ); device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 1305 10377990 8e Linux LVM id and System indicate one meaning, id does not seem intuitive. We need to specify the id to confirm the partition type when fdisk is a partition. For example, if 7 is used, NTFS partitions are used. In fdisk, t functions are used to specify the partition type. Disk/dev/sdb: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065*512 = 8225280 bytes Disk/dev/sdb doesn't contain a validpartition table description: Hard Disk Partition representation: in Linux, hd * x or sd * x is used: * indicates a, B, and c ...... in addition, the numbers 1, 2, and 3 represented by x ...... hd is mostly an IDE hard disk; sd is mostly a SCSI or mobile storage; Boot: indicates a Boot partition. In the preceding example, sda1 is a Boot partition; Start (Start ): indicates that a partition starts from Xcylinder (magnetic column); End (End): indicates that a partition ends with Ycylinder (magnetic column); www.2cto. com2, learn to use the fdisk help function:
[Root @ jetsenLin ~] # Fdisk/dev/sda Thenumber of cylinders for this disk is set to 1305. there isnothing wrong with that, but this is larger than 1024, and couldin certain setups cause problems with: 1) softwarethat runs at boot time (e.g ., old versions of LILO) 2) booting and partitioning software from other OSs (e.g ., dos fdisk, OS/2 FDISK) Command (m for help ): m --- output help information Commandaction a toggle a bootable flag --- set start partition B edit bsd disklabel --- edit partition tag c toggle the dos compatibility flag d delete a partition -- delete a partition l list known partition types -- list partition type m print this menu -- help n add a new partition -- create a new partition o create a new empty DOS partition table -- create a new blank DOS partition table p print the partition table --- print partition table q quit without saving changes --- exit without saving settings s createa new empty Sun disklabel --- t changea partition's system id --- change partition ID u changedisplay/entry units --- change the display unit v verifythe partition table --- check and verify the partition table w write table to disk and exit --- save the partition table x extra functionality (experts only) command (m for help ):
3. perform operations on disk partitions using Fdisk: Create partitions using Fdisk: [root @ jetsenLin ~] # Fdisk/dev/sdbDevice contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. changes willremain in memory only, until you decide to write them. after that, of course, the previuscontent won't be recoverable. www.2cto.com The number of cylinders for this disk isset to 2610. there is nothing wrong with that, but thisis larger than 1024, and cocould in certa In setups cause problemswith: 1) software that runs at boot time (e.g ., old versions of LILO) 2) booting and partitioning software fromother OSs (e.g ., dos fdisk, OS/2 FDISK) Warning: invalid flag 0x0000 of partitiontable 4 will be corrected by w (rite) Command (m for help ): n --- input m will help out, input n does not print help information Command action e extended p primary partition (1-4) --- specify the partition type e as the extended partition p as the primary partition pPartition number (1-4): 1- -- Define the number of partitions -- a primary partition can have up to four First cylinder (1-2610, default 1 ): 1 --- set the position of the Start partition. Last cylinder or + size or + sizeM or + sizeK (1-2610, default 2610 ): using default value 2610 --- set the ending partition location Command (m for help): w --- save the configuration information just now. The partition table has been altered! Calling ioctl () to re-read partition table. Syncing disks. [root @ jetsenLin ~] # Www.2cto.com Fdisk: [root @ jetsenLin ~] # Fdisk/dev/sdb The number of cylinders for this disk isset to 2610. there is nothing wrong with that, but thisis larger than 1024, and cocould in certain setups cause problemswith: 1) software that runs at boot time (e.g ., old versions of LILO) 2) booting and partitioning software fromother OSs (e.g ., dos fdisk, OS/2 FDISK) Command (m for help): d --- d Indicates deletion and lists the number of partitions on the current disk. Selected partition 1 Command (m for help): p ---- p indicates that after the disk is deleted, several remaining partitions are displayed. Disk/dev/sdb: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065*512 = 8225280 bytes Device Boot Start End Blocks Id System ---- No partitions available Command (m for help ): w ---- Save The operation and take effect of The partition table has been altered! Calling ioctl () to re-read partition table. WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy. the kernel still uses the old table. the new table will be used at the nextreboot.
An error is reported here. The partition table is in use. Delete the table and then start Syncing disks. --- synchronize the new disk information [root @ jetsenLin ~]. # Fdisk-l/dev/sdb Disk/dev/sdb: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065*512 = 8225280 bytes Device Boot Start End Blocks Id System www.2cto.com use the fdisk command to create a partition of the specified size and add a partition Fdisk n to create the partition: [root @ jetsenLin ~] # Fdisk/dev/sdb The number of cylinders for this disk isset to 2610. there is nothing wrong with that, but thisis larger than 1024, and cocould in certain setups cause problemswith: 1) software that runs at boot time (e.g ., old versions of LILO) 2) booting and partitioning software fromother OSs (e.g ., dos fdisk, OS/2 FDISK) Command (m for help): n --- create partition Command action e extended p primary partition (1- 4) -- specify the partition type as the primary partition pPartition number (1-4): 1 -- specify the actual partition number First cylinder (1-2610, default 1 ): 1 -- specify the start cylinder or + size or + sizeM or + sizeK (1-2610, default 2610): 1024 --- specify the end cylindrical number Command (m for help ): w --- save partition configuration information The partition table has been altered! Calling ioctl () to re-read partition table. www.2cto.com WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy. the kernel still uses the old table. the new table will be used at the nextreboot. syncing disks.
Add partition: [root @ jetsenLin ~] # Fdisk/dev/sdb ----- Add The partition The number of cylinders for this disk isset to 2610. there is nothing wrong with that, but thisis larger than 1024, and cocould in certain setups cause problemswith: 1) software that runs at boot time (e.g ., old versions of LILO) 2) booting and partitioning software fromother OSs (e.g ., dos fdisk, OS/2 FDISK) Command (m for help): n --- partition type Command action e extended p primary par Tition (1-4) --- specify the primary partition pPartition number (1-4): 1 --- Partition number. I specify 1. Partition 1is already defined. delete it beforere-adding it. -The system prompts that partition Number 1 already exists. After deletion, Run Command (m for help): n -- we re-create the partition Command action e extended p primary partition (1-4) -- specify the partition type pPartition number (1-4): 2 --- because partition 1 already exists, we specify partition 2 to pass. First cylinder (1025-2610, default 1025): --- specifies the starting primary column number. The default value is the First number after the previous partition. Using default value 1025 Last cylinder or + size or + sizeM or + sizeK (1025-2610, default 2610): 2000 -- specify the termination period column number. Www.2cto.com Command (m for help): w --- save The partition configuration The partition table has been altered! Calling ioctl () to re-read partition table. WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy. the kernel still uses the old table. the new table will be used at the nextreboot. syncing disks. [root @ jetsenLin ~] # Use the fdisk command to modify the existing partition type Fdisk. Use the t parameter to specify the view partition type [root @ jetsenLin ~] # Fdisk-l/dev/sdb view partition information, type: Linux, id: 83 Disk/dev/sdb: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065*512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 1 1024 8225248 + 83 Linux/dev/sdb2 1025 2000 7839720 83 Linux modify partition type [root @ jetsenLin ~] # Fdisk/dev/sdb The number of cylinders for this disk isset to 2610. there is nothing wrong with that, but thisis larger than 1024, and cocould in certain setups cause problemswith: 1) software that runs at boot time (e.g ., old versions of LILO) 2) booting and partitioning software fromother OSs (e.g ., dos fdisk, OS/2 FDISK) www.2cto.com Command (m for help): t --- enter modify Partition type Partition number (1-4): 1 --- specify The partition code Hex code (type L tolist codes) to be modified: 6 --- specify the Partition Number as 6, that is, FAT16 Note: view the partition type code, here, you can enter L to view The Changed system type of partition 1 to 6 (FAT16) Command (m for help): w --- save The partition table has been altered! Calling ioctl () to re-read partition table. WARNING: Re-reading the partition tablefailed with error 16: Device or resource busy. the kernel still uses the old table. the new table will be used at the nextreboot. WARNING: If you have created or modifiedany DOS 6. xpartitions, please see the fdisk manualpage for additionalinformation. syncing disks. [root @ jetsenLin ~] # Fdisk-l/dev/sdb --- we can see that FAT16 has been created and the ID has been changed to 6. Disk/dev/sdb: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065*512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 1 1024 8225248 + 6 FAT16/dev/sdb2 1025 2000 7839720 83 Linux [root @ jetsenLin ~] #4. Format and load partitions: the command for formatting partitions is as follows. mkfs is followed by the file system type to be formatted: mkfs. bfs www.2cto.com mkfs. ext2mkfs. ext3mkfs. jfsmkfs. msdosmkfs. vfatmkfs. cramfsmkfs. minixmkfs. reiserfsmkfs. xfs format partition: [root @ jetsenLin ~] # Mkfs. ext4/dev/sdb1 --- format the partition type as ext4mke4fs 1.41.5 (23-Apr-2009) Filesystem label = --- we do not specify the volume label, so there is no OS type: linux --- operating system type Block size = 4096 (log = 2) -- size of a single Block Fragment size = 4096 (log = 2) -- chip size: 1310720 inodes, 5241198blocks262059 blocks (5.00%) reserved for the super userFirst data block = 0 Maximum filesystem blocks = 0160 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperbloc K backups stored on blocks: 32768,983 04, 163840,229 376, 294912,819200, 884736,160 5632, 2654208,409 6000 www.2cto.com Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks andfilesystem accounting information: done This filesystem will beautomatically checked every 27 mounts or180 days, whichever comesfirst. use tune4fs-c or-I to override. attaching a disk: (temporary mounting) [root @ jetsenLin ~] # Mkdir/data -- create a mount directory [root @ jetsenLin ~] # Mount/dev/sdb1/data -- mount/dev/sdb1 to/data to verify whether the mount is successful. [root @ jetsenLin ~] # Df-hFilesystem Size Used Avail Use % Mounted on/dev/mapper/VolGroup00-LogVol00 7.7G 3.1G 4.2G 43%/dev/sda1 99 M 12 M 82 M 13%/boottmpfs 506 M 0 506 M 0%/dev/shm/dev/sdb1 20G 16 K 20G 1%/data -- we can see that the mounting is successful. [Root @ jetsenLin ~] # Attaching a disk: (permanent mounting) use the vi editor to edit the/etc/fstab file. The content is as follows (the red part is just added ): whether to back up the self-check sequence/dev/VolGroup00/LogVol00/ext3 defaults 1 1 LABEL =/boot ext3 defaults 1 2 tmpfs/dev/ shm tmpfs defaults 0 0 devpts/dev/pts devpts gid = 5, mode = 620 0 0 sysfs/sys sysfs defaults 0 0 proc/proc defaults 0 0/dev/VolGroup00/LogVol01swap swap defaults 0 0/data/dev/sdb1 ext4 default 0 0 fourth column mount parameters: check man mount to check whether the Fifth Column is backed up: (0 indicates no backup, 1 indicates backup, and generally no backup is required) Column 6 self-check program (0 indicates no self-check, 1 or 2 indicates self-check. If the root partition needs to be set to 1, other partitions can only be 2) by Wu weilong