Filesystems • Objectives – to understand Unix filesystem concepts • Contents – disk terminology – fdisk – raid, lvm – Make filesystem – filesystem utilities – Check filesystems – Repair – Quota • Practical – to make and mount a disk filesystem • Summary
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Filesystems
• Objectives– to understand Unix filesystem concepts
• Contents– disk terminology
– fdisk
– raid, lvm
– Make filesystem
– filesystem utilities
– Check filesystems
– Repair
– Quota
• Practical– to make and mount a disk filesystem
• Summary
File System Structure
• Single inverted tree structure– individual disks are hidden from the casual user
• Filesystems define how disks are structured– different disks can be formatted with different filesystems
– all filesystems have a superblock (disk information)
– all filesystems have the concept of file i-nodes
• Filesystems must be mounted into the tree structure– a disk/partition can be mounted onto any directory
– directory is referred to as a mount point
• Unix accessed through file interface– file permissions used to control user access to the system
File System Types• A filesystem type defines how the disk data is structured
– Unix supports many different filesystem types (typically 12 or more)– UFS standard across all platforms– many systems support DOS FAT filesystems
• ext2fs classic Linux filesystem (UFS like)– Most well known, many proven recovery toolkits
• ext3fs next generation Linux filesystem– Journalled filesystem for servers with mixed size large number of files
• NFS– Network file system
• ISO 9660 & Joilet– CD-Rom
• MSDOS– DOS filesystem
• VFAT– Originally to be compatible with Windows95 to overcome 8.3 limit
File System Types, continued.
• Reiserfs alternate filesystem for linux– Used by many homeusers, fast for many small files
• UFS (or Fast File System) from Berkeley– long filenames (255), faster and more efficient than many other filesystems
– may support Logical Volume Management with virtual filesystems, striping and mirroring
• VFS– Virtual filesystems belong to device levels
– Managed by LVM, grouped partitions
• RAID– RAID system work below filesystem level, and belong to device level
– Soft raid, stores data over several disks, based on linux drivers
– Hard raid, like softraid but special hardware controls datastore
Unix filesystems• Partition and Slices
– Physical partitons, INTEL plateform splits disk in up to 4 pices– Logical partitions, reside inside physical partitions, extended partitions– Slice is an are of the disk described by start and stop cylinder– Cylinder is a number of disk blocks which size can be altered– Disk block is a number of disk sectors which usally is 512 or 1024 bytes
• Physical diskdevices are named– ATA types: /dev/hd[a-z][’ ’,1-16]– SCSI types: /dev/sd[a-z][’ ’,1-16] (Also SATA belong here)Examples)
/dev/hda - IDE disk 0 [whole disk]/dev/hda1 - IDE disk 0 first partition/dev/sda1 - SCSI disk lun 0 part 0
• Linux configurable dynamic device naming support udev – User defined device name,practicalfor hotpligged devices, will eventually replace
devfs in future.
• If using devfs naming are different (scsi)/dev/scsi/host0/bus0/target1/lun0/disc [whole disk]/dev/scsi/host0/bus0/target1/lun0/part6 [partition 6]/dev/scsi/host0/bus0/target1/lun0/generic [sg device for disk]
• FDISK (preferred)– Create partitions and partition types
– You must allways operate on the whole disk not partitions
– Look on disk partitions /dev/hda (p-rint partititon)
# fdisk /dev/sdaCommand (m for help): p
Disk /dev/hda: 255 heads, 63 sectors, 1244 cylindersUnits = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System/dev/sda1 * 1 17 136521 83 Linux/dev/sda2 18 83 530145 82 Linux swap/dev/sda3 84 475 3148740 83 Linux
# fdisk /dev/sdaCommand (m for help): p
Disk /dev/hda: 255 heads, 63 sectors, 1244 cylindersUnits = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System/dev/sda1 * 1 17 136521 83 Linux/dev/sda2 18 83 530145 82 Linux swap/dev/sda3 84 475 3148740 83 Linux
Working with FDISK, +100M partition.
• Add partition to disk– You must have unallocated disk-space or delete existing part.
– If you have used all 4 primary partition, extended will be activated
– After selecting primary or logical partition you will be asked
Command (m for help): nCommand action e extended (5 or over) p primary partition (1-4)
Command (m for help): nCommand action e extended (5 or over) p primary partition (1-4)
Partition number (1-4): 4 First cylinder (1-1244, default 476): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-1244, default 1244): +100MUsing value 489
Partition number (1-4): 4 First cylinder (1-1244, default 476): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-1244, default 1244): +100MUsing value 489
Working with FDISK, set type 83 linux
• Select partition type to linux (83) for normal partitions– Fdisk will ask you what partition to change
– After writing typ q to exit fdisk
• Make a filesystem on the clean partition– We select ext3fs!
• Mounting the filesystem
Command (m for help): tPartition number (1-4):4Hex code (type L to list codes):83Command (m for help): w. . .
Command (m for help): tPartition number (1-4):4Hex code (type L to list codes):83Command (m for help): w. . .
# mkfs -t ext3 /dev/hdb1 . . .
# mkfs -t ext3 /dev/hdb1 . . .
# mkdir /mnt/extradisk# mount –t ext3 /dev/hdb1 /mnt/extradisk# ls –1 /mnt/extradisklost+found
# mkdir /mnt/extradisk# mount –t ext3 /dev/hdb1 /mnt/extradisk# ls –1 /mnt/extradisklost+found
Raidlevels, RAID 0
• For increasing storage only, no fault tolerance.
Raidlevels, RAID 1
• Data is mirrored to one or more disks.– Minimum 2 disks
Raidlevels, RAID 3
• Data is striped over disks, parity is kept on separate disk.– Minimum 2 disks
Raidlevels, RAID 5
• Data and parity is striped over disks.– Minimum 3 disks
Preparing for software RAID
• Should I Software RAID Partitions Or Entire Disks?– Both works, but preformance and redundancy is in danger
– Use of a SPARE disk is preventing system stop.
• RAID Partitioning– Smallest partition set maxim partition size in RL1-5
– Raid level 0 is additative and slices can vary in size
• Determining Available Partitions
Unmount partitions that should join the raid, if they are mounted!
Filesystem is added on top of the raid, after it has merged.
# fdisk –l[long list will follow]
# fdisk –l[long list will follow]
# umount /dev/sdd2# umount /dev/sdd2
Preparing the software RAID, part. type.
• Change filesystem typ of partition’s– You have to change each partition in the RAID set to be of type FD
– FD=(Linux raid autodetect.
– Waring message is normal, if it appairs!
• Edit The RAID Configuration FileRAID 5 on using 3 disks.
The set will be called /dev/md0.
Filename is: /etc/raidtab
# fdisk /dev/sdc1Command (m for help): tPartition number (1-5): 1Hex code (type L to list codes): fdChanged system type of partition 1 to fd (Linux raid autodetect)Command (m for help): w
# fdisk /dev/sdc1Command (m for help): tPartition number (1-5): 1Hex code (type L to list codes): fdChanged system type of partition 1 to fd (Linux raid autodetect)Command (m for help): w
Virtual File System, LVM devices• Study LVM admin instruction pages
http://www.gentoo.org/doc/en/lvm2.xmland
http://tldp.org/HOWTO/LVM-HOWTO/
• A virtual filesystem is built up from– Physical Volume’s PV (partitions on disks that form a volume group)– Volume Group’s VG (virtual disk’s)– Logical Volume’s LV (logical volume or mountable partition)– Physical Extent PE (Physical Extent, mini partitions who build up LV)
• Virtual filesystem is flexable– You can increase/decrease ”disk-space” while running– Easy manage fast growing virtual disks– Use dynamic growing virtual disks
• Works like standard disk devices• Can be raided• Is not dependent on single disks for storage
Virtual File System, LVM concept• LVM Concept
One or several disks have one or morepartitionsVG is build up from several partitions on several disksLV is a part of or a whole VGThe LVcan be mounted as any other disk device
Configuring LVM Devices
• Backup Your Data– Logout all users!
– Use the tar command or some other method to backup your data in /home. The LVM process will destroy the data on all physical volumes.
• Going into single user mode# init 1
• Unmount your /home filesystem# umount /home
• Determine The Partition Types# fdisk -l /dev/hde
• Change partition type to 8e for all lvm partitions# fdisk /dev/hde
Command (m for help): t
Partition number (1-6): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Define LVM physical devices & VG
• Define each Physical Volume PV# pvcreate /dev/hde5
pvcreate -- physical volume "/dev/hde5" successfully created
# pvcreate /dev/hdf1
pvcreate -- physical volume "/dev/hdf1" successfully created
# fdisk -l /dev/hde
• Run VGscan# vgscan
vgscan -- reading all physical volumes (this may take a while...)
• Create A VG (VolumeGroup) for the PV’s above– This is our device containing both physical volumes
# vgcreate vg1 /dev/hdf1 /dev/hde5
Volume group ”vg1" successfully created
Create Logical Volume’s
• Look into the Volume Group# vgdisplay vg1
. . .
PE Size 4 MB
Total PE 212
Alloc PE / Size 0 / 0
Free PE / Size 212 / 848 MB
. . .
- We have 212 Physical Extents free to create logical volumes with.
• Create LV:s# lvcreate -l 212 vg1 -n lv1
Logical volume "lv1" created
Make filesystem on the Logical Volume
• Make filesystem– Almost any filesystem will do, in both examples we use ext3fs
New fstab LABEL=/home /home ext3 defaults,usrquota,grpquota 1 2
• Remount the filesystem # mount -o remount /home
• Create The Partition Quota Configuration Files# quotacheck -g -u -a
# chmod 600 /home/aquota.user
# chmod 600 /home/aquota.group
• Start the Quota # quotaon -a
Setting the Quota limit
• Make Linux Read The Quota Config File# edquota -u mp3user
The command will invoke the vi editor which will allow you to edit a number of fields.
Disk quotas for user mp3user (uid 593):
Filesystem blocks soft hard inodes soft hard
/dev/hda3 24 0 0 7 0 0
• Change the soft level & hard levelKalle softlimit of 5Mbyte would be 10000
Kalle hard limit could be set to 15000
• Get out of single user mod# init 3
Managing Quota
• Enforcing Quotas# quotacheck –vagu
- should be added as cron job
• Editing Grace Periods# edquota –t
• Editing Group Quotas (group users)# edquota –g users
• Getting Quota Reports# repquota /home
*** Report for user quotas on device /dev/mapper/vg1-lv1Block grace time: 7days; Inode grace time: 7days Block limits File limitsUser used soft hard grace used soft hard grace-----------------------------------------------------------------------------------------root -- 32828 0 0 3 0 0steen -- 4 1000 1500 1 0 0
*** Report for user quotas on device /dev/mapper/vg1-lv1Block grace time: 7days; Inode grace time: 7days Block limits File limitsUser used soft hard grace used soft hard grace-----------------------------------------------------------------------------------------root -- 32828 0 0 3 0 0steen -- 4 1000 1500 1 0 0
Grace period before enforcing soft limits for users:Time units may be: days, hours, minutes, or secondsFilesystem Block grace period Inode grace period/dev/hda3 7days 7days
Grace period before enforcing soft limits for users:Time units may be: days, hours, minutes, or secondsFilesystem Block grace period Inode grace period/dev/hda3 7days 7days