实验八 文件系统和磁盘管理

更新时间:2024-04-07 15:31:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

实验八 文件系统和磁盘管理

实验八 文件系统和磁盘管理

(一)磁盘分区管理

【需求】

? ? ? ?

为一个有空闲空间的磁盘新建一个分区; 对该分区进行格式化;

把该分区挂载到/mnt/music目录; 要求每次机器启动都自动挂载。

【系统及软件环境】

操作系统:Red Hat AS 4.0

【实验配置文件及命令】

1.配置文件:/etc/fstab

2.命令:/sbin/fdisk,/sbin/mkfs.ext3,/bin/mkdir,/bin/mount

【实验步骤】

1. 系统当前的分区表信息。 [root@linux /]# fdisk -l Disk /dev/hda: 80.0 GB, 80060424192 bytes 255 heads, 63 sectors/track, 9733 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 1288 10241437+ 83 Linux /dev/hda3 1289 1415 1020127+ 82 Linux swap /dev/hda4 1416 9733 66814335 5 Extended /dev/hda5 1416 1496 650601 8e Linux LVM /dev/hda6 1497 1517 168651 fd Linux raid autodetect /dev/hda7 1518 1538 168651 fd Linux raid autodetect /dev/hda8 1539 1557 152586 83 Linux /dev/hda9 1558 2321 6136798+ 83 Linux /dev/hda10 2322 2386 522081 82 Linux swap

63

Linux系统管理员实训手册

由上面的信息可知,系统的扩展分区/dev/hda4中还有空闲的空间(因为该磁盘共有9733个柱面,/dev/hda4的结束柱面为9733,而该扩展分区中的最后一个逻辑分区/dev/hda10的结束柱面为2386,所以柱面2387~9733都是空闲的),于是可以新建一个100M的分区。

2.用fdisk新建一个分区。 [root@linux /]# fdisk /dev/hda The number of cylinders for this disk is set to 9733. 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): n First cylinder (2387-9733, default 2387): 2387 Using default value 2387 Last cylinder or +size or +sizeM or +sizeK (2387-9733, default 9733): +100M 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. [root@linux /]# reboot 最后的警告,要求系统重启,新的分区表才会生效。

3.再查看系统的分区表,可以看到多了1个分区/dev/hda11。 [root@linux /]# fdisk -l Disk /dev/hda: 80.0 GB, 80060424192 bytes 255 heads, 63 sectors/track, 9733 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes

64

实验八 文件系统和磁盘管理

Device Boot Start End Blocks Id System /dev/hda1 * 1 13 104391 83 Linux /dev/hda2 14 1288 10241437+ 83 Linux /dev/hda3 1289 1415 1020127+ 82 Linux swap /dev/hda4 1416 9733 66814335 5 Extended /dev/hda5 1416 1496 650601 8e Linux LVM /dev/hda6 1497 1517 168651 fd Linux raid autodetect /dev/hda7 1518 1538 168651 fd Linux raid autodetect /dev/hda8 1539 1557 152586 83 Linux /dev/hda9 1558 2321 6136798+ 83 Linux /dev/hda10 2322 2386 522081 82 Linux swap /dev/hda11 2387 2399 104391 83 Linux 4.格式化该分区。 [root@linux /]# mkfs.ext3 /dev/hda11

5.把该分区挂载到/mnt/music目录。 [root@linux /]# mkdir /mnt/music [root@linux /]# mount /dev/hda11 /mnt/music

6.在/etc/fstab最后添加一项,使其每次开机都自动挂载。 [root@linux /]# vi /etc/fstab # This file is edited by fstab-sync - see 'man fstab-sync' for details LABEL=/ / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 none /dev/pts devpts gid=5,mode=620 0 0 none /dev/shm tmpfs defaults 0 0 none /proc proc defaults 0 0 none /sys sysfs defaults 0 0 /dev/hda3 swap swap defaults 0 0 LABEL=SWAP-hda10 swap swap defaults 0 0 /dev/hda11 /mnt/music ext3 defaults 0 0 【实验故障与分析】

下面的表格中列出了在实验过程中可能会出现的故障及其解决方法。看看是不是对你的实验有所帮助?如果你在实验中还遇到了其他的问题或故障,不妨记录在表格中,通过自己的实践,或者与老师、同学一起找找解决问题的方法。

65

Linux系统管理员实训手册

序 号 1 2 3 实验故障 无法创建hda11 分析与解决 逻辑分区的编号是从5开始,自动递加 【启发联想】

1.系统中哪些分区的大小不能修改,哪些分区的大小可以修改? 2.如果硬盘没有空闲空间,而又需要多建一个分区,怎么处理?

(二)U盘管理

【需求】

? 挂载一个文件系统为FAT32类型的U盘。

【系统及软件环境】

操作系统:Red Hat AS 4.0

【实验配置文件及命令】

1.配置文件:无

2.命令:/sbin/fdisk,/bin/mkdir,/bin/mount,/bin/umount

【实验步骤】

1.插入U盘后,就可查看该U盘的设备名及分区表信息。 [root@linux /]# fdisk -l Disk /dev/hda: 80.0 GB, 80060424192 bytes 255 heads, 63 sectors/track, 9733 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 1288 10241437+ 83 Linux /dev/hda3 1289 1415 1020127+ 82 Linux swap /dev/hda4 1416 9733 66814335 5 Extended /dev/hda5 1416 1496 650601 8e Linux LVM /dev/hda6 1497 1517 168651 fd Linux raid autodetect /dev/hda7 1518 1538 168651 fd Linux raid autodetect

66

