26
ITI-481: Unix Administration Rutgers University Center for Applied Computer Technologies Christopher Uriarte, Instructor Meeting 4

Unix Administration 4

Embed Size (px)

DESCRIPTION

http://www.cju.com/classes/2002/ITI481-03/

Citation preview

Page 1: Unix Administration 4

ITI-481: Unix Administration

Rutgers University Center for Applied Computer TechnologiesChristopher Uriarte, Instructor

Meeting 4

Page 2: Unix Administration 4

Today’s Agenda

• Disk Partitioning

• Directories and File Systems

• Mounting Local File systems

Page 3: Unix Administration 4

Disk Partitions.• A typical UNIX installation will divide one or more

hard drives into multiple partitions.• In Linux, each disk is given its own device name:/dev/hdX (X can range from a-z) – IDE disks/dev/sdX (X can range from a-z) – SCSI disks

• A partition number is added to the device name:/dev/hdXY (Y is the partition number) – IDE disks/dev/sdXY (Y is the partition number) – SCSI disks For example, the first partition on the first IDE drive on a system would be /dev/hda1.

• Disk partition information can be viewed using the ‘df’ command.

Page 4: Unix Administration 4

Understanding File System Types

• Different operating systems use different file systems.

• A file system type is essentially the “specification” for how blocks of data are organized on disks.

• Some file systems have features that other file systems may not have, such as the ability to more easily handle corrupted data or system crashes.

Page 5: Unix Administration 4

Some Common File System Types:• FAT – used with DOS, Windows 3.1, Windows95,

Windows98• FAT32 – used with Windows98/SE, WindowsME an

some Windows95 distributions. Can also be used on Windows NT,2000 and XP.

• NTFS – used on Windows NT, 2000 and XP• UFS (Unix File System) – a generic UNIX file system

used on many UNIX flavors.• EXT2 – a Linux-specific file system used in most

Linux distributions• JFS, ReiserFS, EXT3 – next-generation advance file

systems available as an option on some UNIX systems today. (actually, all are available for Linux)

Page 6: Unix Administration 4

Selecting a File System Type• Linux is unusual, as it allows you to choose

the file system type of a partition during setup.

• Most UNIX’s use their default file system type during install (usually UFS).

• Linux, however, has the flexibility to create and mount many different file system types, although we generally use EXT2, as it’s the most Linux-compatible. (remember, EXT2 is the Linux default)

Page 7: Unix Administration 4

Partitions and File Systems: A Recap

• (From Class 1) Disk Partitioning is the concept of dividing your hard disk into logical partitions, making one hard drive appear as if it’s actually multiple drives.

• There’s several reasons why we partition disks:– Performance– Ease of storage management– Security

Page 8: Unix Administration 4

Disk Partitioning in UNIX

• In UNIX, a physical disk partition is associated with a directory path, sometimes referred to as a mount point.

• All files that are in directories associated with a mount point are stored on the mount point’s physical partition.

• If a directory path is not explicitly associated with a physical disk partition, its files are stored under the root ( “/” ) partition.

Page 9: Unix Administration 4

UNIX Partition Example

/usr

2GB

/ (root)

1.5GB

/home

4GB

swap

Example Partitioning Scheme:

Total Hard Drive Space: 8GB

Contains all files under the /usr directory (I.e.

/usr/local/bin/pico, /usr/bin/vi, etc.)

Contains all files under the /home directors (I.e.

/home/chrisjur, /home/iti1234)

Contains all other files and directors, such

as /var, /opt, /sbin, etc.

[HARD DRIVE]

Page 10: Unix Administration 4

Disk Partitioning: Rules to Live By• Making disk partitions is easy; Changing

them can be hard.• It’s not often easy to expand or shrink disk

partitions (in fact, it’s impossible to do on many operating systems), so make sure you have adequate space for your data storage.

• You can always create partitions from new hard drive.

• You can always create partitions from un-partitioned space on existing, in-use hard drives.

Page 11: Unix Administration 4

Example: Adding a Partition Using Un-partitioned Space

/dev/hda1

Mounted on /home

(Unused)

/dev/hda1

Mounted on /home

/dev/hda2

Mounted on /home2

You can easily take unused hard disk space, format it, partition it and mount

is as a new file system.

Page 12: Unix Administration 4

Steps Required Make a New Partition

• Partition empty space on the hard drive

• Format the newly created partition

• Create a mount point for the partition

• Mount the partition

Page 13: Unix Administration 4

Partitioning Empty Hard Drive Space

• Empty hard drive space can be partitioned using a utility called fdisk.– Fdisk allows you to create, delete and

modify partitions, as well as to set their partition types.

– Allows you to print the partition table for a particular hard drive.

