最近學習分區的時候,請教了一個朋友,相對於他,我是要膜拜的,他提到了說如今在實操操做中,不多會在一塊硬盤上分不少個區,如今實際生產中都是以「T」開頭的,因此說我能夠學習一下parted進行分區,而後在網上看了一些文檔,而後結合本身的系統進行分區掛載等操做。node
首先虛擬機上新添加了一個8T的硬盤,添加完成後從新啓動一下虛擬機,linux
查看如今分區windows
[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 顯示我如今新添加的硬盤爲8Tbash
我如今要把這8T的硬盤進行分區 (主分區:100G 第二個分區爲7.6T 第三個分區爲100G)ide
#對/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格式的優缺點能夠本身百度。)this
(parted) mklabel gpt #硬盤轉換爲gpt格式
(parted) mkpart primary ext4 # 劃分一個100G的主分區 Start? 1 End? 100G
# 劃分第二分區 spa
(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呢。沒有進麼分區,那麼如今我要把第三個分區刪除掉從新分區。orm
#刪除第三個分區ip
(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 到止:分區所有完成。