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