Make existing or already installed root file system encrypted - linux

I'm having an existing manjaro linux installation and my root file system is not encrypted. How do i encrypt my file system without reinstall or lossing any data. Is it possible to copy root file system to another encrypted drive using live cd then make that as my root file system. Can anyone guide me on this.
/dev/sda1 is my root file system which is of size 80gb
/dev/sda2 is my swap which is of size 4GB

superuser.com is more relevant for this kind of questions.
Check out this answer, which uses cryptsetup-reencrypt to do an offline in-place encryption of a block device, e.g. a partition.
If that doesn't suit you, you can also create an encrypted partition and copy files using rsync -a /old /new.

Related

system not booting after moving /usr directory

I run a Linux VM on VirtualBox and just made a mistake by moving the contents in /usr to a different partition mounted as /u01. My intention was to free up space for the / file system but realized I should have used cp instead of mv. It's not possible to run any command now. Is there any way I can recover the system?
Fixed by booting with iso image and mounting the root and restored the contents back to original partition.

Temp directory on root drive runs out of space when PUTing a large file into Apache

I'm putting (via curl on a client) a 10GB file up into an Apache server on Ubuntu Linux (v17.04). The root drive was pretty much full, and the ultimate destination for the PUT is a subversion root that is on a huge drive that's not root. The only other technology involved is mod_dav_svn.
How to move the tmp folder for Apache to that root drive too?
In modern Apache2 installs there's a /etc/apache2/envvars file that can happily have a line added to set the TMPDIR environmental variable.
Reboot Apache and it'll pick that up and run with it.
I've tested it over and over, and it works well (free space on the boot drive does not jeopardize the PUT of the large file).

How to extract/decompress this multi-part zip file in Linux?

I have a zip file thats titled like so file1.zip,file2.zip,file3.zip,etc...
How do I go about extracting these files together correctly? They should produce one output file.
Thanks for the help!
First, rename them to "file.zip", "file.z01", "file.z02", etc. as Info-ZIP expects them to be named, and then unzip the first file. Info-ZIP will iterate through the split files as expected.
I found a way. I had to mount the remote machines user home folder on my Ubuntu desktop pc and use File Roller Archive Manager, which is just listed as Archive Manger in Ubuntu 18.
Mount remote home folder on local machine...
Install sshfs
sudo apt install sshfs
Make a directory for the mount. Replace remote with whatever folder name you want
mkdir remote
Mount the remote file system locally replacing linuxusername with the user account you want to use to login and xxx.* with its IP address or hostname.
sudo sshfs -o allow_other linuxusername#xxx.xxx.xxx.xxx:/ remote
Now in the mounted "remote" folder you can see the contents of the whole linux filesystem and navigate them in a File Manager just like your local file system, limited by user privileges of course where you can only write to the home folder of the remote user account.
Using Archive Manager I openened up the .zip file of the spanned set (not the .z01, .z02 etc files) and extracted inside the "remote" folder. I saw no indication of extraction progress, the bar stayed at 0% until it was complete. Other X Windows based archive applications might work.
This is slow, about 3-5 megabytes per second on my LAN. I noticed Archive Manager use 7z to extract but do not know how as 7z is not supposed to support spanned sets.
Also if your ssh server is dropbear instead of openssl's sshd it will be unbearably slow for large files. I had to extract a 160gb archive and the source filesystem was fat32 so was not able to combine the spanned set into one zip file as it has a 4gb file size limit.

how to reset kernel while the device is booted up?

How to replace the contents of rootfs partition while the device is booted up?
I am using pine64 (1GB) with stripped debian version and struck in writing a factory reset script which will replace all files in the rootfs partition while the device is running? resident restore file could be tar or img file.
I have already tried two approaches
dd the partition from image to the partition on device.
sudo dd if=pine-debian.img skip=*start of rootfs partition* seek=*start of rootfs partition* of=/dev/mmcblk0
Extract the compressed content to the / directory.
sudo tar -C / -zxvf pine-debian.tar.gz
After both the approaches, the system can recognize any command, not even ls. Any help will be appreciated about how to solve this. how to replace fs content while the device is running?
Ideally, you should have two partitions each with a copy of the rootfs. You can write the partition that is currently not in use with dd, and then update the bootloader configuration to point to the just written partition as the root. swupdate supports such a dual-bank scenario, but it only has native support for U-Boot; if you use a different bootloader, you'll have to add a script to perform the swap.
If you really need to overwrite in-place, directly overwriting the partition is not possible because that filesystem is currently in use. Untarring will also fail because some files are currently in use - in particular libc. You could try to add the --unlink-first option to the untar command, but I'm not sure if that works.
Two other options:
Instead of overwriting the full rootfs, use Debian package upgrades. They have pre- and post-install scripts to make the upgrade safe.
Swap to a (temporary, small) in-RAM root filesystem to perform the upgrade. This root filesystem should just contain busybox and the script that performs the upgrade. You can either kill all processes and then do a pivot_root into the temporary rootfs, or you can use kexec --initrd=... to boot into the in-RAM root filesystem.

How can I create a ext3 filesystem with content (files/dirs) and pack them in a binary file?

I would like to create a binary file to be flashed on a SD card. This file should contain a single ext3 partition and should have some files/directories already in it.
How could I do this avoiding using any command which would require root privileges.
Thak you very much!
As user3159253 told in his comment I used genext2fs along with tune2fs to enable journaling (ext3). For having a block size > 1024 bytes you must build the latest genext2fs sources, the one provided in Ubuntu 12.04 LTS doesn't offer such options being a bit old.

Resources