最近学习分区的时候,请教了一个朋友,相对于他,我是要膜拜的,他提到了说现在在实操操作中,很少会在一块硬盘上分很多个区,现在实际生产中都是以“T”开头的,所以说我可以学习一下parted进行分区,然后在网上看了一些文档,然后结合自己的系统进行分区挂载等操作。
首先虚拟机上新添加了一个8T的硬盘,添加完成后重新启动一下虚拟机,
查看现在分区
[root@mytest ]# fdisk -l Disk /dev/sda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdb: 8589.9 GB, 8589934592000 bytes 255 heads, 63 sectors/track, 1044333 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
Disk /dev/sdb: 8589.9 GB 显示我现在新添加的硬盘为8T
我现在要把这8T的硬盘进行分区 (主分区:100G 第二个分区为7.6T 第三个分区为100G)
#对/dev/sdb进行分区(8T)
[root@mytest /]# parted /dev/sdb GNU Parted 2.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands
#因为新挂的硬盘,类似于windows下分区,把MBR格式转换为gpt格式(关于MBR格式和GPT格式的优缺点可以自己百度。)
(parted) mklabel gpt #硬盘转换为gpt格式
(parted) mkpart primary ext4 # 划分一个100G的主分区 Start? 1 End? 100G
# 划分第二分区
(parted) mkpart Partition name? []? #为了后面好分区时好分别标注类似于part1,可以直接回车 File system type? [ext2]? #分区格式可以设置,默认是ext2,现在可以直接回车,一会要格式化 Start? 101G End? 7700G Warning: You requested a partition from 201MB to 7700GB. The closest location we can manage is 200GB to 7700GB. Is this still acceptable to you? #是否确定这样分区 Yes/No? y #确认 y #划分第三个分区 (parted) mkpart Partition name? []? File system type? [ext2]? Start? 8000G End? 8590G Warning: You requested a partition from 8001MB to 8590MB. The closest location we can manage is 8000GB to 8000GB. Is this still acceptable to you? Yes/No? y Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? i #显示/dev/sdb下划分的分区 (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 8590GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 100GB 100GB primary 3 100GB 100GB 512B 2 101GB 7700GB 7599GB
#大家从上面可以看到我第三个分区是大小只有512B因为我第三个分区是从8000的位置开始,然后8590的位置结束(正常添加8T硬盘在系统中会显示7.8G实际使用空间)那么错误出来了,从7700到8000之间不是是还有300M呢。没有进么分区,那么现在我要把第三个分区删除掉重新分区。
#删除第三个分区
(parted) rm Partition number? 3 #确认删除的分区号 (parted) p #删除完分区后查看当前的分区 Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 8590GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 100GB 100GB primary 2 101GB 7700GB 7599GB
#刚才对第三个分区删除了,现在重新对余下的硬盘空间进行分区(从7701开始)
(parted) mkpart Partition name? []? File system type? [ext2]? Start? 7701 End? -1 # -1 相当于到分区最后 (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 8590GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 100GB 100GB primary 3 100GB 101GB 1000MB 2 101GB 7700GB 7599GB
(parted) q #已经分完区,退出分区命令 Information: You may need to update /etc/fstab. #提示不要忘记更新/etc/fstab文件
现在是对硬盘分区完成了,和windows一样,分区完成了要格式化
现在进行格式化:
[root@mytest ~]# mke2fs -t ext4 /dev/sdb1 #对第一个分区进行格式化 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 6111232 inodes, 24413696 blocks 1220684 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 746 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
#第二个分区和第三个分区格式化命令同上
现在进行持载分区:(对于挂载目录自己设置,我是在/root下新建立的alidata文件)
This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@mytest ~]# mkdir alidata/ [root@mytest ~]# mount /dev/sdb1 /root/alidata/ 查看硬盘空间(已经显示刚才挂载的) [root@mytest ~]# df -l Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda3 61522964 1922168 56475600 4% / tmpfs 540092 0 540092 0% /dev/shm /dev/sda1 198337 34099 153998 19% /boot /dev/sdb1 96120588 192176 91045676 1% /root/alidata #可以看到已经被挂载上来 #注:可能在格式化第三个分区的时候会提示如下: [root@mytest ~]# mkfs -t ext4 /dev/sdb3 mke2fs 1.41.12 (17-May-2010) # mkfs.ext4: Device size reported to be zero. Invalid partition specified, or partition table wasn't reread after running fdisk, due to a modified partition being busy and in use. You may need to reboot to re-read your partition table. #提示分区可能出现错误,需要重新启动linux [root@mytest ~]# reboot [root@mytest ~]# mkfs -t ext4 /dev/sdb3 #重启完后继续分区 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 61056 inodes, 244224 blocks 12211 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=251658240 8 block groups 32768 blocks per group, 32768 fragments per group 7632 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done 到止:分区全部完成。