Showing posts with label FSTab. Show all posts
Showing posts with label FSTab. Show all posts

Tuesday, June 29, 2021

AWS : Mount EFS on EC2 - Part II - V Important

 sudo mkdir -p /efs

sudo chmod -R ugo+rwx /efs     

ls -ld /efs 

sudo vi /etc/fstab


fs-face524e.efs.us-east-1.amazonaws.com:/ /efs nfs4 rw,intr,hard,_netdev,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport


sudo mount -a

sudo reboot now


chmod -R 777 /efs  is not safer

chmod -R ugo+rwx /efs is safer - Does not override SETUID AND SETGID BITS - Just Appends permissions

https://unix.stackexchange.com/questions/296675/is-chmod-r-ugorwx-safer-than-chmod-r-777


cd / && sudo umount /efs && sudo mv /efs /fileshare && sudo chmod ugo+w /fileshare  && cat /etc/fstab 

sudo sed  -i 's+/efs+/fileshare+g' /etc/fstab 

sudo mount -a && sudo reboot now

ls -l /fileshare 

df -h


ls -l /fileshare ; df -h

ls -l /fileshare && df -h


umount /efs 

sudo mv /efs /fileshare

sudo chmod ugo+w /fileshare

sudo vi /etc/fstab

sudo reboot now


https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/


sudo sed   's/efs/fileshare/g' /etc/fstab   //Replace content and its temporary

sudo sed   's+/efs+/fileshare+g' /etc/fstab  // Change Delimiter

sudo sed  -i 's+/efs+/fileshare+g' /etc/fstab //-i save changes to file/stream

sudo sed  -e '/fs-face524e/s/fileshare/helloooo/' /etc/fstab //Replace only if lines contain specific string "fs-face524e"

Thursday, April 1, 2021

FSTAB , Linux




The /etc/fstab File

So far, we’ve seen several examples of the mount command to attach to various filesystems. However, the mounts won’t survive after a reboot.

For some filesystems, we may want to have them automatically mounted after system boot or reboot. The /etc/fstab file can help us to achieve this.


FSTAB File, You have to edit using Vi or VIM editor and enter 6 Fields separated by space and then save it

Make sure You take a back up of current/original FSTAB file


Table structure

The table itself is a 6 column structure, where each column designates a specific parameter and must be set up in the correct order. The columns of the table are as follows from left to right: 

  • Device: usually the given name or UUID of the mounted device (sda1/sda2/etc).
  • Mount Point: designates the directory where the device is/will be mounted. 
  • File System Type: nothing trick here, shows the type of filesystem in use. 
  • Options: lists any active mount options. If using multiple options they must be separated by commas. 
  • Backup Operation: (the first digit) this is a binary system where 1 = dump utility backup of a partition. 0 = no backup. This is an outdated backup method and should NOT be used. 
  • File System Check Order: (second digit) Here we can see three possible outcomes.  0 means that fsck will not check the filesystem. Numbers higher than this represent the check order. The root filesystem should be set to 1 and other partitions set to 2

[root@ip-172-31-58-120 ec2-user]# blkid
/dev/xvda1: LABEL="/" UUID="74fc4c15-c86f-4c31-92f6-0df873546b85" TYPE="xfs" PARTLABEL="Linux" PARTUUID="ed868158-eb4b-43a5-8ed5-8b58aa998193"
/dev/xvdf: UUID="2008-11-19-03-48-46-00" LABEL="CDROM" TYPE="iso9660" PTUUID="4971ec01" PTTYPE="dos"

[root@ip-172-31-58-120 ec2-user]# lsblk -f
NAME  FSTYPE  LABEL UUID                                 MOUNTPOINT
xvda
xvda1 xfs     /     74fc4c15-c86f-4c31-92f6-0df873546b85 /
xvdf  iso9660 CDROM 2008-11-19-03-48-46-00               /media/census

[root@ip-172-31-58-120 census]# cat /etc/fstab
UUID=74fc4c15-c86f-4c31-92f6-0df873546b85    /            xfs     defaults,noatime  1   1
UUID=2008-11-19-03-48-46-00                 /media/census iso9660 defaults 0 0


Attach Disk, Format File System, Mount Disk - Linux Machine





3 Steps to Add Disk to Linux System
  •  Attach  (Via AWS Management Console)
  • Format (Add FileSystem/Format Disk/Format Volume)
  • Mount (Make new Disk available under a name)
  • Automatic Mount after Reboot - Edit "/etc/fstab" File
----------------------------------------------------------------------------------------------------------------
  • Find list of all devices attached to  System
      • lsblk -fa
      • du -h
  • Find out which device is unMounted - Device not having Mount Path 
  • FInd out if that Unmounted(Only Attached, Not Mounted) Device is  Blank or has Data within it.
      • sudo file -s /dev/xvdf 
  • Attached Disk can be readonly like a Bootable CD or It can be blank 
  • If The Attached Disk is having no data/raw/blank - Format it and add Filesystem to it , 
  • If the output shows simply data, as in the following example output, there is no file system on the device
  • Use "mkfs" command to create a Filesystem or Format a disk
      •  sudo mkfs -t xfs /dev/xvdf
  • Mount the Disk using below command,   mount <Device_Name> <Mount_Path>
      • sudo mount /dev/xvdf /data
  • Once we mount disk on a label, We need to edit "/etc/fstab" file to make sure that When we reboot System, We can mount these disks automatically under specified names
      • vi /etc/fstab
  • Find out <DEVICE_ID> using "blkid" 
      • blkid
