USTM16 Linux System Administration Lesson 4: Memory Management and Backups Instructor: Peter Chung (cspeter@cse.ust.hk) Peter Chung (cspeter) 1
GNOME System Monitor A graphical user interface to display the memory usage System => Administration => System Monitor Two concepts here: Memory Swap Peter Chung (cspeter) 2
Memory and Virtual Memory In a typical computer system, memory space is much smaller than disk space Example: 4GB RAM, 1TB (1000GB) hard disk Virtual Memory Using disk as an extension of RAM Usually managed by the underlying operating system to increase the effective size of usable memory It is usually called swap space In Linux, swap space can be a swap file a swap partition Peter Chung (cspeter) 3
Creating a swap file (1/2) Example dd if=/dev/zero of=/extra-swap bs=1024 count=1024 dd is a special command to convert and copy a file The first part: dd if=/dev/zero of=/extra-swap /dev/zero is a special device to generate 0 s and it acts as an input stream bs refers to block size (1024 bytes) count refers to the number of blocks (1024 blocks) Result Create a 1MB file 1024 blocks, each block has 1024 bytes Put it to the location /extra-swap Initialize all values as 0 Peter Chung (cspeter) 4
Creating a swap file (2/2) Using mkswap and swapon Please note that /extra-swap is created by the command dd in the previous slide Steps mkswap /extra-swap swapon /extra-swap Switch off the swap space: swapoff /extra-swap Peter Chung (cspeter) 5
Class Exercise: Creating a 1GB swap file Steps 1. dd if=/dev/zero of=/extra-swap bs=1024 count=102400 2. mkswap /extra-swap 3. swapon /extra-swap 4. System => Administration => System Monitor Click on the Resources tab You can observe that the swap memory increases swapoff /extra-swap You can observe that the swap memory decreases Peter Chung (cspeter) 6
Swap partition mkswap can also be used to create a swap partition Suppose a partition (e.g. partition number 2) of size 512MB is created on the second SCSI disk fdisk /dev/sdb The partition 2 of /dev/sdb can be made as a swap partition as follows: mkswap /dev/sdb2 swapon /dev/sdb2 Similarly, the swap partition can be removed swapoff /dev/sdb2 Peter Chung (cspeter) 7
Defining a swap partition during boot time A line can be added to a file /etc/fstab to explicitly mark a partition as a swap partition Peter Chung (cspeter) 8
Other memory mgnt commands Q: Please try and explain the meanings of the following commands free top vmstat mtools Peter Chung (cspeter) 9
Workbook exercise Task 4.1: USB flash drive management Hints: Use mcopy in the mtools Task 4.2: Swap partition creation Learn a command df Task 4.3: Report disk usage Learn a command du The TAs will come to your desk and mark your answers on the workbook Peter Chung (cspeter) 10
Backups Peter Chung (cspeter) 11
Why creating backups? Using advanced disk management techniques (e.g. RAID) can t solve any problem For example, the whole computer system can be immersed in water Solution A regular backup to a network drive is automatically carried out during the mid-night If the whole computer system is destroyed Data can still be completely / partially recovered from the network drive Peter Chung (cspeter) 12
Important of backup Recover from Hardware failures Software bugs Human mistakes Natural disasters Peter Chung (cspeter) 13
Criteria of choosing backup medium Cost Reliability Extremely important Speed Relatively less important Availability Usability How often backup you make Peter Chung (cspeter) 14
Important files / directories in Linux /home User home directory /etc System configuration files Some directories are not suitable to backup /proc (some hardware information, automatically generated by Linux Kernel) Peter Chung (cspeter) 15
Backup strategy Full backup Backup everything once Incremental backup Backup the changes incrementally Backup strategy Example of using six tapes Tape 1 Full backup (Fri) Tape 2 to tape 5 Incremental backup (Mon Thu) Tape 6 Full backup (2 nd Fri) Tape 2 to tape 5 - Incremental backup (Mon Thu) The cycle repeats to the tape 1 Peter Chung (cspeter) 16
Backup tools tar Create an archive of a number of files dump Backup the file system restore Restore from a dump Peter Chung (cspeter) 17
Options in tar -c Create a new archive -x Extract an existing archive -f [HOSTNAME:]F A network hostname can be added F stands for an archive file name or a device name -v Verbose. List out the details during the process Example 1: Create an archive to pack up all text files tar cvf output.tar *.txt Example 2: Create a zipped archive tar cvjf output.tar.gz *.txt Example 3: Extract files (zipped or not) from an archive tar xvf output.tar Peter Chung (cspeter) 18
Workbook exercise Task 7.2: tar Task 7.5: tar and compress Task 7.1: dump and restore Quite similar to the tar command Task 7.3: dd Task 7.4: cp r (copy recursively) The TAs will come to your desk and mark your answers on the workbook Peter Chung (cspeter) 19