2019/3/28 星期四
Linux系列之fdisk 分区挂盘
[root@hadoop04-184 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 47G 8.3G 39G 18% /
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 8.9M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 173M 842M 18% /boot
tmpfs tmpfs 783M 0 783M 0% /run/user/0
我们的根目录分配了50G 比较少,我们挂一个/data 盘分给100G
//现在虚拟机上,挂载硬盘上去
具体操作如下
[root@hadoop04-184 ~]# fdisk -l
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x7f7d07a7
Device Boot Start End Blocks Id System
Disk /dev/sda: 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 label type: dos
Disk identifier: 0x000e6745
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
Disk /dev/mapper/centos-root: 50.5 GB, 50457477120 bytes, 98549760 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: 2147 MB, 2147483648 bytes, 4194304 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
[root@hadoop04-184 ~]# fdisk /dev/sdb //我们来给/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.
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 *(删除一个分区)
l list known partition types (和ls -l的意思一样的 列出分区的类型)
m print this menu *(打印菜单 就是查看帮助)
n add a new partition *(new 创建一个分区)
o create a new empty DOS partition table
p print the partition table *(print打印分区表)
q quit without saving changes *(quit 退出不保存)
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): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x7f7d07a7
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
e extended 扩展分区
p primary partition (1-4) 主分区
接下来选择p
Partition number (1-4): 1 第一块分区的名字
First sector (2048-2097151, default 2048): 这里直接回车表示默认从2048扇区开始
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): //直接回车把所有的都给1
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x7f7d07a7
Device Boot Start End Blocks Id System
/dev/sdb1 2048 209715199 104856576 83 Linux
Command (m for help): w //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@hadoop04-184 ~]# partprobe /dev/sdb (这里命令是告诉linux内核,我们修改了你的分区表)
partprobe - inform the OS of partition table changes
通知操作系统分区表的变化,不执行这个命令就需要重新启动操作系统 ,执行了这个命令就不需要了。
分区好了,接下来就是格式化
接下来格式化,创建文件系统。
[root@hadoop04-184 ~]# mkfs
mkfs mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs
[root@hadoop04-184 ~]# mkfs.xfs /dev/sdb1
这里命令就是可视化,指定文件系统的类型为xfs
...
...
...
[root@hadoop04-184 ~]# tune2fs -c -1 /dev/sdb1 (不让他检查的意思)
[root@linux6 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 7.1G 1.6G 5.1G 25% /
tmpfs tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 ext4 194M 29M 155M 16% /boot
[root@linux6 /]# cd mnt/
[root@linux6 mnt]# ll
total 0
[root@linux6 mnt]# mkdir data1 (创建挂载点)
[root@linux6 mnt]# ll
total 4
drwxr-xr-x. 2 root root 4096 2017-12-21 15:53 data1
[root@linux6 mnt]# cd ~
[root@linux6 ~]# mount /dev/sdb1 /mnt/data1/ (挂载上去)
[root@linux6 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 7.1G 1.6G 5.1G 25% /
tmpfs tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 ext4 194M 29M 155M 16% /boot
/dev/sdb1 ext4 16M 1.2M 14M 8% /mnt/data1
[root@linux6 ~]# cd /mnt/data1/
[root@linux6 data1]# touch majihui.txt
[root@linux6 data1]# echo "i love datcent" > majihui.txt
[root@linux6 data1]# cat majihui.txt
i love datcent
上面的这个挂载情况,重启服务器之后,就没有了
我们接下里用
挂载可以用设备也可以用uuid 要想让他开机自挂起磁盘的话,就需要在/etc/fstab 上去添加
一般情况下:不用uuid的方法
[root@hadoop04-184 ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Jan 16 18:21:38 2019
#
# 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/centos-root / xfs defaults,noatime 0 0
UUID=94663c29-d395-4cd0-8cac-1f0d6dea8969 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /data xfs defaults,noatime 0 0
然后重启就好了
[root@hadoop04-184 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 47G 8.3G 39G 18% /
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 8.9M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 173M 842M 18% /boot
/dev/sdb1 xfs 100G 1.3G 99G 2% /data
tmpfs tmpfs 783M 0 783M 0% /run/user/0
cm_processes tmpfs 3.9G 1.4M 3.9G 1% /run/cloudera-scm-agent/process