\input{../../src/parts/template.tex}

\begin{titlepage}
  \newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % Defines a new command for the horizontal lines, change thickness here

  \center % Center everything on the page

  \textsc{\LARGE QubesOS articles}\\[1.5cm] % Name of your university/college
  %\textsc{\Large Nvidia driver debugging}\\[0.5cm] % Major heading such as course name
  %\large Yukikoo\\[0.5cm] % Minor heading such as course title

  \HRule \\[0.4cm]
  { \huge \bfseries MISC}\\[0.4cm] % Title of your document
  \HRule \\[1.5cm]
 % If you don't want a supervisor, uncomment the two lines below and remove the section above
  \Large \emph{Author:}\\
  Neowutran \\[3cm] % Your name

    \begin{multicols}{2}
  \includegraphics[width=80mm]{shinra.png}\\[1cm] % Include a department/university logo - this will require the graphicx package
      \columnbreak
  \includegraphics[width=80mm]{neowutranlogo.png}\\[1cm] % Include a department/university logo - this will require the graphicx package
    \end{multicols}
  \vfill % Fill the rest of the page with whitespace

\end{titlepage}

 \tableofcontents                                                                
    \pagebreak 


\section{Nitrokey and QubeOS}
To use a nitrokey on QubeOS, a USB passhrough is required.
This means, you need to have a sys-usb VM.
\href{https://www.qubes-os.org/doc/usb/\#attaching-a-single-usb-device-to-a-qube-usb-passthrough}{This is mentioned in the Qubes Documentation.}
\begin{minted}{text}
Note, you cannot pass through devices from dom0
(in other words: a USB VM is required).
\end{minted}
If you are using a USB keyboard, the sys-usb VM is not installed by default.
If you are using a USB keyboard, you have 2 options:
\begin{itemize}
\item Create a sys-usb VM and assign a USB Controller to it.
\item If you can't assign a USB Controller (ex: You only have 1 on your computer and can't buy another), then buy and use a PS/2 Keyboard.
\end{itemize}

\section{Recovery: Mount disk}

\begin{minted}{bash}
#!/bin/bash

########################################################
# Make a LVM image appear in qvm-block
# Create a disposable VM
# Attach the image to the newly created disposable VM
# Wait until the disposable VM is destroyed
# Remove the LVM image from the qvm-block list
######################################################

image=${1?Image file is required, example "/dev/qubes_dom0/vm-debian-9-tmp-root"}
dvm=${2?DVM template name is required, example: "fedora-29-dvm"}
dev=$(basename $(readlink "$image"))
qubesdb-write 
/qubes-block-devices/$dev/desc "$image"
list_before=$(qvm-ls | cut -d " " -f1 | sort)
qvm-run -v --dispvm=$dvm --service qubes.StartApp+xterm &
sleep 5
list_after=$(qvm-ls | cut -d " " -f1 | sort)
diff=$(comm -3 <(echo "$list_before") <(echo "$list_after"))
qvm-block attach $diff dom0:$dev
wait
qubesdb-rm /qubes-block-devices/$dev/
\end{minted}

Then mount the volume.
\begin{minted}{bash}
mount /dev/xxxx /xxxxx 
\end{minted}

In some case, the volume is partitionned, so you need to mount the partition.
First, print the partition table

\begin{minted}{bash}
sudo parted /dev/XXXXXXXXXX unit B print
\end{minted}

Example:

\begin{minted}{bash}
$:sudo parted /dev/windows-vg/vg-game-root unit B print
Model: Linux device-mapper (thin) (dm)
Disk /dev/dm-138: 314572800000B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start       End            Size           Type     File system  Flags
 1      1048576B    105906175B     104857600B     primary  ntfs         boot
 2      105906176B  314571751423B  314465845248B  primary  ntfs
\end{minted}

Then mount the partition you want

\begin{minted}{text}
sudo mount -o loop,offset=105906176 -t ntfs /dev/XXXXXXXXXX /mnt/
\end{minted}

\batchmode
\end{document}