• Can be started with: /sbin/fdisk <hard drive to edit>– e.g. /sbin/fdisk /dev/hda

Page 14: Unix Administration 4

Fdisk: Sample of Help Menu# /sbin/fdisk /dev/hdaCommand (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)

Page 15: Unix Administration 4

Example: Creating a New Partition with Fdisk• Launch fdisk – edit hard disk /dev/hda:> /sbin/fdisk /dev/had

• Type “p” to print the current partition table.• You can now create a new partition, specify the size of

the partition and then specify its file system type.• The “n” option will allow you to add a new partition. You

are prompted to specify whether you want to use a primary partitions 1 to 4) or logical partition (partitions 5 and above). You should choose “p” for primary partition.

• You will be asked to specify a partition number. Refer back to the partition table -You can choose a partition number that is not used from 1-4.

Page 16: Unix Administration 4

Creating Partitions, con’t• You will then be asked to specify the starting

cylinder – simply choose the default.• You will then be asked to specify the size of

your new partition. You can specify this size in cylinders, kilobytes or megabytes (e.g. +1500M makes the partition 1500MB).

• You must now specify the partition’s file system type by using the “t” option. Typing “L” will list the partition type codes. You want to use type 83 – Linux native.

• Finally, type “w” to write the new partition table and exit – you may have to reboot.

Page 17: Unix Administration 4

Step 2: Formatting the new File System• Assuming you just created partition #3 on

/dev/hdb, the partition you just created is now called /dev/hdb3. You must now format that partition.

• Partitions are formatted using the mkfs command. There is a special mkfs, called /sbin/mkfs.ext2, used to format Linux EXT2 file systems. – Usage: /sbin/mkfs.ext2 <partition to format>– e.g. /sbin/mkfs.ext2 /dev/hdb3

Page 18: Unix Administration 4

Step 3: Choosing and Creating a Mount Point• Now that you have a fresh chunk of useable

disk space, you need to decide how you will access it.

• You must choose a unique and empty directory path to be associated with your partition – this is referred to its mount point.

• For example, if you’ve created a partition /dev/hdb2, and you want to access its disk space via the path /newdisk, you must first create the path /newdisk (“mkdir /newdisk”) and we must then mount the partition on that path.

Page 19: Unix Administration 4

Step 4: Mounting the New Partition

• After choosing and creating a mount point, you can mount the partition using the UNIX mount command:– mount [options] <partition> <mount point>For example:mount –t ext2 /dev/hdb3 /newdisk

– ( -t specifies file system type)

• After mounting the file system, you are now ready to use it!

Page 20: Unix Administration 4

Viewing Mounted File Systems

• You can view mounted file systems using the “df –k” command:

Filesystem 1k-blocks Used Available Use% Mounted on

/dev/hda5 3309736 913788 2227820 29% /

/dev/hdb1 495204 13 469623 0% /home

Page 21: Unix Administration 4

Unmounting File Systems

• File systems are unmounted with the umount command:– umount <mount point> – For example:umount /newdisk

• File systems should only be unmounted when they are not in use.

Page 22: Unix Administration 4

Typical Directory Structure

Note: Not all directory paths have their own partitions – in fact, a system may only have 1 partition!

/ - begins the file system structure (root)/boot - kernel files/usr – scripts and binary applications/sbin – basic system tools/home – user home directories/var – log files and other time sensitive data/etc – configuration files/dev – device drivers/opt – typical install location for some commercial software/tmp – temporary storage/mnt – mount points for floppy disks and CD-ROMSswap – swap space

Page 23: Unix Administration 4

Sample Directory Tree with Mount Points

/b oo t/d ev/h d a1

/u s r/d ev/h d a5

/h om e/d ev/h d a6

sw ap/d ev/h d a7

/va r/d ev/h d a8

//d ev/h d a9

Page 24: Unix Administration 4

/etc/fstab

• Specifies what partitions to mount automatically during boot time.

• Entry format:<partition> <mount point> <fs type> <parameters*> <fs_freq*> <fs_passno*>Sample entry:/dev/hda3 /newdisk ext2 defaults 1 2– *These fields are usually set to defaults, 1 and 2, respectively.

• For entries in /etc/fstab, you can run mount command with just mount point:> mount /tmpTo mount all file systems in /etc/fstab:> mount -a

Page 25: Unix Administration 4

Exercises/Problems• How do you rename a the mount point

associated with a partition? (I.e. change the mount point for /dev/hdb3 from /newdisk to /home?)

• What do you do if you’re running out of disk space on a new partition?

• What do you need to do after you’ve added a new hard drive?

Page 26: Unix Administration 4

Homework

• As Assigned in class…