學習啦>學習電腦>操作系統(tǒng)>Linux教程>

linux下磁盤怎么分區(qū)(2)

時間: 春健736 分享

  p #分區(qū)類型為主分區(qū)

  Partition number (1-4, default 1): 1 #分區(qū)號,在這里我們依次選擇1、2、3、4

  First sector (2048-496127, default 2048): #指定分區(qū)的起始扇區(qū),一般默認,按enter鍵即可。

  Last sector, +sectors or +size{K,M,G} (2048-496127, default 496127): +50M #指定分區(qū)的終止扇區(qū),根據(jù)前面的提示我們可以做出相應的選擇+sectors 或 +size{K,M,G}

  Command (m for help): p #用p打印出已建好的分區(qū)列表

  Disk /dev/sdb: 254 MB, 254017536 bytes

  8 heads, 61 sectors/track, 1016 cylinders, total 496128 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

  Device Boot Start End Blocks Id System

  /dev/sdb1 2048 104447 51200 83 Linux

  #剩下的三個分區(qū)的建立操作同上

  #分好四個主分區(qū)后的情況如下

  Command (m for help): p

  Disk /dev/sdb: 254 MB, 254017536 bytes

  8 heads, 61 sectors/track, 1016 cylinders, total 496128 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

  Device Boot Start End Blocks Id System

  /dev/sdb1 2048 104447 51200 83 Linux

  /dev/sdb2 104448 206847 51200 83 Linux

  /dev/sdb3 206848 309247 51200 83 Linux

  /dev/sdb4 309248 309298 25+ 83 Linux

  #已經(jīng)建好四個主分區(qū)啦,現(xiàn)在我們來看看如果再建主分區(qū)或是擴展分區(qū)的話會出現(xiàn)怎樣的情況:

  Command (m for help): n

  You must delete some partition and add an extended partition first

  #看到了吧,不能再建分區(qū)啦!要再建分區(qū)的話必須刪除some分區(qū),再新建一個擴展分區(qū)才行。

  #現(xiàn)在,我們刪掉一個主分區(qū),來新建擴展分區(qū)

  Command (m for help): d #刪除分區(qū)

  Partition number (1-4): 4 #選擇要刪除分區(qū)的分區(qū)號,我們選第四個

  Command (m for help): p #打印,如下,四個分區(qū)變成了三個!

  Disk /dev/sdb: 254 MB, 254017536 bytes

  8 heads, 61 sectors/track, 1016 cylinders, total 496128 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

  Device Boot Start End Blocks Id System

  /dev/sdb1 2048 104447 51200 83 Linux

  /dev/sdb2 104448 206847 51200 83 Linux

  /dev/sdb3 206848 309247 51200 83 Linux

  #新建一個擴展分區(qū)

  #如果在沒有建滿三個主分的區(qū)的情況下建立擴展分區(qū),相關選項會有些不同。

  Command (m for help): n

  Command action

  e extended

  p primary partition (1-4)

  e

  Selected partition 4

  First sector (309248-496127, default 309248): #enter,默認

  Using default value 309248

  Last sector, +sectors or +size{K,M,G} (309248-496127, default 496127): #enter,默認,使用剩余空間

  Using default value 496127

  Command (m for help): p

  Disk /dev/sdb: 254 MB, 254017536 bytes

  8 heads, 61 sectors/track, 1016 cylinders, total 496128 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

  Device Boot Start End Blocks Id System

  /dev/sdb1 2048 104447 51200 83 Linux

  /dev/sdb2 104448 206847 51200 83 Linux

  /dev/sdb3 206848 309247 51200 83 Linux

  /dev/sdb4 309248 496127 93440 5 Extended

  #接下來,我們在新建的擴展分區(qū)里再新建兩個邏輯分區(qū),因為已經(jīng)有了三個主分區(qū),這里不會再顯示是建立邏輯分區(qū)還是主分區(qū)的提示!

  Command (m for help): n

  First sector (311296-496127, default 311296): #enter

  Using default value 311296

  Last sector, +sectors or +size{K,M,G} (311296-496127, default 496127): +50M

  Command (m for help): n

  First sector (415744-496127, default 415744): #enter

  Using default value 415744

  Last sector, +sectors or +size{K,M,G} (415744-496127, default 496127): #enter

  Using default value 496127

  Command (m for help): p

  Disk /dev/sdb: 254 MB, 254017536 bytes

  8 heads, 61 sectors/track, 1016 cylinders, total 496128 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

  Device Boot Start End Blocks Id System

  /dev/sdb1 2048 104447 51200 83 Linux

  /dev/sdb2 104448 206847 51200 83 Linux

  /dev/sdb3 206848 309247 51200 83 Linux

  /dev/sdb4 309248 496127 93440 5 Extended

  /dev/sdb5 311296 413695 51200 83 Linux

  /dev/sdb6 415744 496127 40192 83 Linux

  #上面的列表,就是我們今天分區(qū)的成果啦!接下來保存退出,重啟計算機,就可以進行下一步的mkfs操作啦!如果忘記了相關的操作命令,記得按m!!!

  Command (m for help): w #保存

  The partition table has been altered!

  Calling ioctl() to re-read partition table.

  Syncing disks.

  另:在建好分區(qū)后,我們還可以更改相關分區(qū)的文件系統(tǒng)類型

  #如,我們要把第二個主分區(qū)改成Linux下的交換分區(qū),操作如下

  Command (m for help): t #更改文件系統(tǒng)類型

  Partition number (1-6): 2 #選擇第二個分區(qū)

  Hex code (type L to list codes): L #選擇要更改的文件系統(tǒng)編碼,可以按L來查看相關編碼信息。

  0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris

  1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-

  2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-

  3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-

  ............

  16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS

  17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE

  18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto

  1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep

  1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT

  1e Hidden W95 FAT1

  Hex code (type L to list codes): 82 #查找到linux swap的編碼為82

  Changed system type of partition 2 to 82 (Linux swap / Solaris)

  Command (m for help): p

  ..............

  Device Boot Start End Blocks Id System

  /dev/sdb1 2048 104447 51200 83 Linux

  /dev/sdb2 104448 206847 51200 82 Linux swap / Solaris

  /dev/sdb3 206848 309247 51200 83 Linux

  /dev/sdb4 309248 496127 93440 5 Extended

  /dev/sdb5 311296 413695 51200 83 Linux

  /dev/sdb6 415744 496127 40192 83 Linux

  #最后別忘了保存!如果你須要的話!

  #擴展分區(qū)不能直接使用,邏輯分區(qū)只能建立在擴展分區(qū)上!

  第二步:mkfs(mkfs時分區(qū)的格式最好與fdisk設定的分區(qū)格式一致,不然.......)

  mkfs支持ext2 ext3 vfa msdos jfs reiserfs等文件系統(tǒng)。

  用法1:mkfs -t

  例: mkfs -t ext3 /dev/sdb2

  用法2:mkfs.

  例:mkfs,vfat /dev/sdb3

  mke2fs支持ext2/ext3文件系統(tǒng)

  用法:mke2fs [-j]

  例:mke2fs -j /dev/sdb5

  # 更多更具體的用法請參照相關命令的man手冊

  下面,接著實驗:

  例一

  [root@novice ~]# mkfs -t ext3 /dev/sdb1

  mke2fs 1.41.12 (17-May-2010)

  Filesystem label=

  OS type: Linux

  Block size=1024 (log=0)

  Fragment size=1024 (log=0)

  Stride=0 blocks, Stripe width=0 blocks

  12824 inodes, 51200 blocks

  2560 blocks (5.00%) reserved for the super user

  First data block=1

  Maximum filesystem blocks=52428800

  7 block groups

  8192 blocks per group, 8192 fragments per group

  1832 inodes per group

  Superblock backups stored on blocks:

  8193, 24577, 40961

  Writing inode tables: done

  Creating journal (4096 blocks): done

  Writing superblocks and filesystem accounting information: done

  This filesystem will be automatically checked every 34 mounts or

  180 days, whichever comes first. Use tune2fs -c or -i to override.

  例二:

  [root@novice ~]# fdisk /dev/sdb

  Command (m for help): t

  Partition number (1-6): 6

  Hex code (type L to list codes): L

  0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris

  1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-

  2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-

  3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-

  4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx

  5 Extended 42 SFS 86 NTFS volume set da Non-FS data

  6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .

  7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility

  .........

  Hex code (type L to list codes): 7

  Changed system type of partition 6 to 7 (HPFS/NTFS)

  Command (m for help): p

  Disk /dev/sdb: 254 MB, 254017536 bytes

  8 heads, 61 sectors/track, 1016 cylinders, total 496128 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

  Device Boot Start End Blocks Id System

  /dev/sdb1 2048 104447 51200 83 Linux

  /dev/sdb2 104448 206847 51200 82 Linux swap / Solaris

  /dev/sdb3 206848 309247 51200 83 Linux

  /dev/sdb4 309248 496127 93440 5 Extended

  /dev/sdb5 311296 413695 51200 83 Linux

  /dev/sdb6 415744 496127 40192 7 HPFS/NTFS

  Command (m for help): w

  The partition table has been altered!

  Calling ioctl() to re-read partition table.

  Syncing disks.

  [root@novice ~]# mkfs.ntfs /dev/sdb6

  Cluster size has been automatically set to 4096 bytes.

  Initializing device with zeroes: 100% - Done.

  Creating NTFS volume structures.

  mkntfs completed successfully. Have a nice day.

  第三部:掛載

  掛載:mount

  例:mount /dev/sdb1 /mnt /sdb1

  卸載:umonut

  例:umount /dev/sdb1

  /etc/fstab:

  可以把要掛載的分區(qū)寫入/etc/fstab,這樣在開機的時候就能自動掛載啦!

  #關于mount/nmout具體用法請參照man手冊,/etc/fstab內(nèi)的掛載格式,參數(shù)等在該文件內(nèi)都有相關的說明。這里只做一個簡單的測試,不再累述!

  [root@novice /]# cd /mnt

  [root@novice mnt]# mkdir sdb

  [root@novice mnt]# mount /dev/sdb1 /mnt/sdb

  [root@novice mnt]# cd /mnt/sdb

  [root@novice sdb]# echo "Hello! I am here" > test.txt

  [root@novice sdb]# cat test.txt

  Hello! I am here

  [root@novice sdb]# cd ..

  [root@novice mnt]# umount /dev/sdb1

  [root@novice mnt]# cd /mnt/sdb

  [root@novice sdb]# ls -l

  total 0

  以上就是linux下磁盤怎么分區(qū)的方法了,希望對大家有所幫助。

看過“ linux下磁盤怎么分區(qū) ”的人還看了:

1.Linux上磁盤掛載方法

2.linux虛擬機如何添加磁盤并使用磁盤

3.怎么在一個硬盤上安裝兩個Linux操作系統(tǒng)

4.Linux下使用xfs時提示沒有磁盤空間怎么辦

5.linux系統(tǒng)硬盤安裝教程

749264