实验八 文件系统和磁盘管理

/dev/hda8 1539 1557 152586 83 Linux /dev/hda9 1558 2321 6136798+ 83 Linux /dev/hda10 2322 2386 522081 82 Linux swap /dev/hda11 2387 2399 104391 83 Linux Disk /dev/sda: 264 MB, 264110080 bytes 16 heads, 32 sectors/track, 1007 cylinders Units = cylinders of 512 * 512 = 262144 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 1008 257904 b W95 FAT32 Partition 1 has different physical/logical endings: phys=(1023, 15, 32) logical=(1007, 7, 32) 上面的/dev/sda即是刚插入的U盘,它只有一个分区/dev/sda1,类型为FAT32。在Red Hat AS 4.0中,只要插入U盘,系统就会把它自动挂载到/media目录下,但是存在一个问题就是,如果U盘里的文件名为中文的话,就不能正常显示;如果想让它能够正常显示中文文件名,就需要手动挂载。

2.先卸载,然后手动挂载。 [root@linux /]# umount /dev/sda1 [root@linux /]# mkdir /media/u-disk [root@linux /]# mount -o iocharset=gb2312 /dev/sda1 /media/u-disk [root@linux /]# ls /media/u-disk/ 硕士学位论文0525.doc 答辩建议.txt exe20040607.doc 计算机系2004级毕业答辩通知版.xls 挂载时,设置了iocharset选项后即可正常显示中文文件名。

【实验故障与分析】

下面的表格中列出了在实验过程中可能会出现的故障及其解决方法。看看是不是对你的实验有所帮助?如果你在实验中还遇到了其他的问题或故障,不妨记录在表格中,通过自己的实践,或者与老师、同学一起找找解决问题的方法。

序号 1 2 3 实验故障 无法挂载sdal 分析与解决 这可能是因为系统中已经有一个或多个SCSI设备,这个情况下U盘的名称不再是sda

67

Linux系统管理员实训手册

【启发联想】

1.U盘的名称是如何约定的?

2.如果系统中插入了多个U盘,如何处理?

(三)autofs服务

【需求】

? 利用autofs自动挂载一个nfs文件系统; ? 假设局域网中有一台nfs服务器,其IP为192.168.1.1,共享目录为/tmp;本机 的

IP为192.168.1.2,要求把nfs服务器的/tmp目录挂载到本机的/mnt/nfs目录上。

【系统及软件环境】

1.操作系统:Red Hat AS 4.0 2.软件:autofs-4.1.3-169

【实验配置文件及命令】

1.配置文件: /etc/auto.master,/etc/auto.misc 2.命令:/usr/bin/vim,/sbin/service

【实验步骤】

1.编辑/etc/auto.master,在末尾添加一行。 [root@linux tmp]# vi /etc/auto.master # $Id: auto.master,v 1.3 2003/09/29 08:22:35 raven Exp $ # # Sample auto.master file # This is an automounter map and it has the following format # key [ -mount-options-separated-by-comma ] location # For details of the format look at autofs(5). #/misc /etc/auto.misc --timeout=60 #/misc /etc/auto.misc #/net /etc/auto.net /mnt /etc/auto.misc --timeout=30 2.编辑/etc/auto.misc,在末尾添加一行。 [root@linux tmp]# vi /etc/auto.misc # $Id: auto.misc,v 1.2 2003/09/29 08:22:35 raven Exp $ #

68

实验八 文件系统和磁盘管理

# This is an automounter map and it has the following format # key [ -mount-options-separated-by-comma ] location # Details may be found in the autofs(5) manpage cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom # the following entries are samples to pique your imagination #linux -ro,soft,intr ftp.example.org:/pub/linux #boot -fstype=ext2 :/dev/hda1 #floppy -fstype=auto :/dev/fd0 #floppy -fstype=ext2 :/dev/fd0 #e2floppy -fstype=ext2 :/dev/fd0 #jaz -fstype=ext2 :/dev/sdc1 #removable -fstype=ext2 :/dev/hdd nfs -ro,soft,intr 192.168.1.1:/tmp

3.启动autofs服务。 [root@linux webmin-1.150]# service autofs start

4.测试是否能够自动挂载和卸载。 [root@linux tmp]# ls /mnt -a . .. [root@linux tmp]# cd /mnt/nfs [root@linux nfs]# ls debian_desktop lost+found rhel2.1 rhel4.0_update2 sles9 etc.tar redhat9.0 rhel3.0 rhel4.0_update3 suse10.0 fedora3.0 rfas4.1 rhel3.0_update5 sles8 tftpboot.tar fedora4.0 rfdt4.1 rhel4.0 sles8sp3 turbods10 [root@linux nfs]# ls /mnt -a . .. nfs [root@linux nfs]# cd /tmp //30秒之后再测试,发现该文件系统已经自动卸载了 [root@linux tmp]# ls /mnt -a . .. 【实验故障与分析】

下面的表格中列出了在实验过程中可能会出现的故障及其解决方法。看看是不是对

69

Linux系统管理员实训手册

你的实验有所帮助?如果你在实验中还遇到了其他的问题或故障,不妨记录在表格中,通过自己的实践,或者与老师、同学一起找找解决问题的方法。 序号 1 2 3 实验故障 无法挂载到/mnt/nfs 分析与解决 可能是因为系统中/mnt目录已经挂载了远程目录,而当前用户对该远程目录没有足够的权限 【启发联想】

1.auto.misc文件名可以改变吗? 2.autofs自动挂载有何优点?

70

本文来源:https://www.bwwdw.com/article/r48r.html

Top