fdisk磁盘分区&GPT大于2T磁盘分区

part1. fdisk磁盘分区

总结:磁盘分区其实就是
1.fdisk [待分区磁盘路径]
2.输入n开始分区
3.w 保存退出

Command (m for help): n // 这里用n 创建新分区
Partition type: 
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p //主分区
Partition number (1-4, default 1): //不填 默认
Using default value 1
First sector (2048-125829119, default 2048): //不填 默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-125829119, default 125829119): +30G //需要分配的磁盘大小

查看磁盘

前几天买的服务器,突然发现买的60G数据盘没有。

先用fdisk -l(记得用root 或者 sudo) 查看下所有磁盘。

root@VM-154-45-ubuntu:/media# fdisk -l

Disk /dev/vda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 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 identifier: 0x000e8237

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    16775167     8386560   83  Linux

Disk /dev/vdb: 64.4 GB, 64424509440 bytes
16 heads, 63 sectors/track, 124830 cylinders, total 125829120 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 identifier: 0x00000000

Disk /dev/vdb doesn't contain a valid partition table

Disk /dev/vdc: 2147 MB, 2147483648 bytes
16 heads, 63 sectors/track, 4161 cylinders, total 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
Disk identifier: 0x00000000

我们发现这句话:Disk /dev/vdb doesn't contain a valid partition table

说明/dev/vdb这个磁盘没有格式化。

格式化磁盘

先输入命令:fdisk /dev/vdb

root@VM-154-45-ubuntu:/media# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe09449b2.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m // 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
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)   

出现如上。

然后
前面都可以过,一直到Last sector 表示要分配的空间大小

Command (m for help): n // 这里用n 创建新分区
Partition type: 
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p //主分区
Partition number (1-4, default 1): //不填 默认
Using default value 1
First sector (2048-125829119, default 2048): //不填 默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-125829119, default 125829119): +40G //这里填写空间大小 用+号可以直接写要多大空间,不填就默认所有空间都用上。

然后

Command (m for help): w //推出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.  

然后
如果要格式化磁盘 mkfs

格式化硬盘:

#最新格式是ext4 , 就不要用ext3 了
mkfs.ext4 -t ext4 /dev/vdb1

挂硬盘

在此之前要先将原/data目录的文件复制到别处,以保证挂载之后,其余项目可以正常工作

mount -t ext4 /dev/vdb1 /data/

将挂载信息写入文件

不然,下次重启还得再人工挂。

echo '/dev/vdb1 /data/ ext4 defaults 1 2' >> /etc/fstab

或者直接到fstab 去写

part2 linux大于2T的磁盘使用GPT分区方式

对sdb进行分区,sda是系统盘, 不可分区操作
# parted /dev/sdb 
将MBR磁盘格式化为GPT
(parted) mklabel gpt  

划分所有空间到一个分区
(parted) mkpart primary 0 -1

下面都一样:

  • 格式化
    mkfs.ext4 -t ext4 /dev/vdb1

  • 挂盘
    mount -t ext4 /dev/vdb1 /data/

  • 将挂载信息写入文件
    echo '/dev/vdb1 /data/ ext4 defaults 1 2' >> /etc/fstab

  • mount -r
    测试fstab mount 文件是否生效

你可能感兴趣的:(fdisk磁盘分区&GPT大于2T磁盘分区)