LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script that runs before fstab (https://www.linuxquestions.org/questions/linux-newbie-8/script-that-runs-before-fstab-4175580628/)

fanoflq 05-25-2016 12:39 AM

Script that runs before fstab
 
On CentOs7, if I have this line in /etc/fstab:

/dev/sda6 /mnt/tempdir ext4 default 0 0

But I may NOT have /mnt/tempdir yet.

What script I can use to add command to
create directory /mnt/tempdir such that
init process runs it before init runs /etc/fstab
via command mount -a?

Keruskerfuerst 05-25-2016 02:17 AM

With fstab the patitions are mouted.
I think it is not possible to create a directory below /mnt before the lines in fstab are executed.
You can create that directory manually from command line in run level 3 or 5.

jpollard 05-25-2016 05:20 AM

Normally, /mnt is on a permanent filesystem (as part of the root filesystem). Once the subdirectory is created, it will be available on the next boot - thus available before the mount operation gets done.

rknichols 05-25-2016 08:40 AM

Indeed, once you have created that directory it will stay there. If you just need the boot to proceed regardless, you could use the "nofail" option.
Code:

/dev/sda6 /mnt/tempdir ext4 nofail 0 0

fanoflq 05-25-2016 09:55 AM

I thought using rc.local might be a solution using these commands:

Quote:

mkdir /mnt/tempdir
mount -t ext4 /dev/sda5 /mnt/tempdir
Quote:

[user1@localhost mnt]$ file /dev/sda5
/dev/sda5: block special
Then change ownership of rc.local to execute on reboot:
chmod +x /etc/rc.d/rc.local

I have also commented out mount command in /etc/fstab.
But when I reboot I see these in /mnt/tempdir:

Quote:

[user1@localhost mnt]$ ls tempdir1/
aquota.user lost+found
So it works......
But notice I did not specify quota in rc.local.
So why is aquota.user added auto-magically?
What causes it?


Addendum:

But now I have another problem:


Quote:

[user1@localhost ~]$ sudo chown user1.user1 /mnt/tempdir1/
[user1@localhost ~]$ ls -al /mnt/tempdir1/
total 13
drwxr-xr-x. 3 user1 user1 1024 May 25 11:04 .
drwxr-xr-x. 3 root root 21 May 25 11:00 ..
drwx------. 2 root root 12288 May 25 11:04 lost+found
[user1@localhost ~]$ ls -al /mnt
total 5
drwxr-xr-x. 3 root root 21 May 25 11:00 .
dr-xr-xr-x. 17 root root 4096 Apr 15 14:53 ..
drwxr-xr-x. 3 user1 user1 1024 May 25 11:04 tempdir1
[user1@localhost ~]$ sudo quotacheck -u user1 -f /mnt/tempdir1
quotacheck: Cannot stat() given mountpoint user1: No such file or directory
Skipping...
quotacheck: No correct mountpoint specified.
quotacheck: Cannot initialize mountpoint scan.
[user1@localhost ~]$


[user1@localhost tempdir1]$ pwd
/mnt/tempdir1
[user1@localhost tempdir1]$ sudo quotacheck -u -f /mnt/tempdir1
quotacheck: Mountpoint (or device) /mnt/tempdir1 not found or has no quota enabled.
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option.

Quote:

The directory exists, and mount point exists like so:
[user1@localhost tempdir1]$ mount | grep tempdir1
/dev/sda5 on /mnt/tempdir1 type ext4 (rw,relatime,seclabel,data=ordered)

and I do quotacheck again:

[user1@localhost tempdir1]$ sudo quotacheck -u -f /mnt/tempdir1
quotacheck: Mountpoint (or device) /mnt/tempdir1 not found or has no quota enabled.
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option.



Why am I not able to do quotacheck?

Thank you.

dab1414 05-25-2016 11:01 AM

Look here , or here or here for Centos guide.

Seems you might need to enable quota in /etc/fstab first.

fanoflq 05-25-2016 11:26 AM

Here is the "solution":

I added userquota to rc.local like so:
Quote:

mount -t ext4 -o defaults,usrquota /dev/sda5 /mnt/tempdir1
On reboot, here is what I see:
Quote:

[user1@localhost mnt]$ ls -al tempdir1/
total 1
drwxr-xr-x. 2 user1 user1 1024 May 25 11:24 .
drwxr-xr-x. 3 root root 21 May 25 11:45 ..

[user1@localhost mnt]$ mount | grep tempdir1
/dev/sda5 on /mnt/tempdir1 type ext4 (rw,relatime,seclabel,quota,usrquota,data=ordered)


Then ran quotacheck to create aquota.user file:
Quote:

[user1@localhost mnt]$ sudo quotacheck -u -f /mnt/tempdir1
[sudo] password for user1:
[user1@localhost mnt]$ ls -al tempdir1/
total 8
drwxr-xr-x. 2 user1 user1 1024 May 25 11:54 .
drwxr-xr-x. 3 root root 21 May 25 11:45 ..
-rw-------. 1 root root 6144 May 25 11:54 aquota.user

[user1@localhost mnt]$ sudo quota -f /mnt/tempdir1/
Disk quotas for user root (uid 0): none

# Now you can turn quota on, edit quota....
sudo quotaon -f /mnt/tempdir1
sudo edquota -u user1 -f /mnt/tempdir1

But I do not know why aquota.user in /mnt/tempdir1 was created when I did not use the usrquota option in mount command as described in my previous post.

dab1414 05-25-2016 11:53 AM

Quote:

Originally Posted by fanoflq (Post 5550688)
But I do not know why aquota.user in /mnt/tempdir1 was created when I did not use the usrquota option in mount command as described in my previous post.[/B]

Here is a manpage for quotacheck

Quote:

Description

quotacheck examines each filesystem, builds a table of current disk usage, and compares this table against that recorded in the disk quota file for the filesystem (this step is ommitted if option -c is specified). If any inconsistencies are detected, both the quota file and the current system copy of the incorrect quotas are updated (the latter only occurs if an active filesystem is checked which is not advised). By default, only user quotas are checked. quotacheck expects each filesystem to be checked to have quota files named [a]quota.user and [a]quota.group located at the root of the associated filesystem. If a file is not present, quotacheck will create it.

fanoflq 05-25-2016 11:58 AM

Quote:

quotacheck expects each filesystem to be checked to have quota files named [a]quota.user and [a]quota.group located at the root of the associated filesystem. If a file is not present, quotacheck will create it
But I did not ran quotacheck at the time before I look at /mnt/tempdir1.
I just boot up and look at /mnt.tempdir1,
and aquota.user shows up.
I also deleted tempdir1 before reboot!

MadeInGermany 05-25-2016 03:29 PM

Maybe the /dev/sda5 was mounted some time ago, with quotas enabled?

I still do not understand why a simple entry in fstab plus one time a mkdir does not work for you.

fanoflq 05-25-2016 05:47 PM

Quote:

Maybe the /dev/sda5 was mounted some time ago, with quotas enabled?
Not sure.
I may have to delete and a retry....

Quote:

I still do not understand why a simple entry in fstab plus one time a mkdir does not work for you.
I was trying to do it using scripts and config files.

fanoflq 05-26-2016 01:36 PM

Quote:

Maybe the /dev/sda5 was mounted some time ago, with quotas enabled?

I still do not understand why a simple entry in fstab plus one time a mkdir does not work for you.
It turns out you do not have to create the path and subdirectory needed for a mount point. It is created (by who?) when command in /etc/fstab were executed at boot time.

I unmounted /mnt/tempdir, and deleted all directories in /mnt.
I also commented out everything I did in /etc/rc.local
Then created another partition, /dev/sda8, format it with ext4, and put it in /etc/fstab like so:
/dev/sda5 /mnt/tempdir ext4 defaults 0 0
/dev/sda8 /mnt/temp ext4 default 0 0

Recall that /dev/sda5 is the partition that auto-magically has aquota.user when it is mounted to /mnt/tempdir.

and now I reboot ...there is no aquota.user auto-magically create for /dev/sda8 in /mnt/temp:

Quote:

[user1@localhost mnt]$ ls -al /mnt/temp
total 13
drwxr-xr-x. 3 root root 1024 May 26 13:50 .
drwxr-xr-x. 4 root root 31 May 26 13:53 ..
drwx------. 2 root root 12288 May 26 13:50 lost+found
So I suspect there is a command that I may have done previously that creates aquota.user in /mnt/temp as shown here:
Quote:

[user1@localhost mnt]$ ls -al /mnt/tempdir
total 8
drwxr-xr-x. 2 user1 user1 1024 May 25 12:29 .
drwxr-xr-x. 4 root root 31 May 26 13:53 ..
-rw-------. 1 root root 6144 May 25 12:34 aquota.user

Question#1: Why is directory "lost+found" not shown in /mnt/tempdir but it is shown in /mnt/temp?

Below shows sda5 and sda8 are type ext4:
Quote:

[user1@localhost mnt]$ sudo parted -l
[sudo] password for user1:
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 12.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 1049kB 525MB 524MB primary xfs boot
2 525MB 11.5GB 11.0GB primary lvm
3 11.5GB 12.0GB 524MB extended
5 11.5GB 11.5GB 52.4MB logical ext4
6 11.5GB 11.6GB 78.6MB logical
7 11.6GB 11.7GB 52.4MB logical linux-swap(v1)
8 11.7GB 11.8GB 105MB logical ext4
I thought quota was enable in /mnt/tempdir, but that is not the case:
Quote:

[user1@localhost mnt]$ quota -u -f /mnt/tempdir
quota: Mountpoint (or device) /mnt/tempdir not found or has no quota enabled.
quota: Not all specified mountpoints are using quota.
Quote:

[user1@localhost mnt]$ mount | grep temp
/dev/sda8 on /mnt/temp type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sda5 on /mnt/tempdir type ext4 (rw,relatime,seclabel,data=ordered)

Question#2:
Recall that there is nothing in /etc/fstab or /etc/rc.local command line that cause the creation of quotas in /mnt/tempdir, so how do I prevent aquota.user from being created in case for /dev/sda5?


All times are GMT -5. The time now is 10:41 PM.