--------------------------------------------------------------------------------------------------------------------------
3.4. NFS

NFS (Network File System) is a distributed filesystem protocol that allows us to share remote directories over a network.

To mount an NFS share, we must install the NFS client package first.

Let’s say we have a well-configured NFS shared directory “/export/nfs/shared” on a server 192.168.0.8.

Similar to the Samba share mount, we first create the mount point and then mount the NFS share:

root# mkdir /mnt/nfsShare
root# mount -t nfs 192.168.0.8:/export/nfs/shared /mnt/nfsShare

root# mount | grep nfsShare
192.168.0.8:/export/nfs/shared/ on /mnt/nfsShare type nfs (rw,addr=192.168.0.8)

3.5. Commonly Used mount -o Option

The mount command supports many options.

Some commonly used options are:

  • loop – mount as a loop device
  • rw – mount the filesystem read-write (default)
  • ro – mount the filesystem read-only
  • iocharset=value – character to use for accessing the filesystem (default iso8859-1)
  • noauto – the filesystem will not be mounted automatically during system boot

3.6. The /etc/fstab FileSo far, we’ve seen several examples of the mount command to attach to various filesystems. However, the mounts won’t survive after a reboot.

For some filesystems, we may want to have them automatically mounted after system boot or reboot. The /etc/fstab file can help us to achieve this.The /etc/fstab file contains lines describing which filesystems or devices are to be mounted on which mount points, and with which mount options.

All filesystems listed in the fstab file will be mounted automatically during system boot, except for the lines containing the “noauto” mount option.

Let’s see an /etc/fstab example:

$ cat /etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/sdb1	/	ext4	rw,defaults,noatime,commit=120,data=ordered	0	1
/dev/sdb2	/home	ext4	rw,defaults,noatime,data=ordered	0	2
/dev/sda3	/media/Backup	ntfs-3g	defaults,locale=en_US.UTF-8	0	0
/dev/sda2	/media/Data	ntfs-3g	defaults,locale=en_US.UTF-8	0	0
...

Thus, if we add the following line in this file, the archLinux.iso image will be automatically mounted on /mnt/archIso after system boot:

/media/Data/archLinux.iso /mnt/archIso udf ro,relatime,utf8 0 0

Once a filesystem is mentioned in /etc/fstab, we can mount it by just giving the mount point or the device.

For instance, with the above fstab configuration, we can mount the /dev/sda2 partition with either of the two short commands:

root# mount /media/Data

or

root# mount /dev/sda2

4. Unmounting a Filesystem

The umount command notifies the system to detach the given mounted filesystems. We just provide the filesystem name or the mount point following the umount command.

For example, if we want to unmount the previously mounted USB stick and ISO image:

root# umount /dev/sdd1
root# umount /mnt/archIso

We can also umount multiple mounted filesystems in one shot:

root# umount /dev/sdd1 /mnt/archIso

4.1. Lazy UnmountWhen we want to umount a filesystem, we don’t always know if there are operations still running on it. For instance, a copy job could be running on the filesystem.

Of course, we don’t want to break the copy and get inconsistent data. The option -l will let us do a “lazy” umount.

The -l option informs the system to complete pending read or write operations on that filesystem and then safely unmount it:

root# umount -l mount_point

4.2. Force UnmountIf we pass -f option to the command umount, it’ll forcefully unmount a filesystem even if it’s still busy:

root# umount -f mount_point

We should be careful while executing umount with -f as it could lead to corrupt or inconsistent data in the unmounted filesystem.

One real-world use case for force unmounting could be unmounting a network share because of a connection problem.

-------------------------------------------------------------------------------------

[root@ip-172-31-58-120 ec2-user]# blkid
/dev/xvda1: LABEL="/" UUID="74fc4c15-c86f-4c31-92f6-0df873546b85" TYPE="xfs" PARTLABEL="Linux" PARTUUID="ed868158-eb4b-43a5-8ed5-8b58aa998193"
/dev/xvdf: UUID="2008-11-19-03-48-46-00" LABEL="CDROM" TYPE="iso9660" PTUUID="4971ec01" PTTYPE="dos"

[root@ip-172-31-58-120 ec2-user]# lsblk -f
NAME  FSTYPE  LABEL UUID                                 MOUNTPOINT
xvda
xvda1 xfs     /     74fc4c15-c86f-4c31-92f6-0df873546b85 /
xvdf  iso9660 CDROM 2008-11-19-03-48-46-00               /media/census

[root@ip-172-31-58-120 census]# cat /etc/fstab
UUID=74fc4c15-c86f-4c31-92f6-0df873546b85    /            xfs     defaults,noatime  1   1
UUID=2008-11-19-03-48-46-00                 /media/census iso9660 defaults 0 0

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass