Miscellaneous old stuff

Data CD creation

Many Linux GUI applications for CD/DVD creation are just front-ends for cmdline programs. Due to license problems Debian, Ubuntu, Fedora and some others not long ago replaced cdrtools package with cdrkit. So, now we have genisoimage instead of mkisofs, and wodim (write optical disk media) instead of cdrecord. Options are still the same.

Since ISO images nowdays are often loaded from the Internet, you usually don't have to use genisoimage (or mkisofs). However, if you want to put on CD some set of files of your own choice, you have to create an ISO image first (this stage is usually omitted, if you're burning a DVD):

genisoimage -o cdimage.iso -R -J -V MUSIC.001 /path/to/folder_to_record

or

mkisofs -o cdimage.iso -R -J -V MUSIC.001 /path/to/folder_to_record

To get an image of CD (DVD), use the following cmd:

dd if=/dev/hda of=cdimage.iso

It works good in most cases, but may fail if disk is copy-protected.

When ISO image is ready, you can burn CD-R or CD-RW. If CD-RW is not fresh new, use option blank=fast or blank=all (slower). To find the device names, use options --scanbus or --devices (or look in /dev):

wodim --devices

wodim dev=OLDATAPI --scanbus

cdrecord dev=ATAPI -scanbus

To burn a CD-R:

wodim -v -eject dev=/dev/scd0 cdimage.iso

wodim -v dev=/dev/sr0 cdimage.iso

To burn a used CD-RW (slowly, reliably):

wodim -v blank=fast speed=4 dev=/dev/scd0 cdimage.iso

Other similar commands:

cdrecord -v dev=ATAPI:0,0,0 cdimage.iso

cdrecord -v speed=16 dev=ATAPI:0,0,0 cdimage.iso

cdrecord -v blank=fast speed=4 dev=ATAPI:1,0,0 cdimage.iso

Some popular options with genisoimage, mkisofs, growisofs:

-f follow symlinks in the source dir;
-J generate Joliet dir records in addition to regular ISO9660 filenames; this is primarily useful when the discs are to be used on Windows systems; Joliet filenames are specified in Unicode and each path component can be up to 64 Unicode chars long; note that Joliet is not a standard, only Windows and Linux can read Joliet extensions; for better portability use both Joliet and Rock Ridge extensions;
-R generate ISO9660 filesystem with Rock Ridge extensions;

-V str   set disk label to str;

Data DVD creation

Copy all necessary files (dirs) to a single dir (linux_soft, in this example). It will be the root dir of the new DVD.

One-step procedure:

growisofs -dvd-compat -Z /dev/hda
-J -R -V SOFTWARE.001 ./linux_soft

Two-step procedure requires more space. The first step is an image file creation:

mkisofs -o sw001.iso -R -J -V SOFTWARE.001 ./linux_soft

The second step is burning DVD (+/-R, +/-RW):

growisofs -dvd-compat -Z /dev/hda=sw001.iso

Blanking DVD+RW disks

To perform this tasks you need DVD+RW-Tools package. Quick format/erase is sufficient in most cases:

dvd+rw-format -blank /dev/dvd

To erase the entire disk (it takes time):

dvd+rw-format -blank=full /dev/dvd

CD-RW (DVD+/-RW) packet writing

Warning!

It is totally outdated by USB flash.

Linux kernel must be 2.6.17 or newer. You may also need udftools.

To format CD-RW and create UDF filesystem:

cdrwtool –d /dev/hdc -q

This utility does not support DVD, so there is another one that can be used to format CD-RW and DVD+/-RW. It usually auto defines media type and the only required parameter is the device spec; UDF revision by default is --udfrev=0x0201 (others: 0x0200, 0x0150, 0x0102), --vid can be used to set volume label:

mkudffs /dev/hdc

mkudffs –-media-type=dvd –-vid=TEMP /dev/hdc

mkudffs –-media-type=cdrw –-vid=TEMP /dev/hdc

To write files to CD/DVD/RW in packet mode, create mount point (something like /media/cdrw). Create packet writing device (each time after system restart), unless it's created automatically:

pktsetup pktcdvd0 /dev/hdc

Device name may be different, for example, /dev/hda.

Insert disk, and if it automounts,

umount /dev/hdc

and mount as shown below:

mount –t udf /dev/pktcdvd0 /media/cdrw

Copy files to CD-RW (or delete from ~), then

umount /dev/pktcdvd0

and eject disk. Optionally, you can remove packet device:

pktsetup –d pktcdvd0

Note, that CD/DVD RW have a limited number of overwrites (~ 1000).

Working with DUMP archives

