Sunday, 27 August 2017

encrypting external drive.

Why do I feel like I've done this before and it's gone wrong? Anway. This was shamelessly copied from somewhere else on the 'net, in which place a comment was present saying trucrypt was a more secure approach. Do some searching. For now, this is a private note.
$ sudo apt-get install cryptsetup
$ sudo fdisk /dev/sdf
d 2                        #  delete partition 2
d 1                        # delete partition 1
w                          # write changes.
sudo fdisk /dev/sdf
n    new
1    partition number
 default first sector = 2048 (not 34 as is available)
 default last sector = 15628053133

Created a new partition 1 of type 'Linux filesystem' and of size 7.3TiB
that should have been 8tB. Grrr.
w                  write.
/dev/sdf   now present.
/dev/sdf1  now present.
sudo modprobe dm-crypt
I don't think this was needed. nice indication of disks attached:
 lsblk
$ sudo cryptsetup -v -y -c aes-xts-plain64 -s 512 -h sha512 -i 5000 --use-random luksFormat /dev/sdf1

-v = verbose
-y = verify passphrase, ask twice, and complain if they don’t match
-c = specify the cipher used
-s = specify the key size used
-h = specify the hash used
-i = number of milliseconds to spend passphrase processing (if using anything more than sha1, must be great than 1000)
–use-random = which random number generator to use
luksFormat = to initialize the partition and set a passphrase
/dev/sdf1 = the partition to encrypt
check the configuration of the luks header:
sudo cryptsetup luksDump /dev/sdf1
LUKS header information for /dev/sdf1

Version:        1
Cipher name:    aes
Cipher mode:    xts-plain64
Hash spec:      sha512
Payload offset: 65535
MK bits:        512Key Slot 0: ENABLED
        Iterations:             1367519
        Salt:                   xx xx xx xx xx xx
                                xx xx xx xx xx xx
        Key material offset:    8
        AF stripes:             4000
Key Slot 1: DISABLED
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED
Back up the header:
sudo cryptsetup luksHeaderBackup --header-backup-file /home/me/luksHeaderBackupFile8TB.img /dev/sdf1
open the container and mount at /dev/mapper/volume01:
sudo cryptsetup luksOpen /dev/sdf1 volume01   
create the ext4 filesystem.
sudo mkfs.ext4 /dev/mapper/volume01   
mount it
sudo mkdir -p /mnt/drive01                       
sudo mount /dev/mapper/volume01 /mnt/drive01
unmount and close the container.
sudo umount /mnt/drive01                          
sudo cryptsetup luksClose /dev/mapper/volume01
Latter mounting/unmounting:
sudo cryptsetup luksOpen /dev/sdf1 volume01
sudo mount /dev/mapper/volume01 /home/ms/mnt/drive01
##DO YOUR WORK HERE##
sudo umount /home/ms/mnt/drive01
sudo cryptsetup luksClose /dev/mapper/volume01

non-blocking ping range with julia


a=[]
for i in 1:254  
    @spawn push!(a, [i, 
        match(r"time=(.*)$", 
            split(readstring(`ping -c 1 10.27.96.$i`),  "\n", 
            keep=false)[2])[1]])  
    print(i)  
    sleep(0.1)  
end  
after a line from https://discourse.julialang.org/t/how-can-i-ping-an-ip-adress-in-julia/3380

Friday, 18 August 2017

nvidia and linux.

How NOT to do it! Get your card ID: lspci -vnn | grep VGA Translate the result at NVIDIA. eg, VGA compatible controller [0300]: NVIDIA Corporation Device [10de:1c30] (rev a1) (prog-if 00 [VGA controller]) gives 10de:1c30 and NVIDIA says this is the quadro p2000. Go to http://www.nvidia.com/Download/index.aspx and fill in the details to establish which driver. I get NVIDIA-Linux-x86_64-384.59.run to download so the version is 384. See if apt-get can do it: sudo apt-get install nvidia-384 AND HOSE YOUR MACHINE! No graphics after this. DO NOT USE! ****************************** Use graphics update from the desktop and don't install anything other than the recommended......

Wednesday, 16 August 2017

Julia dictionaries

Something unexpected happened today with Julia 0.5 dictionaries:

In []: test = Dict(1 => Dict(2 => 3))
       test[4]  = test[1]
       test[1][2] = 5
       test
Out[]: Dict{Int64,Dict{Int64,Int64}} with 2 entries:
       4 => Dict(2=>5)
       1 => Dict(2=>5)
So that looks like reference passing. Changing the original also changes the copy. But,

In []: test = Dict(1 => 2)
       test[3] = test[1]
       test[3] = 4
       test
Out[]: Dict{Int64,Int64} with 2 entries:
       3 => 4
       1 => 2
In the case above adjusting the value in the copy does not affect the value in the original. Maybe the direction of propagation is important:

In []: test = Dict(1 => 2)
       test[3] = test[1]
       test[1] = 4
       test

Out[]: Dict{Int64,Int64} with 2 entries:
       3 => 2
       1 => 4
Nope! Direction did not change the outcome. The dictionary of dictionaries appears to use references but the dictionary of keys and values does not. :|