linux下磁盘分区工具有parted和fdisk,但是当磁盘超过2T的时候就不能使用fdisk进行分区了,只能使用parted进行分区。
而且parted进行分区的时候,回车之后直接生效,不像fdisk需要按w才会保存,所以使用parted进行分区的时候一定要慎重。
下面我们先看看磁盘的情况,登陆SSH,执行以下命令(下文中黑色标注部分是键入命令)
[root@linuxbox:/root]#fdisk -l
Disk /dev/mtdblock1: 128 KiB, 131072 bytes, 256 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: 2.7 TiB, 3000592982016 bytes, 5860533168 sectors Disk model: WDC WD30PURX-78P Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes
通常使用 fdisk /dev/sda 命令就可以给2T以下分区,但是单块磁盘的大小超过了2T,就需要用到parted命令了,以上磁盘是检测出2.7T空间,所以我们要用到parted命令。
[root@linuxbox:/root]#parted /dev/sda GNU Parted 3.2 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel gpt Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? yes (parted) mkpart primary 0 2.7T Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? i (parted) print Model: ATA WDC WD30PURX-78P (scsi) Disk /dev/sda: 3001GB Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags:
Number Start End Size File system Name Flags 1 17.4kB 3001GB 3001GB primary
(parted) quit Information: You may need to update /etc/fstab.
以上黑色标注为命令,0 2.7T 的意思是分一个从0到2.7T的磁盘分区,一直到quit分区就完成创建了
接下来要给刚才分好的分区格式化成,本次演示的是ext4。在格式化之前先看看刚才成功的分区是什么名字
[root@linuxbox:/root]#fdisk -l Disk /dev/mtdblock8: 128 KiB, 131072 bytes, 256 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: 2.7 TiB, 3000592982016 bytes, 5860533168 sectors Disk model: WDC WD30PURX-78P Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: gpt Disk identifier: C7CD8B87-B63C-4BDE-BCE0-01D58ABA5BE9
Device Start End Sectors Size Type /dev/sda1 34 5860533134 5860533101 2.7T Linux filesystem
Partition 1 does not start on physical sector boundary.
以上信息可以看出来新分区是 /dev/sda1,下来对分区进行格式化
[root@linuxbox:/root]#mkfs.ext4 /dev/sda1 mke2fs 1.43.1 (08-Jun-2016) Creating filesystem with 732566637 4k blocks and 183148544 inodes Filesystem UUID: 9e38ee79-42a9-45c6-98de-b0885eb2c5dc Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848, 512000000, 550731776, 644972544
Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
[root@PandoraBox_1480:/root]#
执行以上命令后会因为磁盘分区大小问题,越大越需要时间格式化,完成后会自动退回至命令行。下来我们要对分区做挂载,这样才可以在系统中看见这个分区。
本演示在在mnt的根目录中建立一个data的文件夹。挂载到到/mnt/data目录中。
[root@linuxbox:/root]#cd /mnt/ [root@linuxbox:/mnt]#ls [root@linuxbox:/mnt]#mkdir data [root@linuxbox:/mnt]#ls data [root@linuxbox:/mnt]#mount /dev/sda1 data [root@linuxbox:/mnt]#df -h Filesystem Size Used Available Use% Mounted on rootfs 11.9M 500.0K 11.4M 4% / /dev/root 18.3M 18.3M 0 100% /rom tmpfs 219.0M 0 19.0M 0% /sys/fs/cgroup tmpfs 512.0K 0 512.0K 0% /dev /dev/sda1 2.7T 88.0M 2.5T 0% /mnt/data
文章 Google 广告 2
最后查看命令 df-h 已经看出来 ,已经挂载成功。