Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Backups, Commands & Shells

CD/DVD-to-ISO Helper Script

Submitted by on November 27, 2019 – 9:39 pm

I can’t recall the last time I needed to convert a CD to ISO. I have four laptops and not one even has a DVD drive. It took me a while to find an external drive and remember how to do this.

To avoid having to deal with this nonsense the next time around, I wrote a little helper script. I was running it in Elementary OS VM under VirtualBox on Windows 10. Because the VM is rather small, I have the script mount an NFS share and write the ISO to it. You can certainly make this a local directory, if space is not an issue. The script is also available on my GitHub repo.

#!/bin/bash
#
#                                      |
#                                  ___/"\___
#                          __________/ o \__________
#                            (I) (G) \___/ (O) (R)
#                                   Igor Os
#                           igor@comradegeneral.com
#                                 2019-08-22
# ----------------------------------------------------------------------------
# A small helper script to rip CD-ROM to ISO and put it on NFS share
#
# CHANGE CONTROL
# ----------------------------------------------------------------------------
# 2019-08-22  igor  wrote this script
# ----------------------------------------------------------------------------
function func_configure() {
  nas="192.168.122.132"
  nfs_share="software"
  nfs_mount="/mnt/${nas}/${nfs_share}"
  d="/dev/cdrom"
  t="/mnt/cdrom"
  mkdir -p "${t}" "${nfs_mount}" 2>/dev/null
}

function func_mount_nfs() {
  if [ $(mountpoint ${nfs_mount} 2>/dev/null 1>&2; echo $?) -ne 0 ]; then
  mount.nfs ${nas}:${nfs_share} "${nfs_mount}" || exit 1
  fi
}

function func_mount_cdrom() {
  if [ $(mountpoint /mnt/cdrom 2>/dev/null 1>&2; echo $?) -ne 0 ]; then
  mount /dev/cdrom /mnt/cdrom || exit 2
  fi
}

function func_get_geometry() {
  bs=$(isoinfo -d -i /dev/cdrom | grep -i -E -m1 'block size' | grep -oP '[0-9]{1,}')
  cn=$(isoinfo -d -i /dev/cdrom | grep -i -E -m1 'volume size' | grep -oP '[0-9]{1,}')
  if [ -z "${bs}" ] || [ -z "${cn}" ]; then exit 3; fi
}

function func_cdrip() {
  dd if=/dev/cdrom of=${nfs_mount}/cdrom_${RANDOM}_$(date +'%Y-%m-%d_%H%M%S').iso \
  bs=${bs} count=${cn} status=progress
  umount /mnt/cdrom && eject /dev/cdrom
}

# ----------------------------------------------------------------------------
# RUNTIME
# \(^_^)/                                      __|__
#                                     __|__ *---o0o---*
#                            __|__ *---o0o---*
#                         *---o0o---*
# ----------------------------------------------------------------------------
func_configure
func_mount_nfs
func_mount_cdrom
func_get_geometry
func_cdrip

 

Print Friendly, PDF & Email

Leave a Reply