首页 > 代码库 > linux-磁盘分区
linux-磁盘分区
实验目标
为虚拟机添加一块80GB、SCSI接口的硬盘
划分2个20GB的主分区,剩余作为扩展分区
新建2个逻辑分区,分别为2GB、10GB
将第1个逻辑分区的类型改为SWAP(ID82)
将第2个逻辑分区的类型改为VFAT(ID b)
确认分区无误后,保存退出
使用partprobe识别新的分区表 【最好是重启一次】
实验步骤
1)为虚拟机添加一块80GB、SCSI接口的硬盘
[root@localhost~]# fdisk -l //列表查看磁盘分区-默认如果没有给出设备,那么使用那些在/proc/partitions (如果存在)提到的,重启后新的磁盘会被读入该文件//
Disk/dev/sda: 85.8 GB, 85899345920 bytes
255heads, 63 sectors/track, 10443 cylinders
Units =cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2563 20482875 83 Linux
/dev/sda3 2564 2824 2096482+ 82 Linux swap / Solaris
Disk/dev/sdb: 85.8 GB, 85899345920 bytes
255heads, 63 sectors/track, 10443 cylinders
Units =cylinders of 16065 * 512 = 8225280 bytes
Disk/dev/sdb doesn‘t contain a valid partition table //系统提示该磁盘不包含有效分区表,需要进行分区//
[root@localhost~]# cat/proc/partitions //来查看一下这个分区信息文件,sdb设备文件在里面//
majorminor #blocks name
8 0 83886080 sda
8 1 104391 sda1
8 2 20482875 sda2
8 3 2096482 sda3
8 16 83886080 sdb
2)划分2个20GB的主分区,剩余作为扩展分区(分区操作)
[root@localhost~]# fdisk /dev/sdb //fdisk直接接设备文件,开始规划分区,进入交互式操作//
Devicecontains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Buildinga new DOS disklabel. Changes will remain in memory only,
untilyou decide to write them. After that, of course, the previous
contentwon‘t be recoverable.
Thenumber of cylinders for this disk is set to 10443.(这块磁盘有10443个柱面)
Thereis nothing wrong with that, but this is larger than 1024,
andcould in certain setups cause problems with:
1)software that runs at boot time (e.g., old versions of LILO)
2)booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning:invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command(m for help): m
Commandaction
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition ----删除一个分区
l list known partition types
m print this menu ----列出帮助命令
n add a new partition ----创建一个新分区
o create a new empty DOS partition table
p print the partition table ----显示分区表
q quit without savingchanges ----不保存修改直接退出(整个交互过程是模拟,还没有生效,允许撤销)
s create a new empty Sun disklabel
t change a partition‘ssystem id ----修改分区系统ID(不同的文件系统)
u change display/entry units
v verify the partition table
w write table to disk andexit ----保存并退出(一定要想好哦^_^)
x extra functionality (experts only)
Command(m for help): n //开始创建新分区//
Commandaction
e extended ----创建扩展分区
p primary partition (1-4) ----创建主分区
P
Partitionnumber (1-4): 1 ----分区编号(可以划分4个主分区,按正常顺序往下延)
Firstcylinder (1-10443, default 1): ----第一个柱面,默认从第一个开始,直接回车,往下顺延
Usingdefault value 1
Lastcylinder or +size or +sizeM or +sizeK (1-10443, default 10443): +20G ----选择最后一个柱面,或者直接指定该分区大小,这里输入+20G回车
Command(m for help): n ----以下过程类似,不再赘述
Commandaction
e extended
p primary partition (1-4)
p
Partitionnumber (1-4): 2
First cylinder(2434-10443, default 2434):
Usingdefault value 2434
Lastcylinder or +size or +sizeM or +sizeK (2434-10443, default 10443): +20G
Command(m for help): n ----接下来创建扩展分区,除了上述的两个主分区,剩余的空间全部归它所有
Commandaction
e extended
p primary partition (1-4)
e
Partitionnumber (1-4): 3
Firstcylinder (4867-10443, default 4867):
Usingdefault value 4867
Lastcylinder or +size or +sizeM or +sizeK (4867-10443, default 10443):
Usingdefault value 10443
3)新建2个逻辑分区,分别为2GB、10GB
Command(m for help): n
Commandaction
l logical (5 or over)
p primary partition (1-4)
l
Firstcylinder (4867-10443, default 4867):
Usingdefault value 4867
Lastcylinder or +size or +sizeM or +sizeK (4867-10443, default 10443): +2G
Command(m for help): n
Commandaction
l logical (5 or over)
p primary partition (1-4)
l
Firstcylinder (5111-10443, default 5111):
Usingdefault value 5111
Lastcylinder or +size or +sizeM or +sizeK (5111-10443, default 10443): +10G
4)将第1个逻辑分区的类型改为SWAP(ID 82)
Command(m for help): t
Partitionnumber (1-6): 5
Hexcode (type L to list codes): l
0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris
1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec(FAT-
2 XENIXroot 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT-
3 XENIXusr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT-
4 FAT16<32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx
5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data
6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS /.
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de DellUtility
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt
9 AIXbootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access
a OS/2Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
c W95FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs
e W95FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
f W95Ext‘d (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys ab Darwinboot fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
Hexcode (type L to list codes): 82
Changedsystem type of partition 5 to 82 (Linux swap / Solaris)
5)将第2个逻辑分区的类型改为VFAT(ID b)
Command(m for help): t
Partitionnumber (1-6): 6
Hexcode (type L to list codes): b
Changedsystem type of partition 6 to b (W95 FAT32)
6)确认分区无误后,保存退出
Command(m for help): w
Thepartition table has been altered! ----该分区表已经被更改!
Callingioctl() to re-read partition table.
WARNING:If you have created or modified any DOS 6.x
partitions,please see the fdisk manual page for additional
information.
Syncingdisks.
7)使用partprobe识别新的分区表 【最好是重启一次】
创建分区后,这些分区表还没有生效,最好通过重启读取这些分区表,系统才能使用,也可以使用以下命令:
Partprobe /dev/sdb //强制刷新分区表// --RHEL5系列
[root@localhost~]# partprobe/dev/sdb //强制刷新分区表,使系统能够识别//
结果验证
[root@localhost~]# fdisk -l
Disk /dev/sda:85.8 GB, 85899345920 bytes
255heads, 63 sectors/track, 10443 cylinders
Units =cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2563 20482875 83 Linux
/dev/sda3 2564 2824 2096482+ 82 Linux swap / Solaris
Disk/dev/sdb: 85.8 GB,85899345920 bytes
255heads, 63 sectors/track, 10443 cylinders
Units =cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2433 19543041 83 Linux
/dev/sdb2 2434 4866 19543072+ 83 Linux
/dev/sdb3 4867 10443 44797252+ 5 Extended
/dev/sdb5 4867 5110 1959898+ 82 Linux swap/ Solaris
/dev/sdb6 5111 6327 9775521 b W95 FAT32
本文出自 “点点滴滴” 博客,请务必保留此出处http://9118437.blog.51cto.com/9108437/1533983