📜 ⬆️ ⬇️

Saving flash drive based on Linux Debian / Ubuntu distribution

I'll start with the essence of the idea - a bunch of identical computers, they need to install Windows XP with the same set of programs. The first thought is to set up one reference computer, remove the hard disk image from it and deploy it to other computers.

Acronis was not suitable for "religious reasons" of the company.

Looking for a DIY solution, I came across a wonderful thing ntfsclone from the package ntfsprogs.
')
It should be noted that there is no optical disc drive in computers, there is no transferable office in the office, therefore there are two options: run with a screwdriver and drive alternately to each machine or use a USB flash drive. I liked the flash drive option more. Therefore, it stopped and began to study the issue.

To start creating a saving flash drive, we need:
1) A computer with an installed OS from the Linux family.
2) A flash drive does not play a special role, the more - the better.
3) Debian / Ubuntu installation image (I personally chose Ubuntu Server 10.04)

I chose the option to install the OS on the USB flash drive by copying the VirtualBox partition (vdi).

1) Install VirtualBox.
- Install the necessary packages for VirtualBox:
apt-get install qemu-utils virtualbox-ose
- Launch VirtualBox
- Create a virtual machine of operatives take 512mb or more, create a new hard disk file and call it arbitrarily, the main thing is its size - it should be slightly smaller than the size of the prepared flash drive (my flash drive was at 7.6Gb I took the partition as 7.5Gb)
- As a drive, select the ISO image of the distribution of the OS you want to put on the USB flash drive (in my case, UbuntuServer 10.04)
- We start the virtual machine.

2) Install the OS on a virtual machine.
- We go point by point like with a standard installation, we stop at the breakdown of the hard disk - I highly advise not to do the SWAP partition, the flash drive can die quickly (my version of the breakdown was elementary - all the free space is at the root)
- We continue to install further without question.
- Upon completion of the installation I advise you to shove / tmp in tmpfs - there are two reasons, a slight acceleration of work, as well as a decrease in the wear of the flash drive.
tmpfs /tmp tmpfs size=100M 0 0
- Restart the car if everything goes well.

3) Prepare the operating system.
I would like to note one more fact, a person who is completely unfamiliar with the Linux family will be involved in installing the systems, therefore the task is somewhat complicated, it must be done so that the person would not have to climb the console and look for the right commands, so it was decided to make a GUI based on dialog.
- We give ourselves rutovy privileges
sudo -s
- Create the necessary folders where the scripts and the image of the system will be stored.
mkdir /recovery
mkdir /recovery/img
mkdir /recovery/shell

- Next, it is necessary that when the system starts, the script immediately loaded.
touch /recovery/shell/start.sh
chmod +x /recovery/shell/start.sh
nano /etc/init/tty1.conf

The tty1.conf file contains the settings for launching the first virtual console, commenting exec / sbin / getty -8 38400 tty1 and adding exec /recovery/shell/start.sh> / dev / tty1 to it, all output of the script will be sent to the first virtual console.
- then for work we need the ntfsclone binary from the ntfsprogs package.
apt-get install ntfsprogs
- For the beauty of scripts need a package dialog.
apt-get install dialog
- Go to the simplest - scripts to create an image and restore the system.
nano /recovery/shell/start.sh
#!/bin/bash
dialog --title "Recovery" \
--backtitle "RecoveryShell" \
--yesno "Are you sure you want recovery OS?" 7 60
response=$?
case $response in
0) clear ; /recovery/shell/start_recovery.sh;;
1) clear ; /recovery/shell/exit.sh;;
255) clear ; /recovery/shell/create_img.sh;
esac
^X

I'll comment a little bit - here we have created a simple yes / no dialog, however, there are 3 options - double-pressing the ESC key, so we get to the image creation script.
- Write a script to restore the image.
nano /recovery/shell/start_recovery.sh
#!/bin/bash
gunzip -c /recovery/img/backup.img.gz | ntfsclone -r -O /dev/sda1 -
^X

- We write an image creation script.
nano /recovery/shell/create_img.sh
#!/bin/bash/
ntfsclone --save-image -o - /dev/hda1 | gzip -c > /recovery/img/backup.img.gz
^X

- We write the exit script.
nano /recovery/shell/exit.sh
#!/bin/bash
reboot
^X

- In general, the OS preparation is completed.

4) Transferring a virtual hard disk to a USB flash drive (run on the computer where VirtualBox is installed).
- Convert VDI to RAW (used on hard drives)
VBoxManage clonehd -f vdi -O raw input.vdi output.img
Where input.vdi file is the hard disk of the virtual machine.
- Copy RAW image to a USB flash drive.
dd if=output.img of=/dev/sdc
Where / dev / sdc flash drive.
Now please be patient. copies kraaine slowly (it took me about 3-4 hours).

5) Run it!
- If everything is done right then insert the flash drive and enjoy the result.


The reference computer was processed using the Sysprep utility.
(Sysprep) - , Windows . Sysprep , (SID) . Sysprep , , .
(c) microsoft.com

Source: https://habr.com/ru/post/140436/


All Articles