dump was a popular backup utility in the past, partially due to its ability to archive special (device) files in /dev dir. However, as udev now creates device files during system startup, there is no sense to backup /dev dir. Besides, dump has compatibility problems with ext4 filesystems. One of possible replacements is tar.

dump -0u -f /u02/fs_boot /boot

make a full backup of /boot fs to the file fs_boot;

dump -0u -z9 -f /u02/fs_home /home

make a full backup of /home filesystem to the file fs_home using max compression;

dump -0u -e 557099,4718593 -f /u02/fs_u01 /u01

make a full backup of /u01 fs to the file fs_u01 excluding files (dirs) with the specified inodes (557099 and 4718593); use stat fname to find inode;

dump -0u -M -B256000 -z9 -f /u02/fs_root /

make a full backup of the root fs to file fs_root using max compression and cutting output into pieces of 256 MB;

dump -0u -f /dev/st0 /var

make a full backup of /var filesystem to tape;

restore restores filesystems from backups made with dump utility.

restore [options] -f src

src is a disk file or a device. Full backup of a file system may be restored and subsequent incremental backups layered on top of it. Single files and directory subtrees may be restored from full or partial backups.

restore -i   start interactive restore session;

File system restoration example:

Note!

The first two cmds are performed in case you restore the filesystem from archives stored on HDD.

Start Linux using some appropriate LiveCD or USB flash.

mkdir bkp

create a mount point (bkp) for the backup disk (it's assumed to be /dev/sdb3 in this case); it’s a good idea to have a separate HDD for dump archives of your filesystems);

mount /dev/sdb3 /bkp   mount the backup disk;

mke2fs -c -j -T news -L / /dev/sda2

(it’s assumed that a new system disk is properly installed, configured and partitioned) create a new ext3 filesystem with label / (keep in mind that labels of the filesystems to be restored must be copasetic with the original /etc/fstab);

mount /dev/sda2 /mnt   mount an empty fs on /mnt;

cd /mnt

change dir to /mnt (This is important! We must start the restore procedure in the root of an empty filesystem);

restore -r -f /bkp/arc/fs_root

restore filesystem using backup file fs_root;

or, if a backup tape is available (omit first 2 steps, i.e., mkdir bkp and mount /dev/..., insert the tape cartridge with archive instead):

restore rf /dev/st0

restore filesystem from tape (/dev/st0);

Format floppy, create filesystem

This is a two-stage procedure: 1) low-level format, 1) fs creation:

fdformat /dev/fd0H1440

mkfs -t ext2 /dev/fd0 1440

To format floppy for DOS / Windows FAT:

fdformat /dev/fd0

mformat a:/

Writing disk image file to a diskette (Windows):

rawrite2 -f diskimage.bin -d A:

Writing disk image file to a diskette (Linux);

dd if=diskimage.bin of=/dev/fd0 bs=18k

Sendmail

sendmail -bd -q1h

start sendmail as daemon, process mail queue each hour;

sendmail –bi

re-create aliases.db (also newaliases);

sendmail –bp

print message queue (also mailq);

sendmail –bs

use SMTP protocol on std input/output;

Sendmail directories and files:
/etc/aliases /etc/aliases.db
/etc/sendmail.cf /etc/sendmail.hf
/var/spool/mail /var/spool/mqueue
/var/run/sendmail.pid
Sendmail queue prefixes:
qf message header and control file;
df message body;
lf lock file (old);
tf temporary version of qf;
xf temporary file of mailer errors;

UUENCODE, UUDECODE

uuencode src dst > datafile

conv binary file (src) to ASCII (dst) and write it to datafile;

mail address < datafile

send datafile by e-mail;

& s msg_no datafile

(mail at the reception side) save received msg to a datafile;

uudecode datafile

decode datafile;

Sending binary files from Windows to Linux:

uuew a /s tns.arj

at the Windows side: convert tns.arj to tns.uue; start mail, copy / paste tns.uue and send it;

mail   at the Linux side: start mail, write the received message to a file (& w tns), quit mail;

uudecode tns   decode file tns;

unarj e tns.arj   unpack archive tns.arj;

Oracle JDK 8 (Ubuntu 14.xx..16.xx)

Add the PPA:

sudo add-apt-repository ppa:webupd8team/java

Update and install the installer script:

sudo apt update; sudo apt install oracle-java8-installer

(you have to accept Java license to continue downloading and installing Java binaries)

Set Java env variables (pay attention, it can be already installed):

sudo apt install oracle-java8-set-default

Set JAVA_HOME, if third party tools, like maven, need it (javac runs without it).

There can be multiple Java installations on one computer. You can configure which version is default by using update-alternatives (it manages symbolic links):

sudo update-alternatives --config java