centos7 添加硬盘和分区
首先查看系统中的硬盘 [root@svnhost ~]# fdisk -l Disk /dev/sda: 120.0 GB, 120034123776 bytes, 234441648 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 label type: dos Disk identifier: 0x00033922 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 234440703 116707328 8e Linux LVM Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/centos-swap: 12.0 GB, 12004098048 bytes, 23445504 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 /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 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 /dev/mapper/centos-home: 53.8 GB, 53750005760 bytes, 104980480 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 系统中有2块盘/dev/sda和/dev/sdb./dev/sda已经做好分区。下面对/dev/sdb做分区 [root@svnhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x8626c507. 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 g create a new empty GPT partition table G create an IRIX (SGI) partition table 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//新建主分区 Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-3905945599, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-3905945599, default 3905945599): +500G//输入分区大小 Partition 1 of type Linux and of size 500 GiB is set Command (m for help): p //打印分区 Disk /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 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 label type: dos Disk identifier: 0x8626c507 Device Boot Start End Blocks Id System /dev/sdb1 2048 1048578047 524288000 83 Linux Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (1048578048-3905945599, default 1048578048): Using default value 1048578048 Last sector, +sectors or +size{K,M,G} (1048578048-3905945599, default 3905945599): +500G Partition 2 of type Linux and of size 500 GiB is set Command (m for help): p Disk /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 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 label type: dos Disk identifier: 0x8626c507 Device Boot Start End Blocks Id System /dev/sdb1 2048 1048578047 524288000 83 Linux /dev/sdb2 1048578048 2097154047 524288000 83 Linux Command (m for help): n //新建扩展分区 Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): e Partition number (3,4, default 3): First sector (2097154048-3905945599, default 2097154048): Using default value 2097154048 Last sector, +sectors or +size{K,M,G} (2097154048-3905945599, default 3905945599): Using default value 3905945599 Partition 3 of type Extended and of size 862.5 GiB is set Command (m for help): p Disk /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 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 label type: dos Disk identifier: 0x8626c507 Device Boot Start End Blocks Id System /dev/sdb1 2048 1048578047 524288000 83 Linux /dev/sdb2 1048578048 2097154047 524288000 83 Linux /dev/sdb3 2097154048 3905945599 904395776 5 Extended Command (m for help): n//新建逻辑分区 Partition type: p primary (2 primary, 1 extended, 1 free) l logical (numbered from 5) Select (default p): l Adding logical partition 5 First sector (2097156096-3905945599, default 2097156096): Using default value 2097156096 Last sector, +sectors or +size{K,M,G} (2097156096-3905945599, default 3905945599): Using default value 3905945599 Partition 5 of type Linux and of size 862.5 GiB is set Command (m for help): p Disk /dev/sdb: 1999.8 GB, 1999844147200 bytes, 3905945600 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 label type: dos Disk identifier: 0x8626c507 Device Boot Start End Blocks Id System /dev/sdb1 2048 1048578047 524288000 83 Linux /dev/sdb2 1048578048 2097154047 524288000 83 Linux /dev/sdb3 2097154048 3905945599 904395776 5 Extended /dev/sdb5 2097156096 3905945599 904394752 83 Linux Command (m for help): w //写入新的分区表 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. 创建文件系统 [root@svnhost ~]# mkfs -t ext3 /dev/sdb1 [root@svnhost /]# mkfs -t ext3 /dev/sdb2 [root@svnhost /]# mkfs -t ext3 /dev/sdb5 编辑系统文件 [root@svnhost /]#vi /etc/fstab 添加: /dev/sdb1 /u01 ext3 defaults 0 0 /dev/sdb2 /u02 ext3 defaults 0 0 /dev/sdb5 /u03 ext3 defaults 0 0 至此,新建的硬盘分区在系统重启时就会自动挂载。 主分区,扩展分区和逻辑分区 主分区,也称为主磁盘分区,和扩展分区、逻辑分区一样,是一种分区类型。主分区中不能再划分其他类型的分区,因此每个主分区都相当于一个逻辑磁盘(在这一点上主分区和逻辑分区很相似,但主分区是直接在硬盘上划分的,逻辑分区则必须建立于扩展分区中)。 1. 一个硬盘可以有1到3个主分区和1个扩展分区,也可以只有主分区而没有扩展分区,但主分区必须至少有1个,扩展分区则最多只有1个,且主分区+扩展分区总共不能超过4个。逻辑分区可以有若干个。 (硬盘的第一个扇区最重要,其上面有硬盘主引导记录(占用446bytes)和分区表(占用64 bytes),之所以只能有四个主分区就是因为分区表只有64B,只能装下4条记录) 所以只能有四个主分区的硬盘的限制,并不是操作系统的限制,而最多只能有一个拓展分区则是操作系统的限制 2. 分出主分区后,其余的部分可以分成扩展分区,一般是剩下的部分全部分成扩展分区,也可以不全分,剩下的部分就浪费了。 3. 扩展分区不能直接使用,必须分成若干逻辑分区。所有的逻辑分区都是扩展分区的一部分。 硬盘的容量=主分区的容量+扩展分区的容量; 扩展分区的容量=各个逻辑分区的容量之和。 4. 由主分区和逻辑分区构成的逻辑磁盘称为驱动器(Drive)或卷(Volume)。 5. 激活的主分区会成为“引导分区”(或称为“启动分区”),引导分区会被操作系统和主板认定为第一个逻辑磁盘(在DOS/Windows中会被识别为“驱动器C:”或“本地磁盘C:”,即通称的C盘)。有关DOS/Windows启动的重要文件,如引导记录、boot.ini、ntldr、ntdetect.com等,必须放在引导分区中。