Manage Partitions and Disk on Linux
I. Manage Partitions on Linux
- Every hard drive requires at least one partition. In fact, we can devide a standard hard drive into 16 different partitions.
- You can configure 3 types of partitions on a hard drive
- Primary partition : We can create up to 4 different primary partitions on an IDE or a SCSI hard drive. One primary partition must be active; it will include a bootloader such as GRUB or LILO, or Windows boot loaders.
- Extended partition : If you need more partitions, you can convert one primary partition to extended partition. The extended partition then can be further subdivided into logical partitions.
- Logical partition : An extended partition can be devided into logical partitions. We can have up to 12 logical partitions on a hard drive.
- We can add and manage partitions with fdisk command
- Show disk drive by fdisk command. We are having 1 hard disk and 3 partitions.
- Right now, we are having 3 partitions with SCSI hard disk so it’s showing /dev/sda1, /dev/sda2, /dev/sda3. If it is IDE, it should be /dev/hda1, /dev/hda2.
- Use fdisk to create new partition for new disk in your system. Right now we need create a new partition for new disk /dev/sdb.
- Major Linux Filesystem Formats
- ext2 : The seconde extended filesystem, which was the stardard for Linux OS. If you have older system with ext2 partitions, you can easyly to convert to ext3.
- ext3 : The third extended filesystem, which is current default on Linux System. It includes a journal, which save or records all pending changes, such as data to be written to disk.
- jfs : a journaling filesystem developed by IBM.
- reiserfs : The Reiser filesystem, is based on different designs from the Linux extended filesytems.
- xfs : The filesystem developed by Silicon Graphics, it can support extremely hard drives.
- Formatting a Partition
- Use mkfs command to format Linux partitions. We can choose the type of filesystem by -t switch. You can check bad blocks before formatting with -c switch.
- We also can format partition to ext3 filesystem by -j switch
- We can convert an older format ext2 to ext3 by tune2fs command. The only difference between ext2 and ext3 is journal. Therefore, if you create a journal for ext2 filesystem, it’s ext3.
II. Manage Disk on Linux
- du and df commands are disk management commands on Linux. du –> directory usage and df –> disk free.
- Labels for Linux partition is very important . The default /etc/fstab uses disk labels. We also can find disk lablels in GRUB configuration. But when we create a new partition with fdisk and format with mkfs, it will not have label. So you should have label for that.
- Show label
- We also can get more informatin about partition and lable by dump2fs command.
1. Mount Directories
- Before we can use a Linux partition, we need mount it into the Linux system.
- We need to specify the partition, the directory being mouted, the format with the partition.
mount -t format partition directory
- Normally we only required this command, because it will take filesystem format from disk partition
- We also can add that partition to mount to Linux System for permanently. We can add this line to /etc/fstab file.
- After done /etc/fstab, you can activate your mouting by
- Sometimes you need umount directory on Linux System, you can use umount command
2. Filesystem Troubleshooting
- Filesystem problems normally require troubleshooting during boot.
- fsck commands is very important tool. Linux uses it periodically to automatically check most of the partitions on Linux System.
- fsck command checks and repairs Linux filesystems such as fsck.ext2, fsck.ext3, fsck.reiserfs … If the filesystem is unknown, you can only use fsck command.
- -a switch : automatically repair target filesystems without prompts. Should be used only within /etc/rc.sysinit.
- -b superblock : uses a differents superblock.
- -A switch : Checkes all filesystems lists in /etc/fstab.
- -R switch : When -A used, skips the root (/) directory filesystem.
- -y : automatically say “yes” to suggest a solution.
- If you suspect a problem, you can run fsck on any umounted partition.
- Automated partition checks: fsck command is no longer run periodically by default, you can change that by using command as: tune2fs -c count /dev/partition . To find the mount count information for specific partition, use tune2fs command.
3. Understand /etc/fstab file
- /etc/fstab is used during Linux booting process. It will mount partitions and directories to Linux System.
- Column 1 : Label : The filesystem , such as /usr, or partition, such as /dev/sdb1, to be mounted.
- Column 2 : Mount point : The directory where the partition or filesystem is to be mounted.
- Column 3 : Format : filesytem format as ext2, ext3, ext4 …
- Column 4: Mount Options : The defaults option includes rw (read,write), suid (SUID permissions), dev (terminals and block devices such as drives), exec (binary files), auto (automatically mounted), nouser (only root can mount), and async (data is read and written asynhronously).
- Column 5 : Dump value : If it’s 1, filesystem will automatically written to disk.
- Column 6 : Filesystem Check Order : Filesystems that need fsck. The root / filesystem should be 1; others on local should be 2, swap, virtual, CD and remote directories should be 0.
- Others mount options are availabe such as usrquota and grpquota (for set quotas), noauto (to make sure Linux doesn’t look for CD or floppy when it boots), and user (to let any user mount filesystem, such as CD-rom).
4. Logical Volume Management (LVM)
- Without LVM (Logical Volume Management), once drives are partitioned, there are no easy way to expand the available space.
- Example, your company had 20 users and you created 20 users in /home directory, but right now your company increased more than 20 users. So with LVM, you can expand the size of /home directory.
- LVM also allows you to reallocate chunks of disk space between different filesystems. So with LVM, if you have extra room in a filesystem as /var, you can reallocate that space to /home.
- We can create LVM in installation process. You also can create LVM after installation.
Basic Fundamentals about LVM
- LVM is essentially a mapping of different physical sections of a hard drive. Once collected into a logical volume, filesystems such as /home and /usr can be mouted on that volume. We can reorganize logical volumes to include additional hard drive space.
- Some definitions about LVM
- PV (Physical Volume), a PV usually corresponds to a standard primary or logical partition on a hard drive.
- PE (Physical Extent) a PE is a chunk of disk space. Physical Volumes are divided up into a number of equal sized PEs.
- LE (Logical Extent) a LE is a chunk of disk space. The size of an LE in an LVM system is same size of PEs on that systems. Every LE corresponds to a specifi PE.
- LV (Logical Volume) a LV is a collection of LEs. You can mount filesystems such as /usr and /boot on an LV.
- VG (Volume Group) LVs on our sytem, collected together form a VG (Volume Group). When we configure an LVM system, most commands are applied to a VG.
- Create LVM on Linux
- Step 1: Create a Physical Volume
- Step 2: Create Volume Group
- Step 3: Display Volume Group
- Step 4: Add more disk for Volume Group with another parition
- Step 5: Create a Logical Volume
Create a Logical Volume with 200Mb
lvcreate -l number_of_PEs Data -n LogicalVolume
Note: each PE is 4MB in size.
- Step 6: Increate /dev/Data/LogicalVolume01 to 300M
Thanks for using IThelpblog.com.