The number of cylinders for this disk is set to 1958.
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):
进入了这个界面,就代表进入了fdisk的管理模式
在这个时候,可以按“m”来获得帮助
可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
First cylinder (1254-1958, default 1254):
Using default value 1254
Last cylinder or +size or +sizeM or +sizeK (1254-1958, default 1958): +500M
按“n”来添加,下面问从哪个柱面数开始,直接回车,选默认的。最后问这个分区分多大,我们分了500M
还可以做很多事情,还可以按“t”来改变分区的类型,
这个时候按“p”来查看刚刚的操作
Command (m for help): p
Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 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 535 4192965 83 Linux
/dev/sda3 536 1057 4192965 83 Linux
/dev/sda4 1058 1958 7237282+ 5 Extended
/dev/sda5 1058 1188 1052226 82 Linux swap / Solaris
/dev/sda6 1189 1253 522081 83 Linux
/dev/sda7 1254 1315 497983+ 83 Linux
Command (m for help):
可以看到已经分了一个/dev/sda7这个新的分区。
Command (m for help): wq
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.
[root@localhost ~]#
这个时候,已经保存并退出了,但是它给了一个警告:说设备忙,必须要下次重启才行。可以执行一条命令来更新分区(很重要的一条命令)
[root@localhost ~]# partprobe /dev/sda
[root@localhost ~]#
到目前为止,分区已经完成了,
但分区并不能够正常使用,所以还有格式化分区。
格式化分区
#mkfs.ext3 /dev/sda7
[root@localhost ~]# mkfs.ext3 /dev/sda7
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
124928 inodes, 497980 blocks
24899 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
61 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]#
系统在格式化的时候,当分区大小小于1024M的时候,默认格式化的时候block size为1024K,当分区大于1024M的时候,默认格式化的时候block size为4096K。
当然我们可以在格式化的时候指定block size的大小,
[root@localhost ~]# mkfs.ext3 -b 4096 /dev/sda7
还可以使用mount命令不加任何参数来查询系统中所有的设备
[root@localhost ~]# mount
/dev/sda3 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/sda6 on /home type ext3 (rw)
/dev/sda2 on /var type ext3 (rw)
/dev/sda1 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)
nfsd on /proc/fs/nfsd type nfsd (rw)
/dev/sda7 on /mnt type ext3 (rw)
[root@localhost ~]#
但是,mount命令只能够查询到系统中挂载的分区,没有挂载的分区查询不到
还可以用blkid来查询系统中所有的分区,没有挂载的分区也可以查到
[root@localhost ~]# blkid
/dev/sda6: LABEL="/home" UUID="7f75811c-8844-4d6d-a065-f4a1d75602dc" TYPE="ext3"
/dev/sda5: LABEL="SWAP-sda5" TYPE="swap"
/dev/sda3: LABEL="/" UUID="7c54f96f-7d2b-4da9-a4bf-3b474e0e460d" TYPE="ext3"
/dev/sda1: LABEL="/boot" UUID="6663d1de-50d9-4cdf-a4f5-085cab5fa789" TYPE="ext3"
/dev/sda2: LABEL="/var" UUID="b5306518-306a-4fcb-bdd5-dd4063bca9fe" TYPE="ext3"
/dev/hdc: LABEL="RHEL/5.4 i386 DVD" TYPE="iso9660"
/dev/sda7: LABEL="/disk" UUID="3d68e924-8974-420d-81a9-aec7b9e95079" TYPE="ext3"
[root@localhost ~]#
下面来学习一个tune2fs这个工具(很强大)
Tun2fs这个工具主要是用来查询文件系统的参数
可以使用tun2fs –l /dev/sda7来查询/dev/sda7这个分区的详细信息
#tune2fs -l /dev/sda7
[root@localhost ~]# tune2fs -l /dev/sda7
tune2fs 1.39 (29-May-2006)
Filesystem volume name: /disk
Last mounted on:
Filesystem UUID: 3d68e924-8974-420d-81a9-aec7b9e95079
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal resize_inode dir_index filetype needs_recovery sparse_super
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 124928
Block count: 497980
Reserved block count: 24899
Free blocks: 471670
Free inodes: 124917
First block: 1
Block size: 1024
Fragment size: 1024
Reserved GDT blocks: 256
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 2048
Inode blocks per group: 256
Filesystem created: Fri Feb 19 21:30:36 2010
Last mount time: Fri Feb 19 23:01:52 2010
Last write time: Fri Feb 19 23:01:52 2010
Mount count: 4
Maximum mount count: 36
Last checked: Fri Feb 19 21:30:36 2010
Check interval: 15552000 (6 months)
Next check after: Wed Aug 18 21:30:36 2010
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128
Journal inode: 8
Default directory hash: tea
Directory Hash Seed: d49cd094-7bac-466f-bce7-f36e70b277b0
Journal backup: inode blocks
[root@localhost ~]#
在这个里面,可以看到很多信息,可以看到工具的版本1.39版本,可以看到文件系统的卷标,最后一次挂载在哪里,文件系统的UUID是多少,还可以看到文件系统的状态,文件系统的类型,还有Inode count 和block count。
还有空余的inode 和空闲的block .还可以看到block size。还可以看到文件系统是什么时候创建的,最后一次挂载在哪里等等很多信息。
下面学习如何用tune2fs这个工具来将ext2文件系统来转成ext3的文件系统
这个过程是在线,是不会丢失数据的,但是不能够从ext3装成ext2.的文件系统这样会丢失数据的。
[root@localhost ~]# mount | grep /dev/sda7
/dev/sda7 on /mnt type ext2 (rw)
[root@localhost ~]#
可以看到,现在/dev/sda7是ext2的文件系统类型。
将/boot下面的数据复制到/mnt,方便等下实验
[root@localhost ~]# cp /boot/* /mnt/
cp: omitting directory `/boot/grub'
cp: omitting directory `/boot/lost+found'
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
config-2.6.18-164.el5 initrd-2.6.18-164.el5kdump.img System.map-2.6.18-164.el5
initrd-2.6.18-164.el5.img symvers-2.6.18-164.el5.gz vmlinuz-2.6.18-164.el5
[root@localhost mnt]#
我们已经添加了一些文件到/dev/sda7里面,现在就开始将ext2的文件系统转换成ext3的文件系统。
转换命令
#tune2fs -j /dev/sda7
[root@localhost ~]# tune2fs -j /dev/sda7
tune2fs 1.39 (29-May-2006)
Creating journal inode: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override
在使用blkid这个命令来查看一下转换是否成功,
[root@localhost ~]# blkid
/dev/sda6: LABEL="/home" UUID="7f75811c-8844-4d6d-a065-f4a1d75602dc" TYPE="ext3"
/dev/sda5: LABEL="SWAP-sda5" TYPE="swap"
/dev/sda3: LABEL="/" UUID="7c54f96f-7d2b-4da9-a4bf-3b474e0e460d" TYPE="ext3"
/dev/sda1: LABEL="/boot" UUID="6663d1de-50d9-4cdf-a4f5-085cab5fa789" TYPE="ext3"
/dev/sda2: LABEL="/var" UUID="b5306518-306a-4fcb-bdd5-dd4063bca9fe" TYPE="ext3"
/dev/hdc: LABEL="RHEL/5.4 i386 DVD" TYPE="iso9660"
/dev/sda7: UUID="2254c9c7-6d9f-41ea-9c40-ddef8ab15959" SEC_TYPE="ext2" TYPE="ext3"
[root@localhost ~]#
可以看到/dev/sda7原来是ext2,后来变成了ext3的文件系统
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
config-2.6.18-164.el5 initrd-2.6.18-164.el5kdump.img System.map-2.6.18-164.el5
initrd-2.6.18-164.el5.img symvers-2.6.18-164.el5.gz vmlinuz-2.6.18-164.el5
[root@localhost mnt]#
看到了,原先的数据都没有丢失,
其实ext2与ext3文件系统不同的是ext3只是多了一个日志功能。运用tune2fs工具为ext2文件系统增加了一个日志区,所以就变成了ext3的文件系统