How to access (mount) the local hard drive and create a file in the %pre module of the Kickstart script? - centos

I want to access (mount) the local hard drive and create a file in the %pre module of the Kickstart script. But it doesn't seem to work. Please help me, thanks! The ks.cfg code is like this:
%pre
#!/bin/bash
mount /dev/sda1 /mnt
touch /mnt/123456
mkdir /mnt/dir123456
umount /mnt
reboot
%end

Related

permission to write files in Windows Server

I am using redhat OS in virtual box. I have mounted my Server's (windows 2012 R2) hard disk
on my redhat(/home/user1/myfolder) using
sudo mount -t cifs //192.168.100.1/myfolder/ /home/user1/myfolder -o username=MyRegisteredUserNameForServer
Problem:
I can read write and executes the file stored in that server.
Also, using 'sudo nano myfile.txt' I can create a file in the mounted folder "/home/user1/myfolder" but when I try to execute any script that creates files, it says permission denied.
eg: python myscript.py > output.txt
"permission denied"
I tried a lot to get into it but couldn't find the issue.
finally the below worked:
sudo mount -t cifs -o user=MyRegisteredUserNameForServer,password=P#ssw0rd,dir_mode=0777,file_mode=0777 //192.168.100.1/myfolder /home/user1/myfolder

How can I merge 2 mounted volumes on Debian 10?

I've got 2 volumes already mounted on a VPS from Hetzner.
The first one is on / with 1To space. The other one on /home with 2To space.
I want to get my 3 To together, how can I manage to merge those 2 volumes without erasing any data ?
Here is a picture of what a df -h looks like :
Thanks you very much !
You can merge them using a union filesystem. https://en.wikipedia.org/wiki/UnionFS
In Linux, you can find several kernel modules implementing a union fileystem such as aufs and overlayfs. Available modules may vary depending on kernel configuration in your vps. I will give you a configuration example using the aufs kernel module.
In first, create a subdirectory for each mount point:
mkdir -p /for-aufs
mkdir -p /home/for-aufs
To continue, create a directory for the aufs mount point:
mkdir -p /aufs
Edit your /etc/fstab file
none /aufs aufs br:/for-aufs=rw:/home/for-aufs=rw,sum,create=rr 0 0
Or using mount directly:
mount -t aufs -o br:/for-aufs=rw:/home/for-aufs=rw,sum,create=rr none /aufs
Then, you will see a new mount point in /aufs linked to /for-aufs (/dev/md2) and /home/for-aufs (/dev/md3) when executing df -h. When you are using /aufs mount point, a round-robing policy will create/modify files between /for-aufs and /home/for-aufs.
In conclusion, /for-aufs + /home/for-aufs = /aufs
Remember to read the manual for more information:
http://manpages.ubuntu.com/manpages/focal/man5/aufs.5.html

Accidently renamed libc.so.6 and cannot chroot within rescue mode

We have accidently renamed shared library /lib64/libc.so.6 to be /lib64/libc.so_6. Right after previous command the system (CentOS 6.9) throws the following error :
error while loading shared libraries: /lib64/libc.so.6: cannot open shared object file: No such file or directory
When logged in within rescue mode I followed the following commands :
mount /dev/md2 /mnt
mount /dev/md1 /mnt/boot
mount -t dev -o bind /dev /mnt/dev
mount -t proc -o bind /proc /mnt/proc
mount -t sys -o bind /sys /mnt/sys
chroot /mnt
</Code>
Then i get the following error :
/bin/bash: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
I also tried the following commands :
chroot /mnt /bin/bash
chroot /mnt/root/tmp /bin/bash
chroot /mnt/root/tmp /mnt/bin/bash
Then get another error
chroot: failed to run command ‘/mnt/bin/bash’: No such file or directory
Now the system is down and I only have ssh which failed once "libc.so.6" renamed, and rescue mode. How could I enter to system so that i can rename "libc.so_6" back to "libc.so.6"? Is there a work-around to bypass checking for "libc.so_6"?
For the sake of clarity, will post the answer here (in case someone else encounter similar trouble).
When in rescue mode:
mount /dev/md2 /mnt
mv /mnt/lib64/libc.so_6 /mnt/lib64/libc.so.6
Alternatively:
restore system from backup
try booting from some live USB (as Topper Harley proposed in comments)

Centos7 "mount -a" "mount point /mnt/dev/ does not exist"

Adding the following line to the /etc/fstab and rebooting seems to work as expected, i.e. al of the files in the shared directory "DEV" are available and read-only.
/etc/fstab
//192.168.99.100/DEV /mnt/dev/ cifs _netdev,username=username,password=password,ro,uid=500,gid=1001 0 0
However, I am trying to mount this the machines provisioning and avoid rebooting, so I've tried doing a "mount -a" but get the following error:
[root#localhost ~]# mount -a
mount: mount point /mnt/dev/ does not exist
How can I make this mount available without rebooting?
ok, I guess that just adding an /etc/fstab entry automatically creates the mount directory at some point during the first reboot. Soo.... in order to avoid rebooting, I apparently need to manually create the directory first
mkdir /mnt/dev
mount -a
(rejoice)

Symlinking unicorn_init.sh into /etc/init.d doesn't show with chkconfig --list

I'm symlinking my config/unicorn_init.sh to /etc/init.d/unicorn_project with:
sudo ln -nfs config/unicorn_init.sh /etc/init.d/unicorn_<project>
Afterwards, when I run chkconfig --list my unicorn_ script doesn't show. I'm adding my unicorn script to load my application on server load.
Obviously, this is not allowing me to add my script with:
chkconfig unicorn_<project> on
Any help / advice would be awesome :).
Edit:
Also, when I'm in /etc/init.d/ and run:
sudo service unicorn_project start
It says: "unrecognized service"
I figured this out. There were two things wrong with what I was doing:
1) You have to make sure your unicorn script can play nice with chkconfig by adding the below code below #!/bin/bash. Props to digitalocean's blog for the help.
# chkconfig: 2345 95 20
# description: Controls Unicorn sinatra server
# processname: unicorn
2) I was attempting to symlink the config/unicorn_init.sh file when I was already in the project directory which was creating a dangling symlink (pink colored symlink ~> should be teal) by using a relative path. To fix this, I removed the dangling symlink and provided the absolute path to the unicorn_init.sh file.
To debug this I used ll in the /etc/init.d/ directory to see r,w,x permissions and file types, was running chkconfig --list to see a list of services in /etc/init.d/ and also was trying to run the dangling symlink in my /etc/init.d directory with sudo service unicorn_<project> restart
Hope this helps someone.