Managing User Accounts and Disks in Linux
Managing User Accounts and Disks in Linux
• Mounting Filesystems
Supported filesystems
Enabling swap areas
Disabling swap area
Using the fstab file to define mountable file systems
Using the mount command to mount file systems
Mounting a disk image in loopback
Using the umount command
Using the mkfs Command to Create a Filesystem
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
• For a USB flash drive, just plug it into an available USB port.
• Determine the device name for the hard disk: # tail -f /var/log/messages
Department of Computer
Science and Engineering
• From the output, you can see that the USB flash drive was found and
assigned to /dev/sdc etc.
• If the USB flash drive mounts automatically, unmount it: umount /dev/sdc1
• Use the fdisk command to create partitions on the new disk.
• If you start with a new USB flash drive, it may have one partition that is
entirely devoted to a Windows-compatible filesystem (such as VFAT).
• Use p to view all partitions and d to delete the partition
Department of Computer
Science and Engineering
• To create a new partition, type the letter n. You are prompted for the type of
partition
• Choose an extended (e) or primary partition (p). Type the letter p to choose
primary.
Department of Computer
Science and Engineering
• Type in the partition number. If you are creating the first partition (or for only
one partition), type the number 1. You are prompted for the first sector to
start the partition.
• Select the first available sector number (you can just press enter to choose
it). You are prompted for the last sector.
• Enter the size of the partition. Because you are just creating one partition to
consume the whole disk, choose the last available sector. To do that you can
just press Enter to accept the default
Department of Computer
Science and Engineering
• Double-check that the drive is partitioned the way you want by pressing p.
• To make changes to the partition table permanent, type w. This will write the
changes, try to sync those changes with the Linux kernel, and quit fdisk.
• If fdisk cannot sync the partition table on the disk with the kernel, the most
likely reason is that a partition from the disk is still mounted.
Department of Computer
Science and Engineering
• Unmount the partition, and then try running the following command to sync
the disk partition table with the kernel: # partprobe /dev/sdc
• If partprobe does not work, rebooting the computer will make sure the disk
and kernel are in sync.
• Although the partitioning is done, the new partition is not yet ready to use.
For that, you must create a filesystem on the new partition:
# mkfs -t ext4 /dev/sdc1
Department of Computer
Science and Engineering
• To be able to use the new filesystem, you need to create a mount point and
mount it to the partition.
• When you are done using the drive, you can unmount it with the umount
command, after which you can safely remove the drive.
# umount /dev/sdc1
Department of Computer
Science and Engineering
• Set up a USB flash drive to mount automatically every time the system boots.
Edit /etc/fstab and add a line describing what and where to mount. A line you
might add: /dev/sdc1 /mnt/test ext4 defaults 0 1
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Managing User Accounts Department of Computer
Science and Engineering
• Mounting Filesystems
Supported filesystems
Enabling swap areas
Disabling swap area
Using the fstab file to define mountable file systems
Using the mount command to mount file systems
Mounting a disk image in loopback
Using the umount command
Using the mkfs Command to Create a Filesystem
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
• For a USB flash drive, just plug it into an available USB port.
• Determine the device name for the hard disk: # tail -f /var/log/messages
Department of Computer
Science and Engineering
• From the output, you can see that the USB flash drive was found and
assigned to /dev/sdc etc.
• If the USB flash drive mounts automatically, unmount it: umount /dev/sdc1
• Use the fdisk command to create partitions on the new disk.
• If you start with a new USB flash drive, it may have one partition that is
entirely devoted to a Windows-compatible filesystem (such as VFAT).
• Use p to view all partitions and d to delete the partition
Department of Computer
Science and Engineering
• To create a new partition, type the letter n. You are prompted for the type of
partition
• Choose an extended (e) or primary partition (p). Type the letter p to choose
primary.
Department of Computer
Science and Engineering
• Type in the partition number. If you are creating the first partition (or for only
one partition), type the number 1. You are prompted for the first sector to
start the partition.
• Select the first available sector number (you can just press enter to choose
it). You are prompted for the last sector.
• Enter the size of the partition. Because you are just creating one partition to
consume the whole disk, choose the last available sector. To do that you can
just press Enter to accept the default
Department of Computer
Science and Engineering
• Double-check that the drive is partitioned the way you want by pressing p.
• To make changes to the partition table permanent, type w. This will write the
changes, try to sync those changes with the Linux kernel, and quit fdisk.
• If fdisk cannot sync the partition table on the disk with the kernel, the most
likely reason is that a partition from the disk is still mounted.
Department of Computer
Science and Engineering
• Unmount the partition, and then try running the following command to sync
the disk partition table with the kernel: # partprobe /dev/sdc
• If partprobe does not work, rebooting the computer will make sure the disk
and kernel are in sync.
• Although the partitioning is done, the new partition is not yet ready to use.
For that, you must create a filesystem on the new partition:
# mkfs -t ext4 /dev/sdc1
Department of Computer
Science and Engineering
• To be able to use the new filesystem, you need to create a mount point and
mount it to the partition.
• When you are done using the drive, you can unmount it with the umount
command, after which you can safely remove the drive.
# umount /dev/sdc1
Department of Computer
Science and Engineering
• Set up a USB flash drive to mount automatically every time the system boots.
Edit /etc/fstab and add a line describing what and where to mount. A line you
might add: /dev/sdc1 /mnt/test ext4 defaults 0 1
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Understanding Server Department of Computer
Administration Science and Engineering
• Type of Networks
Wired network
Wireless network
• The general approach to configuring networking in three types of Linux
systems
Desktop/laptop networking
Server networking
Enterprise networking
Department of Computer
Science and Engineering
TCP/IP Protocol Suite Department of Computer
Science and Engineering
• The three basic protocols are the Transmission Control Protocol (TCP),
which handles receiving and sending out communications;
• The Internet Protocol (IP), which handles the actual transmissions; and
• The User Datagram Protocol (UDP), which also handles receiving and
sending packets.
• The IP protocol, which is the base protocol that all others use, handles the
actual transmissions, the packets of data with sender and receiver
information in each.
Department of Computer
Science and Engineering
• Other protocols provide various network and user services. The Domain
Name Service (DNS) provides address resolution.
• The File Transfer Protocol (FTP) provides file transmission, and the Network
File System (NFS) provides access to remote file systems.
• Table 34-2 lists the different protocols in the TCP/IP protocol suite.
• These protocols make use of either the TCP or UDP protocol to send and
receive packets, which, in turn, uses the IP protocol for actually transmitting
the packets.
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
• The primary command for stopping and starting SysVinit services is the
service command.
• With the service command, the name of the service you are wishing to
control comes second in the command line.
• The last option is what you want to do to the service, stop, start, restart, and
so on.
• The following example shows how to stop the cups daemon.
Department of Computer
Science and Engineering
• Notice that an OK is given, which lets you know that cupsd has been
successfully stopped.
Department of Computer
Science and Engineering
• To start a service, you simply add a start option instead of a stop option on
the end of the service command as follows:
Department of Computer
Science and Engineering
• To restart a SysVinit service, the restart option is used. This option will stop
the service and then immediately start it again.
Department of Computer
Science and Engineering
• If a SysVinit service is stopped when you attempt to reload it, you will get a
FAILED status. This is shown in the following example:
Stopping and starting the Department of Computer
Upstart init daemon Science and Engineering
• The primary command for stopping and starting Upstart init services is the
initctl command. The options are very similar to SysVinit’s service command:
• Stopping a service with Upstart init — In the following example, the status of
the cups daemon is checked and then stopped using the initctl stop
[Link] command.
Department of Computer
Science and Engineering
• Starting a service with Upstart init — In the following example, the cups
daemon is stopped using the initctl stop [Link] command.
Department of Computer
Science and Engineering
• Restarting a service with Upstart init — Restarting a service with Upstart init
will stop and then start the service. However, the configuration file will not be
reloaded.
Department of Computer
Science and Engineering
• Reloading a service with Upstart init — Reloading will not stop and start the
service. It only loads the configuration file again. This is the option to use
when you have made changes to the configuration file.
• Notice that the process ID (PID) is still 2490, which is the same as it was in
the example for restarting the cups daemon because the process was not
stopped and started in the reload process.
Stopping and starting Department of Computer
the systemd daemon Science and Engineering
• For the systemd daemon, the systemctl command will work for stopping,
starting, reloading, and restarting. The options to the systemctrl command
should look familiar.
• Stopping a service with system - In the example that follows, the status of the
cups daemon is checked and then stopped using the systemctl stop
[Link] command.
• Notice that when the status is taken, after stopping the cups daemon, the
service is inactive (dead) but still considered enabled. This means that the
cups daemon will still be started upon server boot.
Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
• Starting a service with system - Starting the cups daemon is just as easy as
stopping it. The example that follows demonstrates this ease.
• After the cups daemon is started, using systemctl with the status option shows the
service is active (running). Also, its process ID (PID) number, 17003, is shown
Department of Computer
Science and Engineering
An NFS file server provides an easy way to share large amounts of data
among the users and computers in an organization. An administrator of a
Linux system that is configured to share its filesystems using NFS has to
perform the following tasks to set up NFS:
1. Set up the network
2. Start the NFS service.
3. Choose what to share from the server
4. Set up security on the server
5. Mount the filesystem on the client
Department of Computer
Science and Engineering
Installing an NFS Server Department of Computer
Science and Engineering
• In Red Hat Enterprise Linux 6, you need the service and chkconfig
commands to check, start, and enable the NFS service (nfs).
• The following commands show the nfs service not running currently and
disabled:
Department of Computer
Science and Engineering
• As mentioned earlier, the rpcbind service must be running for NFS to work.
So, you could use the following commands to start and permanently enable
both the rpcbind and nfs services
Sharing NFS Filesystems Department of Computer
Science and Engineering
Department of Computer
Science and Engineering
• To share an NFS filesystem from your Linux system, you need to export it
from the server system.
• Exporting is done in Linux by adding entries into the /etc/exports file.
• Each entry identifies a directory in your local filesystem that you want to
share with other computers.
• The entry also identifies the other computers that can share the resource (or
opens it to all computers) and includes other options that reflect permissions
associated with the directory.
Department of Computer
Science and Engineering
• Remember that when you share a directory, you are sharing all files and
subdirectories below that directory as well (by default). So, you need to be
sure that you want to share everything in that directory structure.
• There are still ways to restrict access within that directory structure
Configuring the /etc/exports file Department of Computer
Science and Engineering
• To make a directory from your Linux system available to other systems, you need to
export that directory. Exporting is done on a permanent basis by adding information
about an exported directory to the /etc/exports file. The format of the /etc/exports file
is:
• where Directory is the name of the directory that you want to share and Host
indicates the client computer to which the sharing of this directory is restricted.
• Options can include a variety of options to defi ne the security measures attached to
the shared directory for the host.
• Comments are any optional comments you want to add (following the # sign).
Department of Computer
Science and Engineering
• As root user, you can use any text editor to configure /etc/exports to modify
shared directory entries or add new ones. Here’s an example of an
/etc/exports file:
Exporting the shared Department of Computer
filesystems Science and Engineering
• The -a option indicates that all directories listed in /etc/exports should be exported.
• The -r resyncs all exports with the current /etc/exports file.
• The -v option says to print verbose output. In this example, the /pub and /home directories
from the local server are immediately available for mounting by those client computers that
are named (maple and spruce). The /mnt/win directory is available to all client computers.
Securing Your NFS Server Department of Computer
Science and Engineering