Linux disk partition (1): Add, linux disk partition

Source: Internet
Author: User

Linux disk partition (1): Add, linux disk partition

**************************************** ******************************** **************** 

Original works, from "Deep Blue blog" blog, welcome to reprint, reprint please be sure to indicate the source (http://blog.csdn.net/huangyanlong ).

Please leave a message or email (hyldba@163.com) indicating that there is an error. Thank you very much.

****************************************************************** ***********************************

**************************************** **************************************** *********************

Linux hard disk partition (1): Add
**************************************** **************************************** *********************

*************************
Process description

*************************

-- Add disk # fdisk-l -- view disk status # fdisk/dev/sdb -- partition n for/dev/sdb devices -- add partition p/e -- primary partition/logical partition w -- save and exit # mkdir/data -- create a mount directory # mkfs. ext3/dev/sdb -- format the disk as an ext3 file system # fdisk-l -- view the disk again # mount/dev/sdb/data -- mount the disk to the created mount directory # vi /etc/fstab -- modify the Automatic startup Mount entry/dev/sdb/data ext3 defaults 0 0
*************************
Description
*************************
1. the above operations are a summary. If you can understand them, you do not need to browse the following content;
2. The following are two examples to illustrate the operation process.

**************************************** **************************************** *********************

Example 1: Add a 90 GB disk, divide it into one partition ********************************** **************************************** ***************************

*************************
View disk Information
*************************

[root@hyldb /]# fdisk -lDisk /dev/sda: 128.8 GB, 128849018880 bytes255 heads, 63 sectors/track, 15665 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          64      514048+  83  Linux/dev/sda2              65         586     4192965   82  Linux swap / Solaris/dev/sda3             587       15665   121122067+  83  LinuxDisk /dev/sdb: 96.6 GB, 96636764160 bytes255 heads, 63 sectors/track, 11748 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk /dev/sdb doesn't contain a valid partition table
*************************
Disk Partition
*************************
[Root @ hyldb/] # fdisk/dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. changes will remain in memory only, until you decide to write them. after that, of course, the previuscontent won't be recoverable. the number of cylinders for this disk is set to 11748. there is nothing wrong with that, but this is larger than 1024, and cocould I N certain setups cause problems with: 1) software that 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) Warning: invalid flag 0x0000 of partition table 4 will be corrected by w (rite) Command (m for help ): m -- enter m to view help: Command Prompt Command action a toggle a bootable flag B edit bsd disklabel c toggle the dos compatibility flag d dele Te 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): n- -Add the new partition Command action e extended p primary Partition (1-4) p -- input p to add the primary partition Partition number (1-4 ): 1 -- enter the Partition Number First cylinder (1-11748, default 1): Using default value 1 Last cylinder or + size or + sizeM or + sizeK (1-11748, default 11748 ): using default value 11748 Command (m for help): p -- print partition list Disk/dev/sdb: 96.6 GB, 96636764160 bytes255 heads, 63 sectors/track, 11748 cylindersUnits = cylinders of 16065*512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 11748 94365778 + 83 LinuxCommand (m for help): w -- save and exit The partition table has been altered! Calling ioctl () to re-read partition table. Syncing disks.
*************************
Create a mount directory
*************************
[root@hyldb /]# mkdir /data
*************************
Format a disk
*************************
[Root @ hyldb/] # mkfs. ext3/dev/sdb -- format sdb1 in ext3 format. The file system mke2fs 1.39 (29-May-2006)/dev/sdb is entire device, not just one partition! Proceed anyway? (Y, n) yFilesystem label = OS type: LinuxBlock size = 4096 (log = 2) Fragment size = 4096 (log = 2) 11796480 inodes, 23592960 blocks1179648 blocks (5.00%) reserved for the super userFirst data block = 0 Maximum filesystem blocks = 4294967296720 block groups32768 blocks per group, 32768 fragments per group16384 inodes per groupSuperblock backups stored on blocks: 32768,983 04, 163840,229 376, 294912,819 200, 884736,160 5632, 2654208,409 6000, 7962624,112 39424, 20480000 Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 33 mounts or180 days, whichever comes first. use tune2fs-c or-I to override. [root @ hyldb/] # fdisk-lDisk/dev/sda: 128.8 GB, 128849018880 bytes255 heads, 63 sectors/track, 15665 cylindersUnits = cylinders of 16065*512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 64 514048 + 83 Linux/dev/sda2 65 586 4192965 82 Linux swap/ solaris/dev/sda3 587 15665 121122067 + 83 LinuxDisk/dev/sdb: 96.6 GB, 96636764160 bytes255 heads, 63 sectors/track, 11748 cylindersUnits = cylinders of 16065*512 = 8225280 bytesDisk/dev/sdb doesn't contain a valid partition table
*************************
Attach a disk to a specified path
*************************
[root@hyldb /]# mount /dev/sdb /data[root@hyldb /]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda3             112G  4.3G  102G   5% //dev/sda1             487M   17M  445M   4% /boottmpfs                1006M     0 1006M   0% /dev/shm/dev/sdb               89G  184M   84G   1% /data
*************************
Modify automatic disk mounting
*************************
[Root @ xckydb ~] # Vi/etc/fstabLABEL = // 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 LABEL = SWAP-sda2 swap defaults 0 0 0/dev/sdb/data ext3 defaults 0 0 ~~ "/Etc/fstab" 8L, 608C written -- format description/dev/sdb1/u01 ext3 defaults 0 0 directory mounted to the object to be mounted system type file system access permission after boot whether to detect whether to dump after a problem occurs

**************************************** **************************************** *********************

Example 2: Add a 10 GB disk;
2. divide it into six partitions;
3. The three primary partitions are 2 GB respectively;
4. The remaining space is divided into extended partitions, which are divided into two logical partitions: 1 GB. The remaining space is divided into one logical partition.
**************************************** **************************************** *********************

*************************
View disk Information
*************************

[root@hyl ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda1             9.7G  5.4G  3.9G  59% //dev/sda3              35G   17G   17G  50% /hometmpfs                1006M     0 1006M   0% /dev/shm[root@hyl ~]# fdisk -lDisk /dev/sda: 53.6 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1        1305    10482381   83  Linux/dev/sda2            1306        1827     4192965   82  Linux swap / Solaris/dev/sda3            1828        6527    37752750   83  LinuxDisk /dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk /dev/sdb doesn't contain a valid partition table
*************************
Partition for/dev/sdb Devices
*************************
[root@hyl ~]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course, the previouscontent won't be recoverable.The number of cylinders for this disk is set to 1305.There is nothing wrong with that, but this is larger than 1024,and could in certain setups cause problems with:1) software that 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)Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)Command (m for help): mCommand 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)
*************************
Create the first primary partition: 2 GB in size
*************************
Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 1First cylinder (1-1305, default 1): Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +2048M
*************************
Create the second primary partition: 2 GB in size
*************************
Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 1First cylinder (1-1305, default 1): Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +2048MCommand (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 2First cylinder (251-1305, default 251): Using default value 251Last cylinder or +size or +sizeM or +sizeK (251-1305, default 1305): +2048M
*************************
Create the third primary partition: 2 GB in size
*************************
Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 3First cylinder (501-1305, default 501): Using default value 501Last cylinder or +size or +sizeM or +sizeK (501-1305, default 1305): +2048M
*************************
Print the partition list first.
*************************
Command (m for help): pDisk /dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1         250     2008093+  83  Linux/dev/sdb2             251         500     2008125   83  Linux/dev/sdb3             501         750     2008125   83  Linux
*************************
Create an extended partition
*************************
Command (m for help): nCommand action   e   extended   p   primary partition (1-4)eSelected partition 4First cylinder (751-1305, default 751): Using default value 751Last cylinder or +size or +sizeM or +sizeK (751-1305, default 1305): Using default value 1305
*************************
Create the first logical partition: 1 GB in size
*************************
Command (m for help): nFirst cylinder (751-1305, default 751): Using default value 751Last cylinder or +size or +sizeM or +sizeK (751-1305, default 1305): +1024M
*************************
Create the second logical partition: 1 GB in size
*************************
Command (m for help): nFirst cylinder (876-1305, default 876): Using default value 876Last cylinder or +size or +sizeM or +sizeK (876-1305, default 1305): +1024M
*************************
Create the last logical partition with the remaining capacity
*************************
Command (m for help): nFirst cylinder (1001-1305, default 1001): Using default value 1001Last cylinder or +size or +sizeM or +sizeK (1001-1305, default 1305): Using default value 1305
*************************
Print partition list
*************************
Command (m for help): pDisk /dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1         250     2008093+  83  Linux/dev/sdb2             251         500     2008125   83  Linux/dev/sdb3             501         750     2008125   83  Linux/dev/sdb4             751        1305     4458037+   5  Extended/dev/sdb5             751         875     1004031   83  Linux/dev/sdb6             876        1000     1004031   83  Linux/dev/sdb7            1001        1305     2449881   83  Linux
*************************
Save and exit
*************************
Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
*************************
View disk partition
*************************
[Root @ hyl ~] # Fdisk-lDisk/dev/sda: 53.6 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065*512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 1305 10482381 83 Linux/dev/sda2 1306 1827 82 Linux swap/Solaris /dev/sda3 1828 6527 37752750 83 LinuxDisk/dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065*512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 1 250 2008093 + 83 Linux/dev/sdb2 251 500 2008125 83 Linux/dev/ sdb3 501 750 2008125 83 Linux/dev/sdb4 751 1305 4458037 + 5 Extended/dev/sdb5 751 875 1004031 83 Linux/dev/sdb6 876 1000 1004031 83 Linux/dev/sdb7 1001 1305 2449881 83 Linux-from this we can see that, sdb1, sdb2, and sdb3 are primary partitions, and sdb5, sdb6, and sdb7 are logical partitions.
*************************
Example: Format sdb1 as an ext3 File System
*************************
[root@hyl ~]# cd /[root@hyl /]# mkdir data1[root@hyl /]# mkfs.ext3 /dev/sdb1mke2fs 1.39 (29-May-2006)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)251392 inodes, 502023 blocks25101 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=51589939216 block groups32768 blocks per group, 32768 fragments per group15712 inodes per groupSuperblock backups stored on blocks:         32768, 98304, 163840, 229376, 294912Writing inode tables: done                            Creating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 28 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.
*************************
Example: Set automatic mounting for sdb1 at startup

*************************

[Root @ hyl/] # vi/etc/fstab -- set the automatic mounting LABEL = // ext3 defaults 1 1 LABEL =/home 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 LABEL = SWAP-sda2 swap defaults 0 0 0/dev/sdb1/data1 ext3 defaults 0 0 ~~~ "/Etc/fstab" 8L, 608C written [root @ hyl/] # mount/dev/sdb1/data1 [root @ hyl/] # df-hFilesystem Size Used Avail Use % Mounted on/dev/sda1 9.7G 5.4G 3.9G 59% // dev/sda3 35G 17G 17G 50%/hometmpfs 1006 M 0 1006 M 0%/dev/shm/dev/sdb1 1.9G 35 M 1.8G 2%/ data1

**************************************** ******************************** **************** 

Original works, from "Deep Blue blog" blog, welcome to reprint, reprint please be sure to indicate the source (http://blog.csdn.net/huangyanlong ).

Please leave a message or email (hyldba@163.com) indicating that there is an error. Thank you very much.

Reminder: Click the directory to view the directory.

****************************************************************** ***********************************


Partition the disk in linux. Is this correct?

Right?

Linux hard disk partitions in virtual machines,

Mount the hard disk, assuming sdb
Fdisk command manual drive separation (enter the command by H to see instructions)
Primary Partition
Sdb1 10G; P1
Extended partition P2
Sdb5 10G; L5
Sdb6 20G; L6

Format mkfs-t ext3/dev/sdbX
Df Displays disk Information
Umount/dev/sdb6

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.