Linux中fdisk对应的c函数,linux下fdisk命令实战案例之详解
一、fdisk命令中參數(shù)介紹:
1.查看硬盤使用情形#fdisk?-l?觀察硬盤之實(shí)體使用情形
2.fdisk /dev/sda,進(jìn)入硬盤分割模式1.?輸入?m?顯示所有命令列示。
2.?輸入?p?顯示硬盤分割情形。
3.?輸入?a?設(shè)定硬盤啟動(dòng)區(qū)。
4.?輸入?n?設(shè)定新的硬盤分割區(qū)。
4.1.?輸入?e?硬盤為[延伸]分割區(qū)(extend)。
4.2.?輸入?p?硬盤為[主要]分割區(qū)(primary)。
5.?輸入?t?改變硬盤分割區(qū)屬性。
6.?輸入?d?刪除硬盤分割區(qū)屬性。
7.?輸入?q?結(jié)束不存入硬盤分割區(qū)屬性。
8.?輸入?w?結(jié)束并寫入硬盤分割區(qū)屬性
二、實(shí)戰(zhàn)將/dev/sdd整個(gè)磁盤劃成一個(gè)分區(qū)[root@db01?~]#?fdisk/dev/sdd
Command(m?for?help):?p??????????###查看分區(qū)信息
Disk?/dev/sdd:?1073MB,?1073741824?bytes
255?heads,?63sectors/track,?130?cylinders
Units?=?cylinders?of16065?*?512?=?8225280?bytes
Sector?size(logical/physical):?512?bytes?/?512?bytes
I/O?size(minimum/optimal):?512?bytes?/?512?bytes
Disk?identifier:0x0814ae42
Device?Boot??????Start?????????End??????Blocks??Id??System
Command(m?for?help):?n????###創(chuàng)建分區(qū)
Command?action
e??extended
p??primary?partition?(1-4)
p?????????????????????????????????????????????????????????????????????????###創(chuàng)建主分區(qū)
Partition?number?(1-4):?1??###分區(qū)號(hào)為1
First?cylinder?(1-130,?default?1):??###柱面默認(rèn)為1
Using?default?value1
Last?cylinder,?+cylinders?or?+size{K,M,G}?(1-130,?default?130):???###柱面默認(rèn)為最大130?(即使用全部剩余空間)
Using?default?value130
Command(m?for?help):?w??????###按照以上分區(qū)信息寫入磁盤
The?partition?tablehas?been?altered!
三、實(shí)戰(zhàn)刪除整個(gè)分區(qū)Command(m?for?help):p????????????????????????###查看分區(qū)信息
Disk?/dev/sdd:?1073MB,?1073741824?bytes
255?heads,?63sectors/track,?130?cylinders
Units?=?cylinders?of16065?*?512?=?8225280?bytes
Sector?size(logical/physical):?512?bytes?/?512?bytes
I/O?size(minimum/optimal):?512?bytes?/?512?bytes
Disk?identifier:0x0814ae42
Device?Boot??????Start?????????End??????Blocks??Id??System
/dev/sdd1???????????????1?????????130????1044193+??83??Linux
Command(m?for?help):?d???###刪除分區(qū)
Selectedpartition1????????????????????????###只有一個(gè)分區(qū)時(shí),默認(rèn)刪除
Command(m?for?help):?w??###按照以上分區(qū)信息寫入磁盤
The?partition?tablehas?been?altered!
Calling?ioctl()?tore-read?partition?table.
Syncing?disks.
四、實(shí)戰(zhàn)創(chuàng)建兩個(gè)分區(qū),分區(qū)一200M,分區(qū)二800M[root@db01?~]#?fdisk/dev/sdd
WARNING:DOS-compatible?mode?is?deprecated.?It's?strongly?recommended?to
switch?off?the?mode?(command?'c')?andchange?display?units?to
sectors?(command?'u').
Command(m?for?help):?n???###創(chuàng)建分區(qū)
Command?action
e??extended
p??primary?partition?(1-4)
p????????????????????????????????????????????????????????????????????????????????###創(chuàng)建主分區(qū)
Partition?number?(1-4):?1??###分區(qū)號(hào)為1
First?cylinder?(1-130,?default?1):???###柱面默認(rèn)為1
Using?default?value1
Last?cylinder,?+cylinders?or?+size{K,M,G}?(1-130,?default?130):+200M????###該分區(qū)分配200M空間
Command(m?for?help):?n???###創(chuàng)建分區(qū)
Command?action
e??extended
p??primary?partition?(1-4)
p????????????????????????????????????????????????????????????????????????????????###創(chuàng)建主分區(qū)
Partition?number?(1-4):?2??###分區(qū)號(hào)為2
First?cylinder?(27-130,?default?27):?###柱面默認(rèn)為27
Using?default?value27
Last?cylinder,?+cylinders?or?+size{K,M,G}?(27-130,?default130):???###柱面默認(rèn)為最大130(即使用全部剩余空間)
Using?default?value130
Command?(m?forhelp):?p
Disk?/dev/sdd:?1073MB,?1073741824?bytes
255?heads,?63sectors/track,?130?cylinders
Units?=?cylinders?of16065?*?512?=?8225280?bytes
Sector?size(logical/physical):?512?bytes?/?512?bytes
I/O?size(minimum/optimal):?512?bytes?/?512?bytes
Disk?identifier:0x0814ae42
Device?Boot??????Start?????????End??????Blocks??Id??System
/dev/sdd1???????????????1??????????26??????208813+?83??Linux
/dev/sdd2??????????????27?????????130??????835380??83??Linux
Command(m?for?help):?w?????###按照以上分區(qū)信息寫入磁盤
The?partition?tablehas?been?altered!
五、實(shí)戰(zhàn)創(chuàng)建主分區(qū)、擴(kuò)展分區(qū)、邏輯分區(qū)案例[root@db01?~]#?fdisk/dev/sdd
WARNING:DOS-compatible?mode?is?deprecated.?It's?strongly?recommended?to
switch?off?the?mode?(command?'c')?andchange?display?units?to
sectors?(command?'u').
Command(m?for?help):?n???###創(chuàng)建分區(qū)
Command?action
e??extended
p??primary?partition?(1-4)
p????????????????????????????????????????????????????????????????????????????###創(chuàng)建主分區(qū)
Partition?number?(1-4):?1??###分區(qū)號(hào)為1
First?cylinder?(1-130,?default?1):?###柱面默認(rèn)為1
Using?default?value1
Last?cylinder,?+cylinders?or?+size{K,M,G}?(1-130,?default?130):+200M??###該分區(qū)分配200M空間
Command(m?for?help):?n???###創(chuàng)建分區(qū)
Command?action
e??extended
p??primary?partition?(1-4)
e????????????????????????????????????????????????????????????????????????????????###創(chuàng)建擴(kuò)展分區(qū)
Partition?number?(1-4):?2??###分區(qū)號(hào)為2
First?cylinder?(27-130,?default?27):???###柱面默認(rèn)為27
Using?default?value27
Last?cylinder,?+cylinders?or?+size{K,M,G}?(27-130,?default130):????###柱面默認(rèn)為最大130?(即使用全部剩余空間)擴(kuò)展分區(qū)必須是剩余全部空間
Using?default?value130
Command(m?for?help):?n??###創(chuàng)建分區(qū)
Command?action
l??logical?(5?or?over)
p??primary?partition?(1-4)
l????????????????????????????????????????????????????????????????????????????????###創(chuàng)建邏輯分區(qū)
First?cylinder?(27-130,?default?27):?###柱面默認(rèn)為27
Using?default?value27
Last?cylinder,?+cylinders?or?+size{K,M,G}?(27-130,?default?130):+200M??###該分區(qū)分配200M空間
Command(m?for?help):?n??###創(chuàng)建分區(qū)
Command?action
l??logical?(5?or?over)
p??primary?partition?(1-4)
l????????????????????????????????????????????????????????????????????????????????###創(chuàng)建邏輯分區(qū)
First?cylinder?(53-130,?default?53):?###柱面默認(rèn)為53
Using?default?value53
Last?cylinder,?+cylinders?or?+size{K,M,G}?(53-130,?default?130):+200M?###該分區(qū)分配200M空間
Command(m?for?help):?n???###創(chuàng)建分區(qū)
Command?action
l??logical?(5?or?over)
p??primary?partition?(1-4)
l????????????????????????????????????????????????????????????????????????????????###創(chuàng)建邏輯分區(qū)
First?cylinder?(79-130,?default?79):?###柱面默認(rèn)為79
Using?default?value79
Last?cylinder,?+cylinders?or?+size{K,M,G}?(79-130,?default130):??###柱面默認(rèn)為最大130(即使用全部剩余空間)
Using?default?value130
Command?(m?forhelp):?p
Disk?/dev/sdd:?1073MB,?1073741824?bytes
255?heads,?63sectors/track,?130?cylinders
Units?=?cylinders?of16065?*?512?=?8225280?bytes
Sector?size(logical/physical):?512?bytes?/?512?bytes
I/O?size(minimum/optimal):?512?bytes?/?512?bytes
Disk?identifier:0x0814ae42
Device?Boot??????Start?????????End??????Blocks??Id??System
/dev/sdd1???????????????1??????????26??????208813+?83??Linux
/dev/sdd2??????????????27?????????130??????835380???5??Extended
/dev/sdd5??????????????27??????????52??????208813+?83??Linux
/dev/sdd6??????????????53??????????78??????208813+?83??Linux
/dev/sdd7??????????????79?????????130??????417658+?83??Linux
Command(m?for?help):w???###按照以上分區(qū)信息寫入磁盤
六、使用單個(gè)分區(qū)的方式進(jìn)行格式化分區(qū)
1.查看分區(qū)詳情,確認(rèn)改變分區(qū)表,以免重啟電腦了。[root@db01?~]#?fdisk-l?/dev/sdd??#查看分區(qū)詳情
Disk?/dev/sdd:?1073MB,?1073741824?bytes
255?heads,?63sectors/track,?130?cylinders
Units?=?cylinders?of16065?*?512?=?8225280?bytes
Sector?size(logical/physical):?512?bytes?/?512?bytes
I/O?size(minimum/optimal):?512?bytes?/?512?bytes
Disk?identifier:0x0814ae42
Device?Boot??????Start?????????End??????Blocks??Id??System
/dev/sdd1???????????????1?????????130????1044193+??83??Linux
[root@db01~]#?partprobe?/dev/sdd????#確認(rèn)分區(qū)表的改變將分區(qū)信息寫入磁盤
[root@db01?~]#?ls-lsa?/dev/sdd*
0?brw-rw----.?1?rootdisk?8,?48?Nov?21?11:02?/dev/sdd
0?brw-rw----.?1?rootdisk?8,?49?Nov?21?11:02?/dev/sdd1
2.格式化分區(qū)
2.1 mkfs -t ext4 /dev/sdd1??? (這種方法不方便,不推薦使用)
2.2 mkfs.ext4 /dev/sdd1???? (推薦這種)[root@db01?~]#mkfs.ext4?/dev/sdd1
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
65280?inodes,?261048blocks
13052?blocks?(5.00%)reserved?for?the?super?user
First?data?block=0
Maximum?filesystemblocks=268435456
8?block?groups
32768?blocks?pergroup,?32768?fragments?per?group
8160?inodes?pergroup
Superblock?backupsstored?on?blocks:
32768,?98304,?163840,?229376
Writing?inodetables:?done
Creating?journal(4096?blocks):?done
Writing?superblocksand?filesystem?accounting?information:?done
This?filesystem?willbe?automatically?checked?every?34?mounts?or
180?days,?whichevercomes?first.??Use?tune2fs?-c?or?-i?tooverride.
七、掛載分區(qū)[root@db01?~]#?mkdir/alexpeng
[root@db01?~]#?mount/dev/sdd1?/alexpeng
[root@db01?~]#?df?-h
Filesystem??????Size?Used?Avail?Use%?Mounted?on
/dev/sda3????????45G?4.4G???39G??11%?/
tmpfs??????????1004M?????0?1004M??0%?/dev/shm
/dev/sda1???????485M??39M??421M???9%?/boot
/dev/sdb2????????79G?184M???75G???1%?/oracle
/dev/sdb1????????20G?172M???19G???1%?/soft
/dev/sdd1??????1004M??18M??936M???2%?/alexpeng
八、配置開啟自動(dòng)掛載分區(qū)[root@db01?/]#?vi/etc/fstab
UUID=3e8b0960-23d2-48f3-8661-3f24ce85e9e6/???????????????????????ext4????defaults????????1?1
tmpfs???????????????????/dev/shm????????????????tmpfs???defaults????????0?0
devpts??????????????????/dev/pts????????????????devpts??gid=5,mode=620??0?0
sysfs???????????????????/sys????????????????????sysfs???defaults????????0?0
proc????????????????????/proc???????????????????proc????defaults????????0?0
/dev/sdd1???????????????/alexpeng???????????????ext4????defaults????????0?0
測(cè)試配置是否正確
[root@db01?/]#umount?/alexpeng/
[root@db01?/]#?mount/alexpeng/
如果不正確出現(xiàn)以下信息:
[root@db01?/]#?mount/alexpeng/
mount:?can't?find/alexpeng/?in?/etc/fstab?or?/etc/mtab
總結(jié)
以上是生活随笔為你收集整理的Linux中fdisk对应的c函数,linux下fdisk命令实战案例之详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 镜头视场角计算工具_再谈远心镜头的设计及
- 下一篇: android接口类命名规范_超全面的U