Wednesday, November 01, 2017

Cutting Video with ffmpeg

The highlighted represent the starting point for the cut. In this case no ending point set, so by default the output will include all the remaining of the video.

ffmpeg -i input.mp4 -ss 00:20:01 -async 1 -c copy output.mp4 

If we want to cut the video before the end we cand do it in two ways:

ffmpeg -i input.mp4 -ss 00:20:03 -t 00:01:08 -async 1 -c copy output.mp4

The "-t" option specifies a duration, not an end time. The above command will encode 1 minute and 8 seconds of video starting from the time 00:20:01

ffmpeg -i input.mp4 -ss 00:20:03 -to 00:21:11 -async 1 -c copy output.mp4

If you are using a current version of ffmpeg you can also replace "-t" with "-to" in the above command to end at the specified time.

Note:
Use "-c copy" for making it instantly. In that case ffmpeg will not re-encode the video, just will cut to according size.


-----///

Saturday, November 26, 2016

Rotate a PDF under Linux with pdftk

sudo apt-get install pdftk

To rotate page 1 by 90 degrees clockwise:
pdftk in.pdf cat 1east output out.pdf 

To rotate all pages clockwise:
pdftk in.pdf cat 1-endeast output out.pdf 

From the "man" page
The page rotation setting can cause pdftk to rotate pages and documents. Each option sets the page rotation as follows (in degrees): north: 0, east: 90, south: 180, west: 270, left: -90, right: +90, down: +180. left, right, and down make relative adjustments to a page's rotation.

Adding a Swap Partition After System Installation

Updating partitions.
We need to edit /etc/fstab and add the new swap partition.

sudo nano /etc/fstab

We need to add a line that looks like

UUID=735b3be3-779c-4d21-a944-b033225f3ab4 none   swap    sw      0       0

The UUID can be got using the command

sudo blkid /dev/sdaX

---------///
We can format this partition with:

sudo mkswap /dev/sdX
replacing the X with your partition number. Mount this partition as swap with

sudo swapon -U UUID

If you want to use your swap for hibernating then you need to update the UUID in
/etc/initramfs-tools/conf.d/resume
with this content RESUME=UUID=xxx.
Don't forget to
sudo update-initramfs -u

-----///

Sunday, October 16, 2016

Embedding a PDF in Blogger

The following HTML code is to embed a PDF in Blogger (Blogspot). We only need to change the "srcid" value (the 0B6bwihHnzzPHbHdsQUpFYVQ3Mm8 part for the new corresponding PDF value)


The code can be downloaded from here.
Or copied from here:

<iframe height="480px" src="https://docs.google.com/viewer?srcid=0B6bwihHnzzPHbHdsQUpFYVQ3Mm8&amp;pid=explorer&amp;efh=false&amp;a=v&amp;chrome=false&amp;embedded=true" width="720px"></iframe>

Saturday, October 01, 2016

Mounting the Android Phone in Ubuntu 16.04

I was getting the following pop up message 'Unable to mount Android Device' every time that I plugged my Android smartphone in my Linux Ubuntu 16.04 machine.

I found the solution taking as a reference the following thread.

First I used the following command:

lsusb

That gives me:
Bus 001 Device 004: ID 04e8:6860 Samsung Electronics Co., Ltd Galaxy (MTP)

Then I included this info:
# Samsung LTD Galaxy
ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"

in the following file:
sudo vim /lib/udev/rules.d/69-libmtp.rules

And the following line:
ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666"

In the following file:

sudo vim /lib/udev/rules.d/61-persistent-storage-android.rules

And that's all. After a reboot my Linux PC can mount without problems my Android phone.

-----///

Wednesday, June 29, 2016

Updating the Youtube-DL (Now YT-DLP)

One way to solve error: "externally-managed-environment" is to create a virtual environment folder in your root path. By creating and using a virtual environment, you bypass the system Python entirely, allowing you to install and manage packages freely without impacting the system-wide Python installation.

sudo apt install python3-pip
sudo apt install python3.13-venv

python3 -m venv ~/py_envs
source ~/py_envs/bin/activate

python3 -m pip install yt-dlp
python3 -m pip install --upgrade yt-dlp

Before executing the 2nd command above, you can try executing first the 3rd command to see if the prompt returns a newer version suggestion than python3.13-venv  

