分区管理
fsisk -l 查看当前分区状况[root@localhost ~]# fdisk -l
Disk /dev/hda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 1318 10482412 83 Linux
/dev/hda3 1319 1579 2096482 83 Linux
/dev/hda4 1580 5221 29254365 5 Extended
/dev/hda5 1580 1840 2096451 83 Linux
/dev/hda6 1841 1971 1052226 82 Linux swap / Solaris
显示的各列表示 :第一列 各分区设备名;第二列boot表示启动分区,* 表示此分区是启动分区;第三列第四列表示起始柱面和终止柱面,第五列表在整个分区中包含的总块数,第六列表示文件系统id号
使用fdisk工具,直接输入fsisk 和要操作的硬盘设备[root@localhost ~]# fdisk /dev/hda
The number of cylinders for this disk is set to 5221.
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): n
#输入起始柱面,默认1972First cylinder (1972-5221, default 1972):
Using default value 1972
#输入结束柱面,或者输入磁盘容量 数值 单位Last cylinder or size or sizeM or sizeK (1972-5221, default 5221): 1024M
#显示当前分区状况,默认分区id号都为82,文件系统为ext3Command (m for help): p
Disk /dev/hda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 1318 10482412 83 Linux
/dev/hda3 1319 1579 2096482 83 Linux
/dev/hda4 1580 5221 29254365 5 Extended
/dev/hda5 1580 1840 2096451 83 Linux
/dev/hda6 1841 1971 1052226 82 Linux swap / Solaris
/dev/hda7 1972 2096 1004031 83 Linux
#查看系统支持的文件系统id号Command (m for help): l
... 略
# t修改分区id号,8e表示Linux LVM,是linux系统中作逻辑卷管理的文件系统Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): 8e
Changed system type of partition 7 to 8e (Linux LVM)
# 执行前面的操作并保存结果,如果想恢复为原来设置,则按q退出即可~Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
建立分区之后,新分区还不可以使用,必须先建立正确的文件格式。输入mkfs后按tab键,可以看到创建系统文件的命令
[root@localhost ~]# mkfs
mkfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.msdos mkfs.vfat
#为新分区建立正确的文件格式,参数-b可设置系统存储块的大小, 参数-i可设置每个索引点的大小,
# -c检查分区中的坏块,-L 设置分区的标签(也可用e2label 分区 标签)[root@localhost ~]# mkfs.ext3 /dev/hda7
# 等同于mke2fs -T ext3 /dev/hda7mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
125696 inodes, 251007 blocks
12550 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=260046848
8 block groups
32768 blocks per group, 32768 fragments per group
15712 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
#系统会在一定时间内对文件系统几行检查,如果是重视系统运行速度,而不是稳定性的话,可以使用tune2fs关闭
#这种周期性操作,如
# [root@localhost ~]# tune2fs -i 0 /dev/hda7
# tune2fs 1.39 (29-May-2006)
# Setting interval between checks to 0 seconds
# -i设置系统检查的周期,0 表示不检查文件系统
# -c 设置系统检查的最大月数This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
#查看分区的文件系统格式[root@localhost ~]# file -s /dev/hda7
/dev/hda7: Linux rev 1.0 ext2 filesystem data (large files)
# -j参数设置转化文件格式为ext3[root@localhost ~]# tune2fs -j /dev/hda7
tune2fs 1.39 (29-May-2006)
Creating journal inode: done
This filesystem will be automatically checked every 22 mounts or
0 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# file -s /dev/hda7
/dev/hda7: Linux rev 1.0 ext3 filesystem data (large files)
# -O参数设置转化文件格式为ext2[root@localhost ~]# tune2fs -O ^has_journal /dev/hda7
tune2fs 1.39 (29-May-2006)
[root@localhost ~]# file -s /dev/hda7
/dev/hda7: Linux rev 1.0 ext2 filesystem data (large files)
挂载设备# mount查看当前挂载情况,以空格为分界符,第一列表示设备名称;第二列 on 表示挂载到;
# 第三列表挂载到的文件目录;第四列type表文件类型;第五列表文件类型名;
# 第六列表文件挂载到系统中使用的参数,rw表示用户可对分区进行读写操作,
# gid设置在该分区中建立文件时,文件默认所属的用户组,数字为id号,
# mode表建立文件或目录时的初始权限,ro表只读,
# noexec表禁止在该分区或挂载的目录执行二进制文件,
# nosuid表禁止在该分区或挂载的目录中有设置suid位的文件存在[root@localhost ~]# mount
/dev/hda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda5 on /home type ext3 (rw)
/dev/hda3 on /tmp type ext3 (rw)
/dev/hda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
# mount -o参数可设置指定上述的rw,noexec ..参数,
# 若挂载完后进入目录,显示乱码,指定 -o iocharset=cp936 设置挂载设备的字符
# 若挂载的为iso光盘文件,须指定-o loop
[root@localhost ~]# ls
YlmF_XPSP3_YS8.0F.iso
[root@localhost ~]# mount ~/YlmF_XPSP3_YS8.0F.iso /tmp
mount: /root/YlmF_XPSP3_YS8.0F.iso is not a block device (maybe try `-o loop'?)
[root@localhost ~]# mount -o loop ~/YlmF_XPSP3_YS8.0F.iso /tmp
[root@localhost ~]# cd /tmp
[root@localhost tmp]# ls
autorun.exe Driver I386 OneKey.exe Setup.exe Tools WIN51IP WINNT.BAT WXPE
Autorun.inf DriverBackUp.exe $OEM$ Readme.txt soft WIN51 WIN51IP.SP3 WINNT.XPE 常见问题.mht
# -t表挂载到分区的文件格式
# -L表用分区的标签来挂载[root@localhost ~]# mount -o noexec /dev/hda7 /tmp
[root@localhost ~]# mount
.....
/dev/hda7 on /tmp type ext2 (rw,noexec)
若要让设备在系统启动时就自动挂载,则要修改文件/etc/fstab
如果修改/etc/fstab错误导致无法进入系统,进入修复模式,提示 /etc/fstab 只读,无法修改,
输入 # mount -o remount,rw / 修改文件权限,即可修改[root@localhost ~]# vi /etc/fstab
/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/hda7 /tmp ext3 defaults 0 0
重新规划已有分区可用系统自带工具parted,parted可像fdisk一样新建分区,也可修改已有分区容量# -s 表示不交互操作,后跟设备名,然后加命令
# 删除分区号为7的分区
[root@localhost /]# parted -s /dev/hda rm 7
[root@localhost /]# parted -s /dev/hda print
[root@localhost /]# parted -s /dev/hda mkpart logic 16.2G 18.2G
一个问题未解决,为什么在Red Hat中使用parted 或 resize2fs 对磁盘重新划分大小,老是出现错误~~
Error: File system has an incompatible feature enabled.
参考网址:
http://gchuyun.iteye.com/blog/252672http://jarson.blog.51cto.com/1422982/290393http://helloxy.iteye.com/blog/123443