I tried shrinking a btrfs lvm partition to make room for another new partition. I've used fdisk. I deleted and recreated the btrfs partition. To my despair, the btrfs partition is now typeless. I tried
$ sudo btrfs restore /dev/sda6 /mnt/sda6/
No valid Btrfs found on /dev/sda6
Could not open root, trying backup super
No valid Btrfs found on /dev/sda6
Could not open root, trying backup super
No valid Btrfs found on /dev/sda6
Could not open root, trying backup super
$ sudo btrfs rescue chunk-recover /dev/sda6
read super block error
recover prepare error
Chunk tree recovery failed
$ sudo btrfs rescue super-recover /dev/sda6
No valid Btrfs found on /dev/sda6
Usage or syntax errors
With parted I first decreased the size of the previous partition. /dev/sda5 and now I was able to mkpart with the old start sector of the deleted partition. voila! got back the deleted partition with all files intact.
Related
I'm fairly new to linux but decided to dive right in with arch-linux to become familiar with everything.
Unfortunatelly I can't even finish the installation - shame on me.
The error while booting after setting arch up is:
ERROR: Root device mounted successfully, but /sbin/init does not exist.
Bailing out, you are on your own. Good luck.
I went for btrfs on luks on lvm
The layout looks like this
sda
|- sda1 512MB fat32 /boot
`- sda2 remaining lvm
|- cryptswap 4GB swap
|- crypttmp 2GB tmp /tmp
`- cryptroot remaining btrfs
|- # /
|- #home /home
|- #snapshots /.snapshots
|- #log /var/log
|- #cache /var/cache
`- #tmp /var/tmp
Those are the commands and configurations I used to setup arch:
dd status=progress if=/dev/zero of=/dev/sda
wipe disk
gdisk /dev/sda
o clear gpt table
boot partition
n
↵
↵
+512M
ef00
lvm partition
n
↵
↵
↵
8e00
w write partition changes
setup lvm
pvcreate /dev/sda2
vgcreate vg1 /dev/sda2
lvcreate -L 4G -n cryptswap vg1
lvcreate -L 2G -n crypttmp vg1
lvcreate -l 100%FREE cryptroot vg1
setup encryption
cryptsetup luksFormat /dev/vg1/cryptroot
cryptsetup open /dev/vg1/cryptroot root
make filesystems
mkfs.fat -F32 -n BOOT /dev/sda1
mkfs.btrfs --label ROOT /dev/mapper/root
create btrfs subvolumes
mount /dev/mapper/root /mnt
cd /mnt
btrfs subvolume create #
btrfs subvolume create #home
btrfs subvolume create #snapshots
btrfs subvolume create #log
btrfs subvolume create #cache
btrfs subvolume create #tmp
cd ..
umount /mnt
mount btrfs subvolumes and BOOT partition
mount -o noatime,compress=lzo,space_cache=v2,discard=async,subvol=# /dev/mapper/root /mnt
mkdir /mnt/home
mount -o noatime,compress=lzo,space_cache=v2,discard=async,subvol=#home /dev/mapper/root /mnt/home
mkdir /mnt/.snapshots
mount -o noatime,compress=lzo,space_cache=v2,discard=async,subvol=#snapshots /dev/mapper/root /mnt/.snapshots
mkdir /mnt/var
mkdir /mnt/var/log
mount -o noatime,compress=lzo,space_cache=v2,discard=async,subvol=#log /dev/mapper/root /mnt/var/log
mkdir /mnt/var/cache
mount -o noatime,compress=lzo,space_cache=v2,discard=async,subvol=#cache /dev/mapper/root /mnt/var/cache
mkdir /mnt/var/tmp
mount -o noatime,compress=lzo,space_cache=v2,discard=async,subvol=#tmp /dev/mapper/root /mnt/var/tmp
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
pacstrap /mnt base linux linux-firmware lvm2 btrfs-progs amd-ucode vim install necessities
genfstab -L /mnt > mnt/etc/fstab generate fstab
arch-chroot /mnt
basic configuration
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
hwclock --systohc
vim /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
echo "KEYMAP=de-latin1" >> /etc/vconsole.conf
echo "devstation" >> /etc/hostname
vim /etc/hosts
vim /etc/mkinitcpio.conf
the mkinitcpio.conf content:
MODULES=(btrfs)
HOOKS=(base udev autodetect keyboard keymap consolefont modconf block lvm2 encrypt filesystems fsck)
mkinitcpio -p linux
bootctl install
echo "default arch" > /boot/loader/loader.conf
vim /boot/loader/entries/arch.conf
the arch.conf content
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options cryptdevice=UUID={/dev/vg1/cryptroot uuid inserted here}:root root=/dev/mapper/root rw
exit
umount -a
poweroff
Pulling the arch installation medium out of the computer and starting it.
The booting output
:: running early hook [udev]
Starting version 248.3-2-arch
:: running hook [udev]
:: Triggering uevents...
:: running hook [keymap]
:: Loading keymap...done.
:: running hook [encrypt]
A password is requires to acces the root volume:
Enter passphrase for /dev/mapper/vg1-cryptroot: {inserting passphrase}
:: performing fsck on '/dev/mapper/root'
:: mounting '/dev/mapper/root' on real root
:: running cleanup hook [udev]
ERROR: Root device mounted successfully, but /sbin/init does not exist.
Bailing out, you are on your own. Good luck.
sh: can't access tty; job control turned off
[rootfs ]#
Obviously I didnt setup cryptswap and crypttmp, yet. Those will be setup with crypttab and fstab. I am just mentioning this, and highly doubt it is part of the problem, because they are just partitions not recognized by anything at the moment, aren't they.
I hope I didn't miss any command or configuration I did - I am typing off videos I watched and from head, because no single video I found had the btrfs, luks, lvm config I went with. Thanks for your time/help and reading this through.
Adding rootflags=subvol=# to /boot/loader/entries/arch.conf like so
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options cryptdevice=UUID={/dev/vg1/cryptroot uuid inserted here}:root root=/dev/mapper/root rootflags=subvol=# rw
did the trick.
I ran the following command to install Nix on my Mac:
sh <(curl -L https://nixos.org/nix/install) --daemon --darwin-use-unencrypted-nix-store-volume
And I got the following error:
error: refusing to create Nix store volume because the boot volume is
FileVault encrypted, but encryption-at-rest is not available.
Manually create a volume for the store and re-run this script.
See https://nixos.org/nix/manual/#sect-macos-installation
https://nixos.org/nix/manual/#sect-macos-installation says:
If you're using a recent Mac with a T2 chip, your drive will still be encrypted at rest (in which case "unencrypted" is a bit of a misnomer). To use this approach, just install Nix with:
sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
If you don't like the sound of this, you'll want to weigh the other approaches and tradeoffs detailed in this section.
I don't have a mac with a T2 chip, so what do I do?
I found some related github issues, but no direct answer.
I chose to use the Use a separate encrypted volume suggestion as outlined in by Philipp Haussleiter:
This approach only works if you have a Disk that is formated with APFS (that should always be the case, if your OS is running of a SSD).
You can check this with:
% diskutil list | grep APFS
…
0: APFS Container Scheme - +250.8 GB disk1
…
Create another Volume on your Disk for NIX:
% sudo diskutil apfs addVolume disk1 'APFS' nix
Will export new APFS Volume "nix" from APFS Container Reference disk1
Started APFS operation on disk1
Preparing to add APFS Volume to APFS Container disk1
Creating APFS Volume
Created new APFS Volume disk1s6
Mounting APFS Volume
Setting volume permissions
Disk from APFS operation: disk1s6
Finished APFS operation on disk1
Your disk may not be named disk1s6. Find the name of your disk with:
% diskutil list | grep nix
4: APFS Volume nix 7.7 GB disk1s6
Again, your disk may not be named disk1s6.
Encrypt disk:
You need to enter a passphrase for the encryption. You have to
remember that passphrase once – you can add it to your key chain later
on. After that the disk encryption will start in the background.
% sudo diskutil apfs encryptvolume disk1s6 -user disk
Passphrase for the new "Disk" user (672C4CFF-34C6-4407-83ED-294C1C42E161):
Repeat passphrase:
Starting background encryption with the new "Disk" crypto user on disk1s6
The new "Disk" user will be the only one who has initial access to disk1s6
The new APFS crypto user UUID will be 672C4CFF-34C6-4407-83ED-294C1C42E161
Background encryption is ongoing; see "diskutil apfs list" to see progress
Setup Mount Point:
MacOS Catalina does not allow to create folders directly under your
Root Path /. But we can use another method to have MacOS create that
folder for us. To do this, we have to add an entry into the file
/etc/synthetic.conf:
% sudo bash -c 'echo nix >> /etc/synthetic.conf'
Now, the next time, the system starts, a mount point /nix will be
created. The next task is to have our Volume mounted at Boot.
Setup Mount:
For the Mount Configuration, we need to the UUID of the Volume. We can
find this via the diskutil tool (again, your disk may not be named
disk1s6):
% diskutil info /dev/disk1s6 | grep UUID
We must edit /etc/fstab with vifs:
% sudo vifs
(vifs behaves just like vi, so use vi commands to edit the file):
UUID=1D9389C1-5676-4077-88F5-8D5304A0B1A6 /nix apfs rw
(Your UUID will be different!)
Reboot. You will get a GUI prompt to enter your encryption passphrase,
and save it to the keychain.
I then ran:
sh <(curl -L https://nixos.org/nix/install) --daemon
The --darwin-use-unencrypted-nix-store-volume option isn't necessary because we have an encrypted volume now.
RAM disk can be created in command line with different commands on different operating systems.
For example, to create a RAM disk of 512MB ---
On macOS:
diskutil eraseVolume HFS+ "RAMDisk" `hdiutil attach -nomount ram://1048576`
On Ubuntu:
mkdir /mnt/ramdisk
mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk
Is there any cross-platform method/way to create a RAM disk in Golang?
How to cache a particular directory in RHEL / CentOS ? Suppose I have a directory which contains 10 GB data and I've 48 GB of RAM. How to cache all these data inside the directory(only this specific directory) to my memory for a specific amount of time or indefinitely ?
There's a standard memory device on each Linux system /dev/shm.
When you run the mount command you will see:
tmpfs on /dev/shm type tmpfs (rw)
Generally it's about half the size of the system's memory so if you have 48GB of RAM, its size will be about 24GB. ( you can check this by running df -h )
You can use /dev/shm as if it was a normal hard drive, for example, you can copy a file to it:
cp -r "YOUR DIRECTORY" /dev/shm/
that will do the tirck
I am trying to create a dm-zero device and mount it,but getting the following errors during mount.I have been stuck here for very long. Any help will be appreciated.
Error
mount: wrong fs type, bad option, bad superblock on /dev/mapper/zero_1,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so
steps I followed are:
dmsetup create zero_1 --table '0 20000 zero'
mkfs -t ext2 /dev/mapper/zero_1
mount -t ext2 /dev/mapper/zero_1 /mnt
dmesg says:
[ 2547.110310] EXT2-fs (dm-0): error: can't find an ext2 filesystem on dev dm-0.
Really? dm-zero creates device that returns only 0s. So you will never see ext2 filesystem.