2016/03/10 周四 下午 4点43分
明天老师就要Linux系统目录结构知识了。
一直纠结一个问题:"Linux主机在使用一段时间后,再新添一块磁盘后,怎么识别、格式化分区、挂载。重点是挂载在什么目录下,能否直接挂载到 跟 '/'下?"
介于此问题,随即在网上开始爬文
结论就是 可以挂载到 / 根 下 但貌似没有鸟用。以此引出下面的总结---关于挂载那点事。
首先查看机器上有几块磁盘: fdisk -l
[root@28moban /]# 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: 0x0005a3b0
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 128 819200 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 128 1045 7363584 83 Linux
Disk /dev/sdb: 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: 0x00000000
格式化磁盘并写入文件系统 : mkfs.ext4 /dev/sdb
[root@28moban ~]# mkfs.ext4 /dev/sdb
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 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
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@28moban ~]# mount /dev/sdb /mnt/
或者新建,做为挂载点
[root@28moban ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.8G 1.5G 5.1G 23% /
tmpfs 238M 0 238M 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
/dev/sdb 7.8G 18M 7.4G 1% /mnt
设置开机启动自动挂载
新创建的分区不能开机自动挂载,每次重启机器都要手动挂载。
设置开机自动挂载需要修改/etc/fstab文件
[root@28moban /]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar 1 10:40:56 2016
#
............................华丽丽的省略号..........................................
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/sdb /var ext4 defaults 0 0
卸载磁盘
[root@28moban /]# umount /mnt/
[root@28moban /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.8G 1.5G 5.1G 23% /
tmpfs 238M 0 238M 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
同步数据
[root@28moban ~]# sync
如果可以的话 最好 #reboot 华丽丽的重启一下 !!