yt-dlp is a better option with more functionalities. It's a fork from the youtube-dl 

Note: After you leave the virtual environment, if you need to use yt-dlp again, you have to first execute the 3rd and 4th commands above to set the virtual environment. 

Since this is installed in a virtual environment, you won't get notices of new versions available, so you have to run the 6th command above to check if there's an update ready to be installed. 
Sometimes the yt-dlp command may return an error when trying to download a video, in most cases that's fixed installing the new version. 

Thre's a lot of information and help in the manual:

man yt-dlp 

If you want to check first all the available formats of a YouTube video you need the URL of it along with the flag "-F" after the yt-dlp command:

yt-dlp -F https://www.youtube.com/watch?v=wh-07BzfgYY

And you will have an output like the following:
There will be a list of all the formats with IDs, formats, resolutions, video and audio codecs used, file sizes, extensions, FPS, if video or audio only, etc.

The command to download the format of your preference, by example if ID 18 do the following now using the lower case flag "-f" : 

yt-dlp -f 18 https://www.youtube.com/watch?v=wh-07BzfgYY

That format with ID 18 includes video and audio. But you can choose to merge video only plus audio only formats, in this case you need to have installed FFMPEG for the merge, if not installed yet proceed with:

sudo apt install ffmpeg

Then you can download and merge, by example ID 396 (video only) plus ID 139 (audio only) with the following command:

yt-dlp -f 396+139 https://www.youtube.com/watch?v=wh-07BzfgYY

Note: It's possible to download videos not only from YouTube.

-----------------------
The following produce an error and now it has been deprecated. It's better to use a virtual environment as shown here above:

sudo apt install python3-pip

sudo pip3 install --upgrade youtube-dl

-----------
The following is also deprecated:

sudo apt install python-pip

sudo pip install youtube-dl

If you want to upgrade youtube-dl

sudo pip install --upgrade youtube-dl

or, if necessary

sudo pip install --upgrade pip


The following method of installation is even older and deprecated, it's here just as a reference:

sudo apt-get install python-setuptools

sudo easy_install pip

Friday, February 12, 2016

Segmentation fault (core dumped)

If after a segmentation fault you are not getting the core dumped file, you might need to edit the limits.conf (this is in Ubuntu 14.04)

sudo vim /etc/security/limits.conf

and add a line like:
username      soft    core            50000

The previous line is for a core dumped file up to 50000 KB for that user. The user would have to relogin for the changes to take effect. A "small" core dump file is around 10 MB.

-----/// 

Thursday, October 08, 2015

"ffmpeg" instead of "avconv" in youtube-dl

youtube-dl  https://www.youtube.com/watch?v=9SgpcpZU-tw

WARNING: Your copy of avconv is outdated and unable to properly mux separate video and audio files, youtube-dl will download single file media. Update avconv to version 10-0 or newer to fix this.

Use instead:

youtube-dl  --prefer-ffmpeg  https://www.youtube.com/watch?v=9SgpcpZU-tw

.

Sunday, September 27, 2015

Embedding Subtitles in a Video File

The easiest way is with the MP4Box tool.

First install the GPAC

sudo apt-get install gpac

Then you can use the following command

MP4Box  -add  inputfile.srt  target.mp4

More about this command in this link.

Another Option to do so:

apt-get install mkvtoolnix

mkvmerge -o output.mkv video.mp4 subtitles.srt

or

mkvmerge -o output.mp4 video.mp4 subtitles.srt

In the case you need subtitle conversion:

ffmpeg -i file.srt file.vtt

or

ffmpeg -i file.vtt file.srt

More info in the ffmpeg manual ("man ffmpeg").

How to download only subtitles of videos using youtube-dl

Options:
--write-sub                      Write subtitle file
--write-auto-sub                 Write automatic subtitle file (YouTube only)
--all-subs                       Download all the available subtitles of the video
--list-subs                      List all available subtitles for the video
--sub-format FORMAT              Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"
--sub-lang LANGS                 Languages of the subtitles to download (optional) separated by commas, use IETF language tags like 'en,pt'

So for example, to list all subs for a video:

youtube-dl --list-subs https://www.youtube.com/watch?v=Ye8mB6VsUHw

To download all subs, but not the video:

youtube-dl --all-subs --skip-download https://www.youtube.com/watch?v=Ye8mB6VsUHw

The other way, this really works but makes the file bigger:

mencoder movie.avi -sub movie.srt -o movie.hardsubs.avi -oac copy -ovc lavc -lavcopts vbitrate=1200

Source: Ubuntu Forums.


-----------///

Thursday, October 24, 2013

Converting Still Images to Video from the Command Line

ImageMagick and ffmpeg combined can be used to turn still images into video. Both ImageMagick and ffmpeg have been around for years, and are readily available as packages with most Linux distributions. The tips below allow you to convert images on the command line, which for a may appear to be time consuming, but once you know how to do it you'll find it much faster than using a GUI!

The Packages
You'll need:
ImageMagick
ffmpeg


Resizing Images from the Command Line
ImageMagick includes "mogrify" which is a fine tool for easily changing image size and resolution. Great for converting images for uploading to the web, or preparing large images for video. For example, the following code re-sizes all *.JPG images to a maximum width of 800 pixels and a maximum height of 600 pixels. This will over-write the originals, so take copies of your snaps first!

mogrify -resize 800x600 *.JPG

Morphing Images Together
This step is only needed if you want to create a smooth transition between the images.

Another fine part of ImageMagick is the ability to morph images together. In the following example we take all *.JPG files and create 10 images for each "gap" between the images. The resulting set of images are saved as XXXXX.morph.jpg, where X is the next number in the series.

convert *.JPG -delay 10 -morph 10 %05d.morph.jpg

Creating a Video from Images
ffmpeg can be used to stitch several images together into a video. There are many options, but the following example should be enough to get started. It takes all images that have filenames of XXXXX.morph.jpg, where X is numerical, and creates a video called "output.mp4". The qscale option specifies the picture quality (1 is the highest, and 32 is the lowest), and the "-r" option is used to specify the number of frames per second.

ffmpeg -r 25 -qscale 2 -i %05d.morph.jpg output.mp4

Putting It All Together
Here's a simple example of how to create a video from the command line, using the resizing and morphing techniques we have gone through above. The example first creates a "temp" directory to work in, so we don't risk destroying the original images. Note: the morphing stage may take a while, so be patient!

mkdir temp
cp *.JPG temp/.
mogrify -resize 800x800  temp/*.JPG
convert temp/*.JPG -delay 10 -morph 10 temp/%05d.jpg
ffmpeg -r 25 -qscale 2  -i temp/%05d.jpg output.mp4
# rm -R temp

The Code Used

# Create a directory and copy the original images there for manipulation:
mkdir temp
cp *.JPG temp/.

# Resize the images:
mogrify -resize 200x200  temp/*.JPG
# Create the morph images
convert temp/*.JPG -delay 10 -morph 5 temp/%05d.jpg
# Stitch them together into a video
ffmpeg -r 50 -qscale 2  -i temp/%05d.jpg output.mp4

---------------------------///
In order to make a video out of still images, like in a Power Point or Libre Office Impress, I created one image from every slide starting from a blanc one, naming them form 000.rdp.jpg to 025.rdp.jpg, then I used the command:

avconv -r .1 -qscale 2 -i %03d.rdp.jpg output.mp4

The "-r .1" gave 10 seconds lapse for every slide.


----------
Source: It For Everyone.

Creating an ISO image

Create a cdrom image
sudo dd if=/dev/cdrom of=cd.iso

Create a dvd image
sudo dd if=/dev/dvd of=dvd.iso

Create a scsi cdrom image
For a SCSI CDROM image, your device is probably called /dev/scd0
sudo dd if=/dev/scd0 of=cd.iso

Create an ISO image from files in a directory
To create an ISO image from files within a directory is just as simple. State an output directory and name of the ISO to create, along with a source directory. For example:
mkisofs -o /home/linuxlookup/example.iso /source/directory/

Another way to make any Linux directory into an ISO file:

mkisofs -V LABEL -r DIRECTORY | gzip > cdrom.iso.gz

Using GENISOIMAGE to Create ISO-9660 CD-ROM filesystem
sudo apt-get install genisoimage

To create a vanilla ISO9660 filesystem image of directory:
genisoimage -o cd.iso cd_dir

In the next command the -r and -J ensures long file names work for Unix (using Rock Ridge) and Windows (using Joliet extensions).
genisoimage -r -J -o cd_image.iso /directory

Mounting an image

mkdir -p /mnt/isoimage

mount -o loop -t iso9660 cd.iso /mnt/isoimage


Unmounting

umount -lf /mnt/isoimage

Wednesday, December 26, 2012

How to Put a Password on a PDF File on Linux

First you need to have installed the "pdftk" application.


Then type this command into the terminal:
pdftk  original.pdf  output  new.pdf  user_pw  PROMPT

Replace "Original.pdf" with the original name and change "new.pdf" to a name of your choice. Enter a password when prompted. You will now have a password protected PDF.


Saturday, November 17, 2012

How to play movies with subtitles in mplayer

The basic command is:
$ mplayer name_of_movie.avi -vobsub name_of_subtitle 

As you can note, the name of the subtitle is written without any extension which usually are '.idx', '.ifo' or '.sub'.
The next command will do exactly the same than the first:
$ mplayer name_of_movie.avi -vobsub name_of_subtitle -vobsubid 0

If there is a second language available in the captions then you do:
$ mplayer name_of_movie.avi -vobsub name_of_subtitle -vobsubid 1

The name of the subtitles has to be exactly the same than the name of the movie.

Monday, August 08, 2011

Procedure to mount ISO images under Linux

Link to source.

1) You must login as a root user, if not root user then switch to root user using following command:
$ su -

2) Create the directory i.e. mount point:
# mkdir -p /mnt/disk

3) Use mount command as follows to mount iso file called disk1.iso:
# mount -o loop disk1.iso /mnt/disk

4) Change directory to list files stored inside an ISO image:
# cd /mnt/disk
# ls -l

Setting date and time on Linux/Unix

date mmddhhmi

where:
mm = month
dd = day of month
hh = hour
mi = minute

Example for today date:
sudo date 08081530

Another way, set new data to 8 August 2011 15:30:00, type the following command as root user:
# date -s "8 AUG 2011 15:30:00"

OR
# date --set="8 AUG 2011 15:30:00"

You can also simplify format using following syntax:
# date +%Y%m%d -s "20110808"

Linux Set Time
To set time use the following syntax:
# date +%T -s "15:30:00"

Tuesday, May 24, 2011

Ubuntu Tip: Howto reduce PDF file size from command line

Link to the source.

If you want to reduce PDF file size using command line you can use ghostscript.Ghostscript is used for PostScript/PDF preview and printing. Usually as a back-end to a program such as ghostview, it can display PostScript and PDF documents in an X11 environment.

Furthermore, it can render PostScript and PDF files as graphics to be printed on non-PostScript printers. Supported printers include common dot-matrix, inkjet and laser models.

Package gsfonts contains a set of standard fonts for Ghostscript.

Use the following command syntax to reduce your pdf files

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Replace your file names output.pdf, input.pdf files with your file names.

This is only example you can check man gs command for more options.

For  greater file size reduction, change /ebook for /screen but the resolution might not be good enough.

If you want to install ghostscript use the following command

sudo apt-get install ghostscript

------------
Note: You can achieve great reduction in file size using the commands pdftops and then ps2pdf.

Also you can use pdf2ps and then ps2pdf.

Or using the following script from here, and a copy of it here. The usage is the following:
./shrinkpdf.sh  in.pdf  out.pdf
We can optionally specify an output resolution in DPI (default is 72 DPI):
./shrinkpdf.sh  in.pdf  out.pdf  90

--

Friday, April 08, 2011

How To Set Up Journaled Quota On Scientific Linux 6

As you already know, Scientific Linux 6 is a clon of RHEL 6, so this instructions should work for CentOS 6 too.

First do:
yum install quota

Also you have to edit the edit the /etc/fstab and add:
usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0

If you do not need to set quotas for groups then omit the grpjquota=aquota.group as I did, thenin my fstab I have this:

/dev/mapper/vg_aguila-lv_root   /   ext4   defaults,usrjquota=aquota.user,jqfmt=vfsv0   1  1
UUID=8768d821-e441-40fd-ac08-6ef7b6234d0f  /boot  ext4  defaults  1  2
/dev/mapper/vg_aguila-lv_swap  swap  swap  defaults  0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0


After that you need to use the following commands:
touch /aquota.user /aquota.group
chmod 600 /aquota.*
mount -o remount /

quotacheck -avugm
quotaon -avug

if you need to turn the quotas off then do:
 quotaoff /
or the equivalent
quotaon -f /

The quota system is ready to go, now we have to set the quotas for every user:
 edquota -u username

And we get:

Disk quotas for user username (uid 501):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/mapper/vg_aguila-lv_root         36        0          0         10        0        0


The system automatically uses the default editor.
If we want to set 5MB of quota for username then we edit the file to:

Disk quotas for user username (uid 501):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/mapper/vg_aguila-lv_root         36       5000          0         10        0        0




------
Related links:
Quotas on Debian Lenny
RHEL 6 Quotas
faqs.org

Thursday, February 03, 2011

How To Create An ISO Image Of Directory / Filesystem

To create CD ISO image of directories that contain long file name or non-8.3 format (particularly if you want to burn the CD image for use in Windows system), use the -J option switch that generates Joliet directory records in addition to regular iso9660 file names.

mkisofs   -o   MyDirectory.iso   -J   MyDirectory

Wednesday, February 10, 2010

Migrate users from one Linux machine to another

Have you ever had a need to migrate current running Linux users from installation to another? That would be a simple task if the user count was low. But what happens when the user count is in the hundreds? What do you do then? If you’re not using LDAP, you know you will have to migrate the users’ data, passwords, etc from the old machine to the new. Believe it or not, this is just a matter of a few commands – not necessarily simple commands, but it’s not as complex as you would think.

In this article I am going to show you how to make this migration so your Linux users do not loose their data and their passwords are all retained.

What we're migrating

The list is fairly simple:

/etc/passwd - Contains information about the user.
/etc/shadow - Contains the encrypted passwords.
/etc/group - Contains group information.
/etc/gshadow - Contains group encrypted passwords.
/var/spool/mail - Contains users email (the location will depend upon the mail server you use).
/home/ - Contains users data.
Unfortunately these files can not simply be copied from one machine to another – that would be too easy. Just make sure you enter the following commands correctly.

Source machine

These are the commands you will need to run on the machine you are migrating users FROM. I will assume you are doing this on a system that uses a root user (such as Fedora), so all commands will be done as root:

mkdir ~/MOVE

The above command creates a directory to house all of the files to be moved.

export UGIDLIMIT=500

The above command sets the UID filter limit to 500. NOTE: This value will be dictated by your distribution. If you use Red Hat Enterprise Linux, CentOS, or Fedora this value is shown in the command above. If you use Debian or Ubuntu that limit is 1000 (not 500).

awk -v LIMIT=$UGIDLIMIT -F: ‘($3>=LIMIT) && ($3!=65534)’ /etc/passwd > ~/MOVE/passwd.mig

The above command copies only user accounts from /etc/passwd (using awk allows us to ignore system accounts.)

awk -v LIMIT=$UGIDLIMIT -F: ‘($3>=LIMIT) && ($3!=65534)’ /etc/group > ~/MOVE/group.mig

The above command copies the /etc/group file.

awk -v LIMIT=$UGIDLIMIT -F: ‘($3>=LIMIT) && ($3!=65534) {print $1}’ /etc/passwd | tee – |egrep -f – /etc/shadow > ~/MOVE/shadow.mig

The above command copies the /etc/shadow file.

cp /etc/gshadow ~/MOVE/gshadow.mig

The above command copies the /etc/gshadow file.

tar -zcvpf ~/MOVE/home.tar.gz /home

The above command archives /home.

tar -zcvpf ~/MOVE/mail.tar.gz /var/spool/mail

The above command archives the mail directory. NOTE: If you are using Sendmail this is the correct directory. If you are using Postfix that directory most likely will be /etc/postfix.

Now it’s time to move everything in ~/MOVE over to the new server. You can do this using the scp command like so:

scp -r ~/MOVE/* USER@IP_OF_NEW_SERVER:/home/USER/

Where USER is the username you will use to send the file and IP_OF_NEW_SERVER is the address of the new server. NOTE: If this server is not on line yet you can always copy these files onto a thumb drive and move them that way.

Target machine

Now we’re working on the new server. Follow these commands (run as the root user):

mkdir ~/newsusers.bak

The above command will create a new directory that will house the backup of the current users.

cp /etc/passwd /etc/shadow /etc/group /etc/gshadow ~/newsusers.bak

The above command will copy the necessary files to the new backup directory.

cd /PATH/TO/DIRECTORY
cat passwd.mig >> /etc/passwd
cat group.mig >> /etc/group
cat shadow.mig >> /etc/shadow
/bin/cp gshadow.mig /etc/gshadow

The above commands will restore all password files onto the new system. NOTE: Where /PATH/TO/DIRECTORY is the location where you copied the files onto the new system.

cd /
tar -zxvf /PATH/TO/DIRECTORY/home.tar.gz

The above commands will first change you to the / directory and then unpack the archived /home directory. NOTE: Where /PATH/TO/DIRECTORY is the location where you copied the files onto the new system.

cd /
tar -zxvf /PATH/TO/DIRECTORY/mail.tar.gz

The above commands will first change you to the / directory and then unpack the archived/var/spool/mail directory. NOTE: Where /PATH/TO/DIRECTORY is the location where you copied the files onto the new system.

You can now reboot your system with the users in place.
----------
Source: ghacks.net

Monday, January 04, 2010

BibTeX in 60 seconds

[Link to source]
Ok, so you just want to give it a whirl. No worries, just:

  1. Download a bibliography style file such as h-physrev3.bst, into the directory where your document is. (There are many options about - just look around the web.)
  2. Create your bibliography database file by downloading (into the directory where your document is) and editing the example file tau.bib.
  3. Remove any \begin{thebibliography} ... \end{thebibliography} commands from your document.
  4. Just before the \end{document} command, add
    \bibliographystyle{h-physrev3.bst}
    \bibliography{tau}
    (Alternatively, just download and edit this example file.)
  5. When processing the file, you need to do: latex filename, bibtex filename, latex filename, latex filename.
Another useful reference to this is in the Reed College.

Friday, November 27, 2009

How to convert a JPG file to PDF

You need to have installed "ImageMagick" or "GraphicsMagick"
In Ubuntu or Debian you can install it with the command:
sudo apt install imagemagick

or
sudo apt install graphicsmagick

Then you go to your work directory.
cd my/work/directory/path
And write the command
convert myfile.jpg myfile.pdf

Or with GraphicsMagick
gm convert file.jpg file.pdf

To convert multiple images:
gm convert file1.png file2.png file3.jpg file.pdf

For more, just run:
man gm

With ImageMagick you can also convert multiple JPG files into one multi-image PDF
convert *.jpg -adjoin myfiles.pdf

To merge multiple PDFs into one file:

$ pdftk file1.pdf file2.pdf file3.pdf cat output file123.pdf

CONVERTING  WITH  IMG2PDF

sudo apt install img2pdf

img2pdf --pagesize Letter input.jpg -o output.pdf

man img2pdf 



=====///////

Sunday, October 11, 2009

Create, mount and copy floppy disks images under Linux

If we need it we can create an empty image and mount it using linux's loop devices.
(link to page)

Creating an empty floppy image (1.44MB):
$ dd bs=512 count=2880 if=/dev/zero of= /path/imagefile.img
Format it:
$ mkfs.msdos /path/imagefile.img

There's a more direct way to do this.
Create & format a floppy image of 1.44 MB:
$ /sbin/mkfs.msdos -C /path/imagefile.img 1440

Mounting it:
$ sudo mkdir /media/floppy1/
$ sudo mount -o loop /path/imagefile.img /media/floppy1/

If you want to transfer some files to Windows in VirtualBox then, after copying your files into the floppy image, you have to umount the image.
$ umount /media/floppy1

Now in VirtualBox you start Windows and mount the floppy image (Devices ==> Mount Floppy ==> Floppy Image) as you see in the picture.

Then you can transfer the files from the floppy image to Windows. Do not forget to unmount the floppy image once you're done or you'll get an error next time you try to boot into Windows. This is because the virtual machine tries to boot first from the floppy image.
In case you need to transfer bigger files, instead of a floppy image you can use a CDROM image. If you already have the files in a CD, that's easier since you can directly mount the CD.

Sunday, October 04, 2009

Password-Protect Compressed Zip Archives

(link to note)
The Zip program allows you to password-protect your Zip archives using the -P option. You shouldn't use this option. It's completely insecure, as you can see in the following example (the actual password is 12345678):

$ zip -P 12345678 moby.zip *.txt

Because you had to specify the password on the command line, anyone viewing your shell's history (and you might be surprised how easy it is for other users to do so) can see your password in all its glory. Don't use the -P option!

Instead, just use the -e option, which encrypts the contents of your Zip file and also uses a password. The difference, however, is that you're prompted to type the password in, so it won't be saved in the history of your shell events.

$ zip -e moby.zip *.txt
Enter password:
Verify password:
adding: job.txt (deflated 65%)
adding: moby-dick.txt (deflated 61%)
adding: paradise_lost.txt (deflated 56%)

The only part of this that's saved in the shell is zip -e moby.zip *.txt. The actual password you type disappears into the ether, unavailable to anyone viewing your shell history.

Caution - The security offered by the Zip program's password protection isn't that great. In fact, it's pretty easy to find a multitude of tools floating around the Internet that can quickly crack a password-protected Zip archive. Think of password-protecting a Zip file as the difference between writing a message on a postcard and sealing it in an envelope: It's good enough for ordinary folks, but it won't stop a determined attacker.

Also, the version of zip included with some Linux distros may not support encryption, in which case you'll see a zip error: "encryption not supported." The only solution: recompile zip from source. Ugh.

----------
In case you want to ZIP a directory, this is the command:
zip  -re  myDirectory.zip  myDirectory

Monday, September 28, 2009

Tuesday, August 25, 2009

How to create a custom Ubuntu distro

(link to note)
*Get the packaged you need
sudo apt-get install squahfs-tools mkisofs

*Load the squashfs
sudo modprobe squashfs

create a iso image of Dapper CD
* confirm that cdrom is not mounted, if it is then
sudo umount /cdrom

* dd if /dev/hdc of=/pathtoiso/image.iso
else dd if /dev/cdrom of=/pathtoiso/image.iso

* Create a working directory
mkdir ~/custom

* move the iso to custom
mv /pathtoiso/image.iso ~/custom
cd ~/custom

* mount the image.iso
mkdir mnt
sudo mount -o loop image.iso mnt

* get the contents of iso in to a local dir
mkdir extract
rsync –exclude=/casper/filesystem.squashfs -a mnt/ extract

*Mount squashfs
mkdir squahfs
sudo mount -t squashfs -o loop mnt/casper/filesystem.squashfs squashfs
mkdir tmp
sudo cp -r squashfs/* edit

*Mount the root
sudo chroot edit
mount -t proc none /proc
mount -t sysfs none /sys
export HOME=/root

*Customization
Now you have all the settings ready and you can readily customise by apt-get
for eg, to add mplayer
sudo apt-get install mplayer

*The default backgrounds and splashscreens can be simpley copied .

*Edit LiveCD user
sudo vi edit/usr/share/initramfs-tools/scripts/casper-bottom/10adduser
sudo vi edit/usr/share/initramfs-tools/scripts/casper

*Cleanup
rm -rf /tmp/*
umount /proc
umount /sys
exit

chmod +w extraxt/casper/filesystem.manifest
sudo chroot edit dpkg-query -W –showformat=’${Package} ${Version}\n’ > extract/casper/filesystem.manifest
sudo cp extract/casper/filesystem.manifest extract/casper/filesystem.manifest-desktop
sudo sed -ie ‘/ubiquity/d’ extract/casper/filesystem.manifest-desktop
sudo mksquashfs edit extract/casper/filesystem.squashfs
sudo vim extract-cd/README.diskdefines

*Generate new md5sum
sudo -s
rm extract/md5sum.txt
(cd extract && find . -type f -print0 | xargs -0 md5sum > md5sum.txt)
exit

*Create the iso
cd extract
sudo mkisofs -r -V “$IMAGE_NAME” -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../custom.iso .

*You can test the cd by
qemu -cdrom custom.iso -boot d

*Burn the iso using k3b or nautilus-cd-burner
or
cdrecord dev=/dev/hdc custom.iso