Date post: | 29-Mar-2015 |
Category: |
Documents |
Upload: | larissa-seale |
View: | 227 times |
Download: | 1 times |
CIS 191 - Lesson 2
StorageDevices
CIS 191 - Lesson 2
Floppy drive and diskettes
Hard drive (IDE and SCSI)
USB flash drive (aka pen drive)
Storage Devices
CIS 191 - Lesson 2
DAS – Direct Attached StorageNAS – Network Attached StorageSAN – Storage Area Networks
Storage Devices
CIS 191 - Lesson 2
IDE drives: Primary master (/dev/hda)Primary slave (/dev/hdb)Secondary master (/dev/hca)Secondary slave (/dev/hdd)
SCSI drives: Each SCSI disk has a target id (1-7) or (1-14). (/dev/sda, /dev/sdb, ...)
Recognizing and specifying storage devices
CIS 191 - Lesson 2
USB Flash (pen) drives: Same device naming as SCSI drives (can use dmesg to distinguish)
Floppies: First drive (/dev/fd0)Second drive (/dev/fd1)…
Recognizing and specifying storage devices
CIS 191 - Lesson 2
RecognizingStorageDevices
CIS 191 - Lesson 2
Master IDE drive on primary
One IDE drive
Recognizing and specifying storage devices
CIS 191 - Lesson 2
Master IDE drive on Secondary
Two IDE drives
Recognizing and specifying storage devices
Master IDE drive on primary
CIS 191 - Lesson 2
USB flash (pen) drive
IDE hard drive
Floppy drive
Recognizing and specifying storage devices
CIS 191 - Lesson 2
SCSI hard drive
USB flash drive
SCSI and USB Flash (pen) drive
Recognizing and specifying storage devices
CIS 191 - Lesson 2
dmesg command output
Plugging in USB flash drive starts here
Device identification (/dev/sdb) shows here
and log ends here
CIS 191 - Lesson 2
Geometry
14 tracks8 sectors per
track
CIS 191 - Lesson 2
Example Physical CHS Disk Drive Geometry
One sectorOne track
3 platters6 heads
14 cylinders
One imaginary cylinder
One head on each side of platter
size = cylinders x heads x sectors per track x 512 bytessize = 14 x 6 x 8 x 512 = 344,064 bytes
CIS 191 - Lesson 2
Disk Drive Geometry
Times have changed!
•Disk drives are no longer limited to 1024 cylinders (old BIOS restriction)
•Modern track density has hit over tens of thousands of tracks per inch (the old 3.5”diskette had 80 per side)
•Zone bit recording places more sectors per track on outside tracks. E.g. A IBM 34.2 GB Deskstar has 272 to 452 sectors per track.
•NOTE: The OS uses logical disk geometry which does not match physical disk geometry.
•Modern drives use Logical Block Addressing (LBA) rather than the old CHS addressing.
CIS 191 - Lesson 2
Disk Drive Geometryphysical ≠ logical
Modern drives have variable number of sectors per track. It is not possible to represent their full capacity using the old CHS method.
The BIOS shows 16 logical heads and 63 logical sectors per track and adjust the number of logical cylinders to approximate the full capacity.
The OS fdisk shows 255 logical heads and 63 logical sectors per track and then adjusts logical cylinders accordingly.
Disk /dev/hda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
CIS 191 - Lesson 2
Disk sizes (fdisk command)5GB VMWare Drive
5 x 1024 x 1024 x 1024 = 5,368,709,120 bytes
255 heads x 63 sectors/track x 652 cylinders x 512 bytes
= 5,362,882,560 bytesNOTE
This is logical (not physical) disk geometry
Cylinders Blocks(1 block = 1024 bytes)
CIS 191 - Lesson 2
Disk sizes (df command)
3,5266,204 x 1000 x (1000/1024) = 3,443,558,594 bytes
= 3.4 GB
101,107 x 1000 x (1000/1024)= 98,737,304 bytes
= 99 MB
NOTE: 1 computer KB = 1,024 bytes (2 to the 10th power)
1 human KB = 1,000 bytes
CIS 191 - Lesson 2
DiskPartitions
CIS 191 - Lesson 2
Free Space
Setting up Hard DrivesStep 1 – Add hard drive to computer
Add the hard drive:
•Low-level formatting has already been done at the factory (lays out the physical tracks and sectors).
•There are no partitions yet.
•There are no file systems yet.
Note: Floppies, unlike hard drives, can be low-level formatted with the fdformat command
CIS 191 - Lesson 2
Partition Boot Sector
Data
Master Boot Record (MBR)
Free Space
Setting up Hard DrivesStep 2 - Partition the hard drive
Partition Boot Sector
Data
Partition the hard drive:
•The MBR is on the very first sector and is 512 bytes long.
•The first 446 bytes of the MBR gets system boot code.
•The next 64 bytes of the MBR gets the partition table.
•The last 2 bytes are marked 0xAA55.
CIS 191 - Lesson 2
Partition Boot Sector
Data
Master Boot Record (MBR)
Free Space
Setting up Hard DrivesStep 2 - Partition the hard drive
Partition Boot Sector
Data
Primarypartition
Primarypartition
The MBR partition table records the location, status and type of each primary partition.
Each added partition has its own boot sector at the beginning.
CIS 191 - Lesson 2
Setting up Hard DrivesStep 2 - Partition the hard drive
Partition Boot Sector
Data
Master Boot Record (MBR)
Partition Boot Sector
Data
Partition Boot Sector
Data
Partition Boot Sector
Data
Primarypartition
Primarypartition
Primarypartition
Primarypartition
The maximum number of primary partitions is four.
CIS 191 - Lesson 2
Partition Boot Sector
Data
Master Boot Record (MBR)
Partition Boot Sector
Data
Partition Boot Sector
Data
Partition Boot Sector
Data
Primarypartition
Primarypartition
Primarypartition
Extendedpartition
One of the four primary partitions can be an extended partition
An extended may contain an arbitrary number of logical partitions
Unused Boot Sector
Data
Unused Boot Sector
Logicalpartition
Logicalpartition
Setting up Hard DrivesStep 2 - Partition the hard drive
CIS 191 - Lesson 2
Partition Boot Sector
Data
Master Boot Record (MBR)
Partition Boot Sector
Data
Partition Boot Sector
Data
Partition Boot Sector
Data
Unused Boot Sector
Data
Unused Boot Sector
Setting up Hard DrivesStep 3 – Add file systems to partitions
Superblock
Inode Table
ext2 file system
Data Blocks
CIS 191 - Lesson 2
fdisk and mountShow current partitions and their usage
Partition Boot Sector
/boot
Master Boot Record (MBR)
Partition Boot Sector
/
Partition Boot Sector
swap
Partition Boot Sector
/home
Unused Boot Sector
Free Space
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4 /dev/sda5
CIS 191 - Lesson 2
Specifying partitions
Partitions are labeled by Linux as the drive name following by a number. The numbers 1-4 are reserved for the first four primary partitions. 5 or higher indicates it is a logical partition.
Examples:
/dev/hda1 = first partition (primary) on the primary master IDE drive.
/dev/sdb3 = third partition (primary) on the second SCSI drive.
/dev/sda5 = fifth partition (logical partition) on the first SCSI drive.
CIS 191 – Lesson 2
[root@rh9 root]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 332 2562367+ 83 Linux/dev/sda3 333 365 265072+ 82 Linux swap/dev/sda4 366 652 2305327+ 5 Extended/dev/sda5 366 492 1020096 83 Linux/dev/sda6 493 505 104391 83 Linux
Disk /dev/sdb: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table[root@rh9 root]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course, the previouscontent won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help):
Specifying partitionsAdd 1 primary and 1 extended to new drive
/dev/sda has been partitioned already.
/dev/sdb has not been partitioned yet.
CIS 191 – Lesson 2
Command (m for help): nCommand action e extended p primary partition (1-4)ePartition number (1-4): 1First cylinder (1-261, default 1): 1Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): 50
Command (m for help): nCommand action l logical (5 or over) p primary partition (1-4)lFirst cylinder (1-50, default 1):Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-50, default 50): 10
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System/dev/sdb1 1 50 401593+ 5 Extended/dev/sdb5 1 10 80262 83 Linux
Command (m for help):
MBR
Boot Sector
Unused
Free
/dev/s
db1
/dev
/sdb
5
Specifying partitionsAdd 1 primary and 1 extended to new drive
Note: The second partition added is number 5 because it is in an extended partition. Numbers 1-4 are reserved for the four primary partitions.
CIS 191 - Lesson 2
fdiskPartition Utility – (n)ew and (p)rint
[root@rh9 root]# fdisk /dev/sda
Command (m for help): nFirst cylinder (493-652, default 493):Using default value 493Last cylinder or +size or +sizeM or +sizeK (493-652, default 652): +100MCommand (m for help): p
Disk /dev/sda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 332 2562367+ 83 Linux/dev/sda3 333 365 265072+ 82 Linux swap/dev/sda4 366 652 2305327+ 5 Extended/dev/sda5 366 492 1020096 83 Linux/dev/sda6 493 505 104391 83 Linux
Command (m for help):
Boot Sector
/boot
MBR
Boot Sector
/
Boot Sector
swap
Boot Sector
/home
Unused
Free Space
Unused
/dev
/sda
5
/dev
/sda
6
/dev
/sda
2
/dev
/sda
3
/dev
/sda
1
/dev/s
da4
CIS 191 - Lesson 2
fdiskPartition Utility – (m)enu of commands
Command (m for help): mCommand 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):
Boot Sector
/boot
MBR
Boot Sector
/
Boot Sector
swap
Boot Sector
/home
Unused
Free Space
Unused
/dev
/sda
5
/dev
/sda
6
/dev
/sda
2
/dev
/sda
3
/dev
/sda
1
/dev/s
da4
CIS 191 - Lesson 2
fdiskPartition Utility – (w)rite out partition table
Command (m for help): wThe 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@rh9 root]# partprobe
Boot Sector
/boot
MBR
Boot Sector
/
Boot Sector
swap
Boot Sector
/home
Unused
Free Space
Unused
/dev
/sda
5
/dev
/sda
6
/dev
/sda
2
/dev
/sda
3
/dev
/sda
1
/dev/s
da4
Use partprobe to update the kernel without rebooting. This is required if you want to mount a new partition.
CIS 191 - Lesson 2
fdiskPartition Utility – the l option
[root@rh9 root]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 332 2562367+ 83 Linux/dev/sda3 333 365 265072+ 82 Linux swap/dev/sda4 366 652 2305327+ 5 Extended/dev/sda5 366 492 1020096 83 Linux/dev/sda6 493 505 104391 83 Linux
Boot Sector
/boot
MBR
Boot Sector
/
Boot Sector
swap
Boot Sector
/home
Unused
Free Space
Unused
/dev
/sda
5
/dev
/sda
6
/dev
/sda
2
/dev
/sda
3
/dev
/sda
1
/dev/s
da4
CIS 191 - Lesson 2
Making File
Systems
CIS 191 - Lesson 2
[root@rh9 root]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 332 2562367+ 83 Linux/dev/sda3 333 365 265072+ 82 Linux swap/dev/sda4 366 652 2305327+ 5 Extended/dev/sda5 366 492 1020096 83 Linux/dev/sda6 493 505 104391 83 Linux
Disk /dev/sdb: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table[root@rh9 root]# echo "Rich was here" > /dev/sdb[root@rh9 root]# xxd /dev/sdb | more0000000: 5269 6368 2077 6173 2068 6572 650a 0000 Rich was here...0000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ < snipped >................0000150: 0000 0000 0000 0000 0000 0000 0000 0000 ................[root@rh9 root]#
/dev/sdb is a newly added un-partitioned drive
You can write and read to the drive however it is very clumsy compared to using a file system*
dd command (continued)Reading and writing directly to a drive
*Never do this to a drive containing important data
[root@rh9 root]# echo "Rich was here too" > test[root@rh9 root]# wc -c test 18 test[root@rh9 root]#[root@rh9 root]# dd if=test of=/dev/sda6 bs=1 count=1818+0 records in18+0 records out[root@rh9 root]# dd if=/dev/sda6 bs=1 count=18Rich was here too18+0 records in18+0 records out[root@rh9 root]#[root@rh9 root]# xxd /dev/sda6 | more0000000: 5269 6368 2077 6173 2068 6572 6520 746f Rich was here to0000010: 6f0a 0000 0000 0000 0000 0000 0000 0000 o...............0000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................< snipped >[root@rh9 root]# dd if=/dev/zero of=/dev/sda6 bs=1 count=1818+0 records in18+0 records out[root@rh9 root]# xxd /dev/sda6 | more0000000: 0000 0000 0000 0000 0000 0000 0000 0000 ................0000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................< snipped >
CIS 191 - Lesson 2
/dev/sdb6 is a newly added, un-mounted partition on /dev/sda
/dev/zero has an unlimited numbers of binary zeros. Can be used to zero out a partition or drive.*
dd command (continued)Reading and writing directly to a partition
We can also write and read directly to the partition.*
*Never do this to a partition containing important data
CIS 191 - Lesson 2
Adding File Systems
Superblock
Inode Table
Data Blocks
Analogy: making a file system on an empty partition is like painting the stripes on a parking lot. It organizes the space and makes it efficient.
ext2 file system
CIS 191 - Lesson 2
Adding File Systems
Superblock
Inode Table
mkfs –t ext2 /dev/sda6
Data Blocks
Boot Sector
/boot
MBR
Boot Sector
/
Boot Sector
swap
Boot Sector
/home
Unused
Free Space
Unused
/dev
/sda
5
/dev
/sda
6
/dev
/sda
2
/dev
/sda
3
/dev
/sda
1
/dev/s
da4
CIS 191 - Lesson 2
mkfs –t type device -t ext2 –t ext3 (has journaling) -t vfat (compatible with Windows) -t jfs (IBM’s journaled file system) -t reiserfs
For ext2 or ext3 use: -N option to specify number of inodes-m option to specify % blocks reserved for superuser (default 5%)-L option to set the volume label for the file system
Example: mkfs –t ext3 /dev/sda6(puts ext3 file system on 6th partition of 1st SCSI drive)
Example: mkfs –t ext2 –m 0 –N 1000 –L myfiles /dev/sda6(puts ext2 file system with 1000 inodes, no space reserved for superuser, volume label “myfiles” on 6th partition of 1st SCSI drive, )
Note: mkfs is actually a front end for various file systems builders.
[root@rh9 root]# ls /sbin/mkfs*/sbin/mkfs /sbin/mkfs.ext2 /sbin/mkfs.jfs /sbin/mkfs.reiserfs/sbin/mkfs.cramfs /sbin/mkfs.ext3 /sbin/mkfs.msdos /sbin/mkfs.vfat
mkfs command
[root@partide root]# fdisk -l /dev/sda
Disk /dev/sda: 999 MB, 999816704 bytes4 heads, 8 sectors/track, 61023 cylindersUnits = cylinders of 32 * 512 = 16384 bytes
Device Boot Start End Blocks Id System/dev/sda1 * 1 61024 976379+ b Win95 FAT32[root@partide root]#[root@partide root]# umount /mnt[root@partide root]# mount /dev/sda1 /mnt[root@partide root]# ls -l /mnttotal 713064-rwxr-xr-x 1 root root 730177536 Mar 23 23:18 KNOPPIX_V5.1.1CD-2007-01-04-EN.iso[root@partide root]#
CIS 191 - Lesson 2
This pen drive works with Windows or Linux
File SystemsFAT32 file system
CIS 191 - Lesson 2
Superblock
Inode Table
Data Blocks
ext2 file system
ext2 file system
Superblock has:• File system type, label, inode count, block
count, etc. about entire file system.• Redundant copies are maintained.• Use: dumpe2fs –h /dev/sda2 to see / superblock info on rh9 VM
inodes have:• file type, permissions, link count, owner,
group, size, major and minor numbers, creation date, modification date, access date, pointers to data blocks.
• Does not contain filenames which are kept in directories.
• Use stat command to see inode information
Data blocks have actual file and directory data.
CIS 191 - Lesson 2
Superblock
Inode Table
ext2 file system
Data Blocks
[simmsben@opus ~]$ls -il letter102609 -rw-r--r-- 1 simmsben cis90 1044 Jul 20 2001 letter
Hello Mother! Hello Father!
Here I am at Camp Granada. Things are very entertaining,and they say we'll have some fun when it stops raining.
All the counselors hate the waiters, and the lake hasalligators. You remember Leonard Skinner? He gotptomaine poisoning last night after dinner.
Now I don't want this to scare you, but my bunk mate hasmalaria. You remember Jeffrey Hardy? Their about toorganize a searching party.
Take me home, oh Mother, Father, take me home! I hate Granada.Don't leave me out in the forest where I might get eatenby a bear! Take me home, I promise that I won't make noise,or mess the house with other boys, oh please don't make mestay -- I've been here one whole day.
Dearest Father, darling Mother, how's my precious littlebrother? I will come home if you miss me. I will evenlet Aunt Bertha hug and kiss me!
Wait a minute! It's stopped hailing! Guys are swimming!Guys are sailing! Playing baseball, gee that's better!Mother, Father, kindly disregard this letter.
Alan Sherman
bigfile 102574bin 102575letter 102609
bigfile 102574bin 102575letter 102609
102609
-
1
simmsben
cis90
1044
2001-07-20
2008-08-08
2008-06-20
Pointer(s) to data blocks
inode number
Type
Number of links
User
Group
Size
Modification time
Access Time
Change time
Pointer(s) to data blocks
rw-r—r-- Permissions
CIS 191 - Lesson 2
ext2 file systemUsing dumpe2fs –h to show superblock information
[root@rh9 root]# dumpe2fs -h /dev/sda2dumpe2fs 1.32 (09-Nov-2002)Filesystem volume name: /Last mounted on: <not available>Filesystem UUID: b552eed8-4c9d-4f8f-9edf-dd76037f82bdFilesystem magic number: 0xEF53Filesystem revision #: 1 (dynamic)Filesystem features: has_journal filetype needs_recovery sparse_superDefault mount options: (none)Filesystem state: cleanErrors behavior: ContinueFilesystem OS type: LinuxInode count: 320640Block count: 640591Reserved block count: 32029Free blocks: 228375Free inodes: 220820First block: 0Block size: 4096Fragment size: 4096Blocks per group: 32768Fragments per group: 32768Inodes per group: 16032Inode blocks per group: 501Filesystem created: Fri Jul 18 09:37:33 2008Last mount time: Fri Jul 18 17:06:16 2008Last write time: Fri Jul 18 17:06:16 2008Mount count: 3Maximum mount count: -1Last checked: Fri Jul 18 09:37:33 2008Check interval: 0 (<none>)Reserved blocks uid: 0 (user root)Reserved blocks gid: 0 (group root)First inode: 11Inode size: 128Journal UUID: <none>Journal inode: 8Journal device: 0x0000First orphan inode: 229443
[root@rh9 root]#
If you leave off the –h option you will also see the data block status as well.
CIS 191 - Lesson 2
ext2 file systemUsing stat command to show Inode details
[root@rh9 root]# lsanaconda-ks.cfg install.log install.log.syslog test testdir[root@rh9 root]# ls -ltotal 36-rw-r--r-- 1 root root 1220 Jul 18 16:57 anaconda-ks.cfg-rw-r--r-- 1 root root 19626 Jul 18 16:51 install.log-rw-r--r-- 1 root root 2895 Jul 18 16:51 install.log.syslog-rw-r--r-- 1 root root 18 Jul 18 17:24 testdrwxr-xr-x 2 root root 4096 Jul 20 18:41 testdir[root@rh9 root]# stat test testdir File: `test' Size: 18 Blocks: 8 IO Block: 4096 Regular FileDevice: 802h/2050d Inode: 37058 Links: 1Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)Access: 2008-07-20 18:40:47.000000000 -0700Modify: 2008-07-18 17:24:47.000000000 -0700Change: 2008-07-18 17:24:47.000000000 -0700
File: `testdir' Size: 4096 Blocks: 8 IO Block: 4096 DirectoryDevice: 802h/2050d Inode: 20964 Links: 2Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)Access: 2008-07-20 18:41:08.000000000 -0700Modify: 2008-07-20 18:41:08.000000000 -0700Change: 2008-07-20 18:41:08.000000000 -0700
[root@rh9 root]#
Note: The name of the file is not kept in the Inode. It is kept as data in a directory file.
CIS 191 - Lesson 2
ext2 file systemlost+found directory
[root@rh9 root]# mkfs -t ext2 /dev/sda6mke2fs 1.32 (09-Nov-2002)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)26104 inodes, 104391 blocks5219 blocks (5.00%) reserved for the super userFirst data block=113 block groups8192 blocks per group, 8192 fragments per group2008 inodes per groupSuperblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729
Writing inode tables: doneWriting superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@rh9 root]# mount /dev/sda6 /mnt[root@rh9 root]# ls /mntlost+found[root@rh9 root]# ls -l /mnttotal 12drwx------ 2 root root 12288 Jul 21 08:22 lost+found[root@rh9 root]#
Note: The lost+found directory is created when you make a ext2 or ext3 file system. This is where the fsck utility will place any recovered data it finds when checking a file system. Don’t delete it!
CIS 191 - Lesson 2
Mounting File
Systems
CIS 191 - Lesson 2
Mounting and Un-mounting file systems • mount [device-file] [directory] • umount [device-file | directory]
Mount information1./etc/fstab (what to mount at boot time)2./etc/mtab (current mount status)
Mounting File Systems
CIS 191 - Lesson 2
/
/bin
/etc
/mnt
/cdrom
On the rh9 VM
[root@rh9 root]# mount/dev/sda2 on / type ext3 (rw)none on /proc type proc (rw)/dev/sda1 on /boot type ext2 (rw)none on /dev/pts type devpts (rw,gid=5,mode=620)/dev/sda5 on /home type ext3 (rw)none on /dev/shm type tmpfs (rw)
[root@rh9 root]# cat /etc/mtab/dev/sda2 / ext3 rw 0 0none /proc proc rw 0 0/dev/sda1 /boot ext2 rw 0 0none /dev/pts devpts rw,gid=5,mode=620 0 0/dev/sda5 /home ext3 rw 0 0none /dev/shm tmpfs rw 0 0[root@rh9 root]#
[root@rh9 root]# ls -F /home /boot /mnt/boot:boot.b kernel.h module-info-2.4.20-6 [email protected] lost+found/ os2_d.b vmlinuz-2.4.20-6config-2.4.20-6 message System.map@grub/ message.ja System.map-2.4.20-6initrd-2.4.20-6.img module-info@ vmlinux-2.4.20-6
/home:lost+found/ rsimms/
/mnt:cdrom/ floppy/ hgfs/[root@rh9 root]#
/dev
/boot
/home
/rsimms
/grub
/lost+found
/lost+found
/dev/sda1
/dev/sda2
/dev/sda5
/dev/sda6
/floppy
/hgfs
mount command with no arguments shows current mount status in /etc/mtab
Showing current mount status
CIS 191 - Lesson 2
/
/bin
/etc
/mnt
/dir1
On the rh9 VM
[root@rh9 root]# mkfs -t ext3 /dev/sda6mke2fs 1.32 (09-Nov-2002)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)26104 inodes, 104391 blocks5219 blocks (5.00%) reserved for the super userFirst data block=113 block groups8192 blocks per group, 8192 fragments per group2008 inodes per groupSuperblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729
Writing inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@rh9 root]# mount /dev/sda6 /mnt[root@rh9 root]# cd /mnt[root@rh9 mnt]# mkdir dir1 dir2[root@rh9 mnt]# lsdir1 dir2 lost+found[root@rh9 mnt]# cd[root@rh9 root]# ls /mntdir1 dir2 lost+found[root@rh9 root]# umount /mnt[root@rh9 root]# ls /mntcdrom floppy hgfs[root@rh9 root]#
/dev
/boot
/home
/rsimms
/grub
/lost+found
/lost+found
/fdir2
/lost+found
/dev/sda1
/dev/sda2
/dev/sda5
/dev/sda6
mount will overlay the new files ystem on a directory in the current file hierarchy. The old directory is no longer accessible until the new one is un-mounted
Making a file system and mounting it
/dir1
/fdir2
/lost+found
/
/bin /etc /mnt
/cdrom
/dev/boot /home
/rsimms
/grub
/lost+found
/lost+found
/floppy
/hgfs
/lib
/dev/sda6
/dev/sda1
/dev/sda5
Mounting File SystemsLike pinning the tail on the donkey
mount /dev/sda6 /mnt
/
/bin /etc /mnt
/dir1
/dev/boot /home
/rsimms
/grub
/lost+found
/lost+found
/dir2
/lost+found
/lib
/dev/sda1
/dev/sda5
Mounting File SystemsLike pinning the tail on the donkey
/dev/sda6
mount /dev/sda6 /mnt
Mounting File SystemsCaveats
• Don’t mount a file system to a directory you are in.
• You can’t un-mount a file system you have cd’ed into:
[root@rh9 mnt]# umount /mntumount: /mnt: device is busy[root@rh9 mnt]# cd[root@rh9 root]# umount /mnt[root@rh9 root]#
CIS 191 - Lesson 2
[root@rh9 root]# mount/dev/sda2 on / type ext3 (rw)none on /proc type proc (rw)/dev/sda1 on /boot type ext2 (rw)none on /dev/pts type devpts (rw,gid=5,mode=620)/dev/sda5 on /home type ext3 (rw)none on /dev/shm type tmpfs (rw)
[root@rh9 root]# cat /etc/mtab/dev/sda2 / ext3 rw 0 0none /proc proc rw 0 0/dev/sda1 /boot ext2 rw 0 0none /dev/pts devpts rw,gid=5,mode=620 0 0/dev/sda5 /home ext3 rw 0 0none /dev/shm tmpfs rw 0 0[root@rh9 root]#
devicemount point
file system type
mount options
dump frequency
fsckpass
Note: spaces added to output above for readability
Mounting File Systemsmount command and /etc/mtab
CIS 191 - Lesson 2
[root@rh9 root]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1LABEL=/boot /boot ext2 defaults 1 2none /dev/pts devpts gid=5,mode=620 0 0LABEL=/home /home ext3 defaults 1 2none /proc proc defaults 0 0none /dev/shm tmpfs defaults 0 0/dev/sda3 swap swap defaults 0 0/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
devicemount point
file system type
mount options
dump frequency
fsckpass
Note: spacing modified in output above for readability
Mounting File Systems/etc/fstab
/etc/fstab is used to automatically mount file systems at boot time
CIS 191 - Lesson 2
[root@rh9 root]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1LABEL=/boot /boot ext2 defaults 1 2none /dev/pts devpts gid=5,mode=620 0 0LABEL=/home /home ext3 defaults 1 2none /proc proc defaults 0 0none /dev/shm tmpfs defaults 0 0/dev/sda3 swap swap defaults 0 0/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
devicemount point
file system type
mount options
dump frequency
fsckpass
Note: spacing modified in output above for readability
Swap Space/etc/fstab
/etc/fstab is used to automatically mount file systems at boot time