A script to mount available CD/DVD Drive on system boot automatically ?
Now we will look how to mount a CD/DVD rom drive on Linux/Unix drive automatically on system reboot.
We can use the below command/script in /etc/profile or /etc/rc.sysinit or similar startup script in /etc/rc*/d.
[root@nglinux]# mkdir -p /tmp/cdrom; for i in hda sr0 scd0; do mount -t iso9660 /dev/$i /tmp/cdrom && break; done mount: special device /dev/hda does not exist mount: block device /dev/sr0 is write-protected, mounting read-only
Verify the mountpoint if it is mounted correctly.
[root@nglinux]# df -h /tmp/cdrom Filesystem Size Used Avail Use% Mounted on /dev/sr0 1.7G 1.7G 0 100% /tmp/cdrom [root@nglinux ks]#
Now you can observe that the cdrom is mounted.
The command tries to mount different drives in /dev/ directory and as soon it finds the correct drive, it breaks the loop and exit.
It will not mount other drives since they are not of iso9660 type.
Useful post