您的位置:首页 > 运维架构 > Linux

LINUX磁盘管理

2013-06-04 23:03 274 查看
1.显示系统磁盘分区情况:

[root@vm1 mnt]# fdisk -l

Disk /dev/sda: 274.8 GB, 274877906944 bytes
255 heads, 63 sectors/track, 33418 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 13054 104751832+ 8e Linux LVM
/dev/sda3 13055 32635 157284382+ 5 Extended
/dev/sda5 13055 32635 157284351 83 Linux

2.显示系统文件使用情况

[root@vm1 mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup01-LogVol00
86G 78G 3.6G 96% /
/dev/sda1 99M 16M 79M 17% /boot
tmpfs 4.9G 0 4.9G 0% /dev/shm
/dev/sda5 148G 188M 140G 1% /mnt/fifth

3.使用fdisk分区命令

[root@vm1 mnt]# fdisk /dev/sda

The number of cylinders for this disk is set to 33418.
There is nothing wrong with that, but this is larger than 1024,
and could 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)

Command (m for help): m -------------为查看所有命令
Command action
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 saving changes--------------------不保存退出
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit----------------------将刚才的操作写入分区表
x extra functionality (experts only)

Command (m for help):--------------------------输入以上操作,回车执行

4.执行分区操作

[root@vm1 mnt]# fdisk /dev/sda

Command (m for help):n-----------------------------新建分区

Command action
l logical (5 or over)
p primary partition (1-5)

l---------------------------------------输入l,增加一个逻辑分区

Partition number (1-5):-------------------------------------------------------输入5,则设置新分区的名字为sda5,请选择不存在分区名

First cylinder (51-125, default 51): -------------------------------------注:这个就是分区的Start 值;这里最好直接按回车

Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:这个是定义分区大小的,+200M 就是大小为200M ;当然您也可以根据p 提示的单位cylinder的大小来算,然后来指定 End 的数值。回头看看是怎么算的;还是用+200M 这个办法来添加,这样能直观一点。如果您想添加一个10G 左右大小的分区,请输入 +10000M ;如果想分所有分区,则回车

Command (m for help):w--------------------------------------------------上面结束后,输入w,将刚才的操作写入注册表,如果直接输入q,则对以上的操作不生效

Command (m for help):q--------------------------------------------------退出fdisk命令

5.执行格式化操作

重启系统后,执行

[root@vm1 mnt]#mkfs.ext3 /dev/sda5------------------------------对以上的分区进行格式化

6.使刚才的分区开机挂载

[root@vm1 mnt]# vi /etc/fstab-----------------------------------------此文件可在开机时执行,以进行开机挂载操作

/dev/VolGroup01/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
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/VolGroup01/LogVol01 swap swap defaults 0 0
/dev/sda5 /mnt/fifth ext3 defaults 1 2---------------------------------------------此行为后增加,说明开机时将/dev/sda5 挂载到/mnt/fifth,文件格式为ext3

当提示No free sectors available时,说明无空间可分,这时可以考虑对Extended分区进行重新分区

执行以下命令

[root@vm1 mnt]# fdisk -l

Disk /dev/sda: 274.8 GB, 274877906944 bytes
255 heads, 63 sectors/track, 33418 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 13054 104751832+ 8e Linux LVM
/dev/sda3 13055 32635 157284382+ 5 Extended
/dev/sda5 13055 32635 157284351 83 Linux

说明:

33418 cylinders:磁盘共有这么多柱面

/dev/sda3 13055 32635:32635为扩展分区的结束柱面号

/dev/sda5 13055 32635:sda5的13055 32635与sda3一致,说明此扩展分区的空间全部分给了此逻辑分区,当sda5的End值小于sda3的End值时,说明sda3还有分区没被划分,可以对磁盘分区进行扩展操作。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: