Linux系列之fdisk 分區掛盤
阿新 • • 發佈:2019-03-28
cto gen defaults flag locks inux partition 格式 bytes 2019/3/28 星期四
Linux系列之fdisk 分區掛盤
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
Linux系列之fdisk 分區掛盤