Linux 添加新硬盘
1.在 /dev/ 目录下找到新的硬盘,sda 为本地硬盘,sda1、sda2.. 为分区,sdb 就是新添加的硬盘,如:
[root@wusuyuan ~]# ls -ltr /dev/sd*brw-rw----. 1 root disk 8, 0 11月 14 14:12 /dev/sdabrw-rw----. 1 root disk 8, 3 11月 14 14:12 /dev/sda3brw-rw----. 1 root disk 8, 2 11月 14 14:12 /dev/sda2brw-rw----. 1 root disk 8, 1 11月 14 14:12 /dev/sda1brw-rw----. 1 root disk 8, 16 11月 14 14:12 /dev/sdb
学习的机器为虚拟机,与真实的物理机器略有不同,真实的物理机器根据硬盘接口类型(IDE、SATA、SCSI、光纤通道和SAS)可能为hda、sda或其它的名称。
2.使用管理员权限对新的硬盘 /dev/sdb 分区:
[root@wusuyuan ~]# fdisk /dev/sdb ####进入分区Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0xb7ee5a9d.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 toswitch off the mode (command ‘c‘) and change display units to
sectors (command ‘u‘).Command (m for help): m #### 查询帮助
Command actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitionl list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition‘s system id
u change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)Command (m for help): n ####创建新的分区
Command actione extendedp primary partition (1-4)e ####选择分区类型(扩展分区、主分区)Partition number (1-4): 1 ####分区数,这里分1个区First cylinder (1-2610, default 1): 2610 ####这里输入分区大小,默认单位为mb
Command (m for help): p ####查看分区表信息
Disk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x35b64cadDevice Boot Start End Blocks Id System/dev/sdb1 2610 2610 8032+ 5 ExtendedCommand (m for help): w ####写入分区信息,如果未确定或想取消,输入q退出
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.
在写入分区信息时要仔细核对和确认,写入分区信息后不可再更改。 分区完成后,新的硬盘还是不能使用的,需要进行格式化。
3.使用mkfs进行格式化硬盘分区:
[sywu@wusuyuan ~]$ mkfsUsage: mkfs [-V] [-t fstype] [fs-options] device [size]#-t 格式化分区类型,如 ext3、ext4[root@wusuyuan ~]# mkfs -t ext4 /dev/sdb #对分区进行格式化,类型为ext4mke2fs 1.41.12 (17-May-2010)/dev/sdb is entire device, not just one partition!无论如何也要继续? (y,n) y文件系统标签=操作系统:Linux块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks1310720 inodes, 5242880 blocks262144 blocks (5.00%) reserved for the super user
第一个数据块=0Maximum filesystem blocks=4294967296160 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000正在写入inode表: 完成Creating journal (32768 blocks): 完成Writing superblocks and filesystem accounting information:完成This filesystem will be automatically checked every 35 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
分区格式化完成后使用mount 命令装载新的分区:
[root@wusuyuan ~]# mount /dev/sdb /disk2 #装载分区[root@wusuyuan ~]# df -h #查询分区文件系统 容量 已用 可用 已用%% 挂载点/dev/sda2 97G 9.9G 82G 11% /tmpfs 1.9G 200M 1.7G 11% /dev/shm/dev/sda1 194M 52M 133M 28% /boot/dev/sdb 20G 1.9G 17G 11% /disk2
4.配置新的分区自动装载:
#在/etc/fstab 中配置分区自动装载[root@wusuyuan ~]# vim /etc/fstab## /etc/fstab# Created by anaconda on Sun Jan 5 08:17:56 2014## 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
#UUID=9c738ca5-810a-46ec-b896-57fc8286b2a5 / ext4 defaults 1 1UUID=05b44d26-bd3a-4688-81e1-c83da70512a7 /boot ext4 defaults 1 2UUID=7146f132-f77b-4a17-8686-d7c9c9be10ad swap swap defaults 0 0tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0/dev/sdb /disk2 ext4 defaults 1 2 #加入新的分区信息
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。