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
通知操作系统分区表的变化,不执行这个命令就需要重新启动操作系统 ,执行了这个命令就不需要了。
在centos6.5系统中[root@hdfs-node02-90-149--22 /etc/yum.repos.d]# partprobe /dev/sdb
-bash: partprobe: command not found
解决方法:参考链接为:https://blog.51cto.com/tonychiu/326592
[root@server1 ~]# partprobe
-bash: partprobe: command not found
[root@server1 ~]# yum -y install parted
[root@server1 ~]# partprobe
分区好了,接下来就是格式化 接下来格式化,创建文件系统。
[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
如果要使用uuid的话,那么如何拿到磁盘的uuid呢
[root@metricx02 /]# ls -l /dev/disk/by-uuid
total 0
lrwxrwxrwx. 1 root root 9 Sep 6 15:02 2021-09-06-14-50-48-00 -> ../../sr0
lrwxrwxrwx. 1 root root 10 Sep 6 15:05 747df62f-b37e-41a9-b83d-1193da89dbdb -> ../../sdb1
lrwxrwxrwx. 1 root root 10 Sep 6 15:02 f856d385-fe64-4188-b4f8-51f6089b75e6 -> ../../sda1
方法2:
[root@shd20 kudu]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 1.8T 0 disk
└─sdb1 8:17 0 1.8T 0 part /data1
sda 8:0 0 1.8T 0 disk
├─sda1 8:1 0 200M 0 part /boot/efi
├─sda2 8:2 0 500M 0 part /boot
└─sda3 8:3 0 1.8T 0 part
├─VolGroup01-root (dm-0) 253:0 0 468G 0 lvm /
└─VolGroup01-swap (dm-1) 253:1 0 30G 0 lvm [SWAP]
sdd 8:48 0 1.8T 0 disk
└─sdd1 8:49 0 1.8T 0 part /data3
sde 8:64 0 1.8T 0 disk
└─sde1 8:65 0 1.8T 0 part /data4
sdf 8:80 0 1.8T 0 disk
sdf1 8:81 0 1.8T 0 part /data5
sdg 8:96 0 1.8T 0 disk
└─sdg1 8:97 0 1.8T 0 part /data6
sdh 8:112 0 1.8T 0 disk
└─sdh1 8:113 0 1.8T 0 part /data7
sdc 8:32 0 1.8T 0 disk
└─sdc1 8:33 0 1.8T 0 part /data2
sdi 8:128 0 1.8T 0 disk
└─sdi1 8:129 0 1.8T 0 part /data8
sdj 8:144 0 372G 0 disk
└─sdj1 8:145 0 372G 0 part /datassd
[root@shd20 kudu]# blkid /dev/sdj1
/dev/sdj1: UUID="ac5706ab-0ea8-4a66-be02-79ad726e39f7" TYPE="ext4"
[root@metricx02 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Dec 5 00:08:21 2018
#
# 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=f856d385-fe64-4188-b4f8-51f6089b75e6 / xfs defaults 0 0
UUID=747df62f-b37e-41a9-b83d-1193da89dbdb /data xfs defaults 0 0