我们应该都知道,Linux里,没有C,D盘这样的概念,有的只有目录,一切都是以目录为标准。Linux将所有的硬件设备都当做文件来处理,因此当使用光驱等硬件设备时,必须将其挂载到系统中,只有这样Linux才能识别。
最基本的也是最上层的就是根目录(/),下面可以有很多目录,根目录里可以加载成一个硬盘分区,下面的任意目录,也可以加载另一个硬盘分区,正是因为这种组织方式,挂载必须挂载到某个特定的目录中。在服务器上新添加一块硬盘,重新启动,按F5进入开始做RAID,在此不做介绍。系统启动后通过fdisk查看所有分区信息。
<span style="font-size:12px;">[root@localhost ~]# fdisk -l <span style="color:#ff0000;">Disk /dev/sdb: 599.9 GB, 599932844032 bytes</span> 255 heads, 63 sectors/track, 72937 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 524288 bytes Disk identifier: 0xa70f5417 Disk /dev/sda: 300.0 GB, 299966445568 bytes 255 heads, 63 sectors/track, 36468 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 262144 bytes Disk identifier: 0x00002b09 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 36469 292422656 8e Linux LVM Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 262144 bytes Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_swap: 30.0 GB, 29993467904 bytes 255 heads, 63 sectors/track, 3646 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 262144 bytes Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_home: 215.8 GB, 215759192064 bytes 255 heads, 63 sectors/track, 26231 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 262144 bytes Disk identifier: 0x00000000 </span>通过查看,一块600GB的硬盘已添加成功。
(1)显示帮助菜单,通过fdisk命令来为新的硬盘分区,通过fdisk命令查看,新的硬盘为/dev/sdb
<span style="font-size:12px;">[root@localhost ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x14c853e7. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): </span>输入m后会查看这些命令的介绍
<span style="font-size:12px;">Command (m for help): m Command action a toggle a bootable flag // 设置可引导标记 b edit bsd disklabel // 编辑bsd磁盘标签 c toggle the dos compatibility flag // 设置DOS操作系统兼容标记 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 // 建立空白DOS分区表 p print the partition table // 显示分区列表 q quit without saving changes // 不保存退出 s create a new empty Sun disklabel // 新建空白SUN磁盘标签 t change a partition's system id // 改变一个分区的系统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): </span>(2)新建主分区,输入n开始新建分区
<span style="font-size:12px;">Command (m for help): n Command action e extended // 扩展分区 p primary partition (1-4) // 主分区 p // 先新建一个主分区 Partition number (1-4): 1 // 输入主分区的分区号 First cylinder (1-72937, default 1): // 默认从第一个磁柱开始 Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-72937, default 72937): +300G // 在此输入最后一个磁柱,表示此分区的大小,这里需要大家自己换算一个空间大小,但Linux提供了更加人性化的表示方式,可以直接输入空间大小+300G </span>(3)新建扩展分区,再次输入n新建
<span style="font-size:12px;">Command (m for help): n Command action e extended p primary partition (1-4) e // 新建扩展分区 Partition number (1-4): 2 // 分区号 First cylinder (39164-72937, default 39164): // 默认即可 Using default value 39164 Last cylinder, +cylinders or +size{K,M,G} (39164-72937, default 72937): // 若把剩余的空间全部分给扩展分区,默认即可,若只利用其一部分,按上述的步骤操作 Using default value 72937 </span>
(4)查看分区情况,输入p
<span style="font-size:12px;">Command (m for help): p Disk /dev/sdb: 599.9 GB, 599932844032 bytes 255 heads, 63 sectors/track, 72937 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 524288 bytes Disk identifier: 0x14c853e7 Device Boot Start End Blocks Id System /dev/sdb1 1 39164 314584544+ 83 Linux Partition 1 does not start on physical sector boundary. /dev/sdb2 39164 72937 271281876+ 5 Extended </span>
(5)新建逻辑分区
<span style="font-size:12px;">Command (m for help): n Command action l logical (5 or over) // 逻辑分区 p primary partition (1-4) l // 新建逻辑分区 First cylinder (39164-72937, default 39165): // 从扩展分区中划分逻辑分区 Using default value 39165 Last cylinder, +cylinders or +size{K,M,G} (39165-72937, default 72937): Using default value 72937 </span>再次查看可知:
<span style="font-size:12px;">Command (m for help): p Disk /dev/sdb: 599.9 GB, 599932844032 bytes 255 heads, 63 sectors/track, 72937 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 262144 bytes / 524288 bytes Disk identifier: 0x14c853e7 Device Boot Start End Blocks Id System /dev/sdb1 1 39164 314584544+ 83 Linux Partition 1 does not start on physical sector boundary. /dev/sdb2 39164 72937 271281876+ 5 Extended /dev/sdb5 39165 72937 271281622+ 83 Linux Partition 5 does not start on physical sector boundary. </span>
由上述信息可知,逻辑分区的分区号是从5开始的,这是因为主分区+扩展分区最多只能分4个,而逻辑分区可以分若干个,SCSI最多可分16个逻辑分区,IDE最多分63个分区。
输入w保存退出<span style="font-size:12px;">Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.</span>
建立好分区之后,要对其进行格式化操作。
<span style="font-size:12px;">[root@localhost ~]# mkfs -t ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) /dev/sdb1 alignment is offset by 229888 bytes. This may result in very poor performance, (re)-partitioning suggested. Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=64 blocks, Stripe width=128 blocks 19668992 inodes, 78646136 blocks 3932306 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 2401 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.</span>
主分区已格式化完成,接下来格式化扩展分区
[root@localhost ~]# mkfs -t ext4 /dev/sdb2 mke2fs 1.41.12 (17-May-2010) mkfs.ext4: inode_size (128) * inodes_count (0) too big for a filesystem with 0 blocks, specify higher inode_ratio (-i) or lower inode count (-N).结果显示出现错误,这是因为直接格式化扩展分区是不允许的,只能格式化主分区和逻辑分区。
[root@localhost ~]# mkfs -t ext4 /dev/sdb5 mke2fs 1.41.12 (17-May-2010) /dev/sdb5 alignment is offset by 2048 bytes. This may result in very poor performance, (re)-partitioning suggested. Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=64 blocks, Stripe width=128 blocks 16957440 inodes, 67820405 blocks 3391020 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 2070 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkdir /disk1 [root@localhost ~]# mkdir /home/disk5挂载
[root@localhost ~]# mount /dev/sdb1 /disk1 [root@localhost ~]# mount /dev/sdb5 /home/disk5查看
[root@localhost ~]# mount /dev/mapper/VolGroup-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) /dev/mapper/VolGroup-lv_home on /home type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) <span style="color:#ff0000;">/dev/sdb1 on /disk1 type ext4 (rw) /dev/sdb5 on /home/disk5 type ext4 (rw)</span>挂载成功!
查看分区的UUID
[root@localhost ~]# blkid /dev/sda1: UUID="c52896c1-468e-49a1-a57a-5c4dd643230c" TYPE="ext4" /dev/sda2: UUID="t8tBtG-4gaK-8OQH-lHdO-qUUt-OHE8-rrJb8B" TYPE="LVM2_member" /dev/mapper/VolGroup-lv_root: UUID="0ea03348-489d-4e85-a6c9-dba25dc9bfa4" TYPE="ext4" /dev/mapper/VolGroup-lv_swap: UUID="06dcde24-f621-4e07-9846-1a2be5d3025d" TYPE="swap" /dev/mapper/VolGroup-lv_home: UUID="507c118a-e085-4d05-b349-d8a9f10b861c" TYPE="ext4" <span style="color:#ff0000;">/dev/sdb1: UUID="de95793a-c343-464b-a799-373ab1d9eb18" TYPE="ext4" /dev/sdb5: UUID="548429b6-d343-4049-8775-0fb46c71945d" TYPE="ext4" </span>修改/etc/fstab文件
[root@localhost ~]# vi /etc/fstab # # /etc/fstab # Created by anaconda on Thu Apr 14 05:59:56 2016 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/VolGroup-lv_root / ext4 defaults 1 1 UUID=c52896c1-468e-49a1-a57a-5c4dd643230c /boot ext4 defaults 1 2 /dev/mapper/VolGroup-lv_home /home ext4 defaults 1 2 /dev/mapper/VolGroup-lv_swap swap swap defaults 0 0 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 proc defaults 0 0 <span style="color:#ff0000;">UUID=de95793a-c343-464b-a799-373ab1d9eb18 /disk1 ext4 defaults 1 2 UUID=548429b6-d343-4049-8775-0fb46c71945d /home/disk5 ext4 defaults 1 2</span>因为fstab是系统启动的一个重要文件,所以我们要用mount -a来查看,若没有报错,则说明配置正确。
[root@localhost ~]# mount -a再次查看确认
[root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root ext4 50G 769M 46G 2% / tmpfs tmpfs 32G 0 32G 0% /dev/shm /dev/sda1 ext4 485M 33M 427M 8% /boot /dev/mapper/VolGroup-lv_home ext4 198G 188M 188G 1% /home <span style="color:#ff0000;">/dev/sdb1 ext4 296G 191M 281G 1% /disk1 /dev/sdb5 ext4 255G 188M 242G 1% /home/disk5</span>
若fstab文件写错,则在开机启动时会报错,这时就不能远程对其进行操作,需要在本机上对fstab文件进行修改,但用vi/vim是编辑不了文件,这时候需要输入
[root@localhost~]# mount -o remount,rw /
此时就可以再次修改fstab这个文件了。