time: 2018.3.27linux
SCSI
硬盤fdisk -l
查看是否有未分區的硬盤, 有則說明硬盤添加成功[root@localhost ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000b515e Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 ...
此處爲未分區的
/dev/sdb
web
在Linux系統中,管理硬盤設備最經常使用的方法就當屬fdisk命令了。fdisk命令用於管理磁盤分區,格式爲「fdisk [磁盤名稱]」,它提供了集添加、刪除、轉換分區等功能於一身的「一站式分區服務」。不過與前面講解的直接寫到命令後面的參數不一樣,這條命令的參數(見表6-5)是交互式的,所以在管理硬盤設備時特別方便,能夠根據需求動態調整windows
fdisk
經常使用參數:網絡
參數 | 做用 |
---|---|
m | 查看所有可用的參數 |
n | 添加新的分區 |
d | 刪除某個分區信息 |
l | 列出全部可用的分區類型 |
t | 改變某個分區的類型 |
p | 查看分區表信息 |
w | 保存並退出 |
q | 不保存直接退出 |
3.fdisk /dev/sdb
將硬盤分爲2個分區:app
[root@localhost ~]# fdisk /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): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xe03a1b13 Device Boot Start End Blocks Id System # 添加新分區 Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): # 回車使用默認值, 建立主分區, e爲擴展分區 Using default response p Partition number (1-4, default 1): # 回車默認分區編號爲1 First sector (2048-20971519, default 2048): # 起始扇區, 默認便可 Using default value 2048
無需計算扇區個數, 輸入 +5G 建立容量5G的分區ide
# 無需計算扇區個數, 輸入 +5G 建立容量5G的分區 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +5G Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): p # 查看分區表, 已經添加了一個分區 Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xe03a1b13 Device Boot Start End Blocks Id System /dev/sdb1 2048 10487807 5242880 83 Linux Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): # 主分區 Using default response p Partition number (2-4, default 2): # 分區編號2 First sector (10487808-20971519, default 10487808): # 起始扇區默認 Using default value 10487808 Last sector, +sectors or +size{K,M,G} (10487808-20971519, default 20971519): # 分配剩餘容量 Using default value 20971519 Partition 2 of type Linux and of size 5 GiB is set Command (m for help): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xe03a1b13 Device Boot Start End Blocks Id System /dev/sdb1 2048 10487807 5242880 83 Linux /dev/sdb2 10487808 20971519 5241856 83 Linux # 保存並退出 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# fdisk -l # 此時從新查看分區狀況, 成功 Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000b515e Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xe03a1b13 Device Boot Start End Blocks Id System /dev/sdb1 2048 10487807 5242880 83 Linux /dev/sdb2 10487808 20971519 5241856 83 Linux
# 格式化爲ext4 [root@localhost ~]# mkfs.ext4 /dev/sdb1; mkfs.ext4 /dev/sdb2 ... [root@localhost ~]# mkdir /mnt/sdb1 /mnt/sdb2 [root@localhost ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Mar 22 12:44:05 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 # /dev/mapper/rhel-root / xfs defaults 0 0 UUID=db2c838d-1f2f-4b99-a3a2-191b81914b44 /boot xfs defaults 0 0 /dev/mapper/rhel-swap swap swap defaults 0 0 [root@localhost ~]# echo '/dev/sdb1 /mnt/sdb1 ext4 defaults 0 0' >> /etc/fstab [root@localhost ~]# echo '/dev/sdb2 /mnt/sdb2 ext4 defaults 0 0' >> /etc/fstab [root@localhost ~]# mount -a # 自動掛載 [root@localhost ~]# df -h # 查看掛載狀態和硬盤使用量信息 Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 17G 3.0G 15G 18% / devtmpfs 897M 0 897M 0% /dev tmpfs 912M 84K 912M 1% /dev/shm tmpfs 912M 9.0M 903M 1% /run tmpfs 912M 0 912M 0% /sys/fs/cgroup /dev/sda1 1014M 173M 842M 18% /boot tmpfs 183M 16K 183M 1% /run/user/42 tmpfs 183M 0 183M 0% /run/user/0 /dev/sdb1 4.8G 20M 4.6G 1% /mnt/sdb1 /dev/sdb2 4.8G 20M 4.6G 1% /mnt/sdb2 [root@localhost ~]#
mount -t auto <設備路徑> <掛載點>
spa
-t
<文件系統類型> 指定設備的文件系統類型,常見的有:
ext2
linux目前經常使用的文件系統
msdos
MS-DOS的fat,就是fat16
vfat
windows98經常使用的fat32
nfs
網絡文件系統
iso9660
CD-ROM光盤標準文件系統
ntfs
windows NT/2000/XP的文件系統
auto
自動檢測文件系統 code