新增一块硬盘
首先用fdisk -l 发现待分区的磁盘 /dev/sdb
root@ubuntu:/home/vincent# fdisk -l
Disk /dev/sdb: 30 GiB, 32212254720 bytes, 62914560 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/sda: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0x83f32b97
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 39845887 39843840 19G 83 Linux
/dev/sda2 39847934 41940991 2093058 1022M 5 Extended
/dev/sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris
root@ubuntu:/home/vincent#
可以看到/dev/sdb/没有分区
对/dev/sdb进行分区
root@ubuntu:/home/vincent# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x5440707b.
Command (m for help): m
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-62914559, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-62914559, default 62914559):
Created a new partition 1 of type 'Linux' and of size 30 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
重新查看硬盘分区,发现/dev/sdb/ 分了/dev/sdb1
格式化分区
root@ubuntu:/home/vincent# mkfs -t ext3 /dev/sdb
mke2fs 1.42.13 (17-May-2015)
Found a dos partition table in /dev/sdb
Proceed anyway? (y,n) y
Creating filesystem with 7864320 4k blocks and 1966080 inodes
Filesystem UUID: d4b47420-ff25-479e-8641-9af726be66ef
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
root@ubuntu:
挂载/dev/sdb
root@ubuntu:/home/vincent# mount /dev/sdb /mnt/
开启自动挂载/dev/sdb
在给系统新增了磁盘以后,如果重启系统我们会发现找不到存储了;但是使用fdisk -l可以看到存储空间,说明存储还在。这是因为关机后,挂载已经自动卸载掉了。我们当然可以手动再次将其挂载,但如果每次重启都需要这样手动操作会很不方便;因此我们可以利用自动挂载,这样系统每次开机的时候就可以自动将磁盘挂载上去了。
修改/etc/fstab文件
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda1 during installation
UUID=d0a34ba5-22af-4897-913c-8cb8e8116000 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=494805d7-8640-406d-96c8-3b90e85244e7 none swap sw 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
/dev/sdb /mnt auto defaults 0 0
可以很明显的看到文件有6列。
第1列是设备名或者卷标
第2列是挂载点(也就是挂载目录)
第3列是所要挂载设备的文件系统或者文件系统类型
第4列是挂载选项,通常使用defaults就可以
第5列设置是否使用dump备份,置0为不备份,置1,2为备份,但2的备份重要性比1小
第6列设置是否开机的时候使用fsck检验所挂载的磁盘,置0为不检验,置1,2为检验,但置2盘比置1的盘晚检验。
将/dev/sdb挂载到/mnt, 文件系统自动选择,不进行dump备份以及开机磁盘检验
注意:
(1)根目录必须优先于其他挂载点
(2)挂载点必须为已经存在的目录
(3)卸载时必须保证当前磁盘没有发生读写操作
fdisk 最大只能创建2T的硬盘,如需要更大则使用parted命令:
parted /dev/sdb 进入分区命令行模式,可以随时用help来查看命令用法
mklabel gpt 将MBR格式的磁盘格式化为GPT格式
mkpart primary 0 -1 将整个磁盘化为一个分区,一般命名为/dev/sdb1
print 打印分区结果
quit 退出分区命令行模式
Linux硬盘分区与挂载指南

2427

被折叠的 条评论
为什么被折叠?



