1、創建一個10G分區,並格式爲ext4文件系統;
(1) 要求其block大小爲2048, 預留空間百分比爲2, 卷標爲MYDATA, 默認掛載屬性包含acl;
[root@wangyafei ~]# fdisk -l
磁盤 /dev/sdb:21.5 GB, 21474836480字節,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/sda:128.8 GB,128849018880 字節,251658240 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標籤類型:dos
磁盤標識符:0x000aaf3f
設備Boot Start End Blocks Id System
/dev/sda1 * 2048 4196351 2097152 83 Linux
/dev/sda2 4196352 96479231 46141440 8e Linux LVM
磁盤/dev/mapper/cl-root:42.9 GB, 42945478656 字節,83877888 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤/dev/mapper/cl-swap:4294 MB, 4294967296 字節,8388608 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
[root@wangyafei~]# fdisk /dev/sdb
歡迎使用 fdisk (util-linux 2.23.2)。
更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。
Device does not contain a recognized partition table
使用磁盤標識符0xa3aab447 創建新的 DOS 磁盤標籤。
命令(輸入 m 獲取幫助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分區號 (1-4,默認 1):1
起始扇區(2048-41943039,默認爲 2048):
將使用默認值 2048
Last 扇區, +扇區 or+size{K,M,G} (2048-41943039,默認爲 41943039):+10G
分區 1 已設置爲 Linux 類型,大小設爲 10 GiB
命令(輸入 m 獲取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盤。
[root@wangyafei~]# fdisk -l
磁盤 /dev/sdb:21.5 GB, 21474836480字節,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標籤類型:dos
磁盤標識符:0xa3aab447
設備Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
磁盤 /dev/sda:128.8 GB,128849018880 字節,251658240 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標籤類型:dos
磁盤標識符:0x000aaf3f
設備Boot Start End Blocks Id System
/dev/sda1 * 2048 4196351 2097152 83 Linux
/dev/sda2 4196352 96479231 46141440 8e Linux LVM
磁盤/dev/mapper/cl-root:42.9 GB, 42945478656 字節,83877888 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤/dev/mapper/cl-swap:4294 MB, 4294967296 字節,8388608 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
[root@wangyafei~]# mkfs -b 2048 -t ext4 -L MYDATA -m 2 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系統標籤=MYDATA
OS type: Linux
塊大小=2048(log=1)
分塊大小=2048(log=1)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 5242880 blocks
104857 blocks (2.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=273678336
320 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456,409600, 442368, 802816, 1327104,
2048000, 3981312
Allocating group tables: 完成
正在寫入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@wangyafei~]# tune2fs -o acl /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
[root@wangyafei ~]#
(2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
[root@wangyafei~]# mount -o noexec,noatime /dev/sdb1 /data/mydata
[root@wangyafei ~]# mount | grep sdb1
/dev/sdb1 on /data/mydata type ext4(rw,noexec,noatime,seclabel,data=ordered)
[root@wangyafei ~]#
2、創建一個大小爲1G的swap分區,並創建好文件系統,並啓用之;
[root@wangyafei~]# fdisk /dev/sdb
歡迎使用 fdisk(util-linux 2.23.2)。
更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。
命令(輸入 m 獲取幫助):n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
分區號 (2-4,默認 2):2
起始扇區(20973568-41943039,默認爲 20973568):
將使用默認值 20973568
Last 扇區, +扇區 or+size{K,M,G} (20973568-41943039,默認爲 41943039):+1G
分區 2 已設置爲 Linux 類型,大小設爲 1 GiB
命令(輸入 m 獲取幫助):t
分區號 (1,2,默認 2):2
Hex 代碼(輸入 L 列出所有代碼):82
已將分區“Linux”的類型更改爲“Linuxswap / Solaris”
命令(輸入 m 獲取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 設備或資源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盤。
[root@wangyafei~]# partx -a /dev/sdb
partx: /dev/sdb: error adding partition 1
[root@wangyafei~]# mkswap /dev/sdb2
正在設置交換空間版本 1,大小 = 1048572 KiB
無標籤,UUID=e11cef19-dc78-44d1-8f8b-9993aa6c2f81
[root@wangyafei~]# free
total used free shared buff/cache available
Mem: 2032156 176716 1631596 9132 223844 1660244
Swap: 4194300 0 4194300
[root@wangyafei~]# swapon /dev/sdb2
[root@wangyafei ~]# free
total used free shared buff/cache available
Mem: 2032156 177432 1630828 9132 223896 1659508
Swap: 5242872 0 5242872
[root@wangyafei ~]#
3、寫一個腳本
(1)、獲取並列出當前系統上的所有磁盤設備;
(2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
[root@wangyafei~]# touch DiskInfo_test.sh
[root@wangyafei~]# vim $
[root@wangyafei~]# cat $
#!/bin/bash
#Author:wangyafei
fdisk -l | grep "^/.*"
echo " "
df -lh
[root@wangyafei ~]# bash $
/dev/sdb1 2048 20973567 10485760 83 Linux
/dev/sdb2 20973568 23070719 1048576 82 Linux swap / Solaris
/dev/sda1 * 2048 4196351 2097152 83 Linux
/dev/sda2 4196352 96479231 46141440 8e Linux LVM
文件系統 容量 已用 可用已用% 掛載點
/dev/mapper/cl-root 40G 4.8G 36G 12% /
devtmpfs 982M 0 982M 0% /dev
tmpfs 993M 0 993M 0% /dev/shm
tmpfs 993M 9.0M 984M 1% /run
tmpfs 993M 0 993M 0% /sys/fs/cgroup
/dev/sda1 2.0G 128M 1.9G 7% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb1 9.8G 13M 9.6G 1% /data/mydata