Linux System Administration, level 1 Lecture 4: Partitioning and Filesystems Part II: Tools & Methods
The sequence 1. Create one or more empty partitions 1a. (optional) Arrange them into a RAID or LVM device and create one or more volumes therein 2. Create a filesystem on each empty volume 3. Mount the volume(s) into your filesystem tree 3a. (optional) Configure /etc/fstab to automatically mount the volume at boot time
Partitioning tools fdisk the CLI standard Not difficult to master if you understand partitioning Disk Druid Red Hat's GUI tool Unfortunately, only available during install parted PARTition EDitor Resizes partitions fips resizes 'doze partitions
Creating a RAID 1. Create RAID partitions (type FD) 2. Create /etc/raidtab; specify partitions See lab exercise for details 3. mkraid /dev/mdx to create the RAID 4. Create a filesystem on it & mount it --- OR... just create it at install time in Disk Druid
RAID tools raidstart, raidstop raidsetfaulty device partition to simulate a failed drive raidhotremove, raidhotadd remove a failed drive from an active RAID, add a (properly partitioned) drive to an active RAID mdadm configure/administer RAIDs lsraid list RAID devices
Creating Logical Volumes 1. Create LVM partitions (type 8E) 2. vgscan to initialize 2 database files (1 time only) 3. pvcreate partition to register the Physical Volumes 4. vgcreate devname to create the Volume Group 5. lvcreate -L size -n name devname to create the Logical Volume --- OR... just create it at install time in Disk Druid
LVM tools vgextend volgroup partition to add a new partition to a Volume Group pvmove partition to move data from a physical volume before removing it vgreduce volgroup partition to remove a Physical Volume from a Volume Group pvdisplay, vgdisplay, lvdisplay for information about your LVM components
Creating filesystems mke2fs options device create an ext2 filesystem Options (not an exhaustive list): -j create a journaling (i.e. ext3) filesystem -L set the filesystem's volume label -c check for bad blocks -R stride=number set the chunk size (optimizes performance if the filesystem is on a RAID)
Resizing a logical volume e2fsadm options device to resize an ext2/ext3 logical volume Examples of options are: -L +100M to increase the LV and FS by 100 MB -L -50M to decrease the LV and FS by 50 MB Calls lvextend or lvreduce Then calls resize2fs
More filesystem tools e2fsck device to check an ext2/ext3 filesystem for errors Must be unmounted In most cases you can use fsck instead No defragment tool ext2/ext3 normally doesn't fragment (unless you fill the partition) tune2fs convert an ext2 fs to ext3 and more dosfsck and mtools for FAT filesystems
Mounting and unmounting Simplest mount command: mount what-to-mount where-to-mount-it What-to-mount is a device. In Unix, all devices are files that live in /dev Your mountpoint is an empty directory you've created somewhere in your tree. Example: mount /dev/hda1 /windoze To unmount: umount device (or) umount mountpoint
mount options mount -o options device mountpoint Options separated by commas (no spaces), can incl. ro, rw mount the device read-only or writeable umask=number to set permissions for FAT loop number to mount a filesystem that is contained in a file (i.e., not in /dev) e.g. a CD- ROM image (.iso file) or an image of a floppy More when we look at /etc/fstab
/etc/fstab: automatic mounting Items in this file will automatically mount at boot Six fields, separated by whitespace: 1. Device name 2. Mountpoint 3. Filesystem type 4. Mount options 5. Level 0 dump frequency 6. fsck order
fstab fields 1-3 1. Device Must be a block device or network share Examples: /dev/hda4 or 10.20.30.4:/home May be a volume label 2. Mountpoint 3. Filesystem type See man mount for the list of possible types Common types are ext3, vfat, iso9660, smb, nfs
fstab field 4 4. Mount options See man mount for the list Special mount options for fstab include auto or noauto whether to mount at boot user or nouser whether non-root users can mount this device. Normally used for CD-ROMs and floppies. noatime do not update the files' access times (speeds disk access on busy systems with many small files) defaults means rw,suid,dev,exec,auto,nouser,async
fstab fields 5-6 5. Level 0 dump frequency 0 never 1 daily, 2 every other day, 3 etc. 6. fsck order 0 don't fsck (usually means it's not an ext2/3 fs) 1 fsck first (only set on root filesystem) 2-9 Second, third, etc. Can be done in parallel. If these fields are missing they are presumed 0
Unix fs owners and permissions Each file is owned by a user and by a group Each file has three sets of permissions: User ( u - the user that owns the file) Group ( g - the group that owns the file) Others ( o - aka the world ) In each set are three possible permissions: read ( r ), write ( w ) and execute ( x ) Represented in nine bits, or three Octal digits
The nine permission bits Three groups... 1 st group: Owner permissions ( u ) 2 nd group: Group permissions ( g ) 3 rd group: World permissions ( o )... of three bits each The 4 bit: Read permission ( r ) The 2 bit: Write permission ( w ) The 1 bit: Execute permission ( x )
Octal representation of the nine bits 100 (read, no write, no execute) = 4 110 (read and write, no execute) = 6 111 (read, write and execute) = 7 101 (read and execute, no write) =??? 755 = owner can read, write & execute; group and world can only read & execute 640 = owner can read & write, group read only, world no access
The 9 bits a la ls -l One character plus rwxrwxrwx If a permission is off, it's a dash: rwxr-xr-x First character: d This file is a directory c This file is a character device (in /dev) b This file is a block device (in /dev) l This file is a symlink
Permissions tools - chown chown, chgrp Change user/ group ownership of a file Both can be done with chown: chown user.group filename Recurse with -R chown -R ken.users *
Permissions tools - chmod chmod Change permissions on a file Can be done symbolically or with Octal chmod g+r filename chmod u-x filename chmod 755 filename Recurse with -R enable group read disable owner execute Octal sets all nine bits chmod -R o+r * make everything in this directory and all directories under it world-readable
One last tool: ln ln -s sourcefile destname makes a symlink One file appears in many directories, but is physically stored only once Works across filesystems, even into remote and dosfs Operations (read, write, execute) on symlink access the actual file Delete operates on the symlink, not the actual file ln sourcefile destname makes a hard link Only works on the same filesystem