Create a False Sized 1TB Flash Drive

Here is how my version of the script looks. I went through each necessary step individually, and left any step I didn't follow commented out in the script. Make any changes you need to:

!/usr/bin/sudo bash


This will list all the drives attached to the system.

echo What drive would you like to use? Be careful. This tool can be system destroying. echo (e.g.\; /dev/sda1)

Prints text to STOUT.

read DRIVE

Reads user input from STDIN.

I skipped this part as my drive was already mounted.

mount $DRIVE

echo $DRIVE mounted

Mount whichever system disk you need from lsblk output to fake the size of.

echo CD to /tmp cd /tmp

Change to temp directory.

echo Creating a Directory named \"flash\" mkdir flash

Create a directory called flash.

echo CD to /tmp/flash cd flash

Change directory to the newly created "flash" directory.

echo 'Enter file size in Kilobytes (1000000000 = 1TB) : ';read FILESIZE

Ask user for fake file size in kilobytes.

echo Creating MSDOS File System mkdosfs -C temp_file $FILESIZE

mkdosfs creates a MSDOS file system in the file "temp_file" with a kilobyte size of 1tb or 1e+9 or user defined file size.

ls -lha

This will show you the list of files in the current working directory displaying the header info as 954G's.

ls -sh

This will show you the TRUE file size, NOT header info.

echo Unmounting $DRIVE
umount $DRIVE

Unmount whichever system disk you used on line 2.

ls -s temp_file

List files and displays the size of the temp in non-human readable (dropping -h).

echo Requesting escalation to root \for \write to $DRIVE

Ignore the "\" in front of for/write. This was done to fix an issue with the color coding of words in my text editor.

sudo su

Elevate shell to root privileges.

Here I had to re-declare the DRIVE variable as it didn't carry over into my root session...

read DRIVE

I use the same variable as in the regular user terminal session.

head -c 244136K temp_file > $DRIVE

Redirect readout at 244136K of temp_file to $drivename.

echo Write successful, de-escalating shell exit

De-escalate shell to normal user privilege.

Here I remounted the $DRIVE, otherwise it didn't show up in the results of the next step.

sudo mount $DRIVE /media/joshd

The mount point (/media/joshd) is obviously going to be user specific, as any other user might choose a different mount point.

df -h

Display file sizes (-h human readable i.e.; 1Mb instead of 1024kb) as read from header.

sudo fdisk $DRIVE

Displays actual file size.

I didn't follow through with the rest of the steps, as I was having trouble with the mlabel/dosfslabel commands.

echo 'Input New Label for Drive (e.g.; 1 TB DRIVE) : ';read $DRIVENAME

Ask user for new drive label.

sudo mlabel -i /dev/sd# ::"$drivename"

Relabel drive using the mlabel tool.

sudo dosfslabel /dev/sd# "$drivename"

Relabel drive using dosfslabel tool.

echo Complete! Drive should now reflect as $drivename and $drivesize in KB

/r/SecureMyPC Thread