Linux系统下添加新硬盘
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux系统下添加新硬盘相关的知识,希望对你有一定的参考价值。
Linux系统下添加新硬盘、分区及挂载,通过虚拟机环境实现(VMware12pro+C6.8
2.6.32-642.el6.x86_64 )
1、将硬盘插入后,通过fdisk -l 查看当前系统磁盘信息
[[email protected] ~]# fdisk -l Disk /dev/sda: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000679b2 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 124 786432 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 124 1045 7396352 83 Linux Disk /dev/sdb: 1073 MB, 1073741824 bytes #新磁盘 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
/dev/sdb 是新挂载的磁盘。
2、通过 fdisk /dev/sdb 对磁盘进行分区
[[email protected] ~]# fdisk/dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI orOSF disklabel Building a new DOS disklabel with disk identifier 0x753bb844. 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 correctedby w(rite) WARNING: DOS-compatible mode is deprecated. It‘s stronglyrecommended to switch off the mode(command ‘c‘) and change display units to sectors (command‘u‘). Command (m for help): n #输入n添加一个分区(add a new partition) Command action e extended p primary partition (1-4) p #输入p创建一个主分区 Partition number (1-4): 1 #输入分区编号,是第一个分区输入 1 即可 First cylinder (1-130, default 1): #这里直接回车 默认从1开始 Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): #输入分区大小,默认回车是给所有 Using default value 130 Command (m for help): w # w 将分区表写入磁盘 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
3、再次输入 fdisk -l 查看刚才的分区情况
[[email protected] ~]# fdisk -l Disk /dev/sda: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000679b2 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 124 786432 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 124 1045 7396352 83 Linux Disk /dev/sdb: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xdb4feed0 Device Boot Start End Blocks Id System /dev/sdb1 1 130 1044193+ 83 Linux
最后一个 /dev/sdb1 就是新创建的分区,如果有多个分区命名就是 /dev/sdb2,/dev/sdb3...以此类推。
4、使用 mkfs -t ext4 -c /dev/sdb1 对新创建的分区进行格式化
[[email protected] ~]# mkfs -t ext4 -c /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65280 inodes, 261048 blocks 13052 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8160 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Checking for bad blocks (read-only test): done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 24 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
5、使用mount 对新分区进行挂载
[[email protected] ~]# mount /dev/sdb1 /www/img/
6、使用df -h 命令对分区信息进行查看
[[email protected] ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 6.9G 1.9G 4.7G 29% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 190M 33M 147M 19% /boot /dev/sdb1 988M 1.3M 936M 1% /www/img
也可以 查看 /proc/mounts 查看磁盘挂载情况
[[email protected] ~]# cat /proc/mounts rootfs / rootfs rw 0 0 proc /proc proc rw,relatime 0 0 sysfs /sys sysfs rw,relatime 0 0 devtmpfs /dev devtmpfs rw,relatime,size=487956k,nr_inodes=121989,mode=755 0 0 devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0 tmpfs /dev/shm tmpfs rw,relatime 0 0 /dev/sda3 / ext4 rw,relatime,barrier=1,data=ordered 0 0 /proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0 /dev/sda1 /boot ext4 rw,relatime,barrier=1,data=ordered 0 0 none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0 /dev/sdb1 /www/img ext4 rw,relatime,barrier=1,data=ordered 0 0
7、将挂载信息加入/etc/fstab实现开机自动挂载
[[email protected] ~]# echo "/dev/sdb1 /www/img ext4 defaults 0 0">>/etc/fstab [[email protected] ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Fri Oct 28 11:06: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 # UUID=a9ef6300-ef4a-41f4-8b64-dbf20a1ea507 / ext4 defaults 1 1 UUID=57ba6098-a74e-4f04-b7e8-c947457d397a /boot ext4 defaults 1 2 UUID=606bdc7b-fe6b-48db-b2dd-6624d4842c7d 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 /dev/sdb1 /www/img ext4 defaults 0 0
以上是关于Linux系统下添加新硬盘的主要内容,如果未能解决你的问题,请参考以下文章