AM·OS STORAGE NOTES =================== This document describes how to manage disk storage on an installed AM·OS system: how the installer lays out the disk, how to add logical volumes after install, how to shrink the root filesystem, and how to install on an mdadm RAID array. Everything here operates on a live system. All disk-modifying commands should be run as root and, where the text says so, from a rescue environment (the AM·OS install ISO is one). 1. WHAT THE INSTALLER CREATES ----------------------------- The layout depends on the choices made in setup.sh: Plain (no encryption, no LVM): sda1 ext4 / Encrypted (no LVM), BIOS: sda1 ext4 /boot (plain, LILO-readable) sda2 LUKS -> lukssda2 -> ext4 / Encrypted (no LVM), EFI: sda1 vfat /boot/efi sda2 LUKS -> lukssda2 -> ext4 / LVM (no encryption), BIOS: sda1 ext4 /boot (plain, LILO-readable) sda2 LVM PV -> vg0-root -> ext4 / LVM (no encryption), EFI: sda1 vfat /boot/efi sda2 LVM PV -> vg0-root -> ext4 / LVM + LUKS, BIOS: sda1 ext4 /boot sda2 LUKS -> lukssda2 -> LVM PV -> vg0-root -> ext4 / LVM + LUKS, EFI: sda1 vfat /boot/efi sda2 LUKS -> lukssda2 -> LVM PV -> vg0-root -> ext4 / LVM with data volume (any): ...plus vg0-data mounted at the path chosen in the wizard. Why /boot is a separate partition on BIOS when LUKS or LVM is in use: LILO reads the kernel via BIOS int 13h, direct sector access. It cannot see through device-mapper layers. Putting /boot on a plain ext4 partition is what makes LILO able to find the kernel. The LUKS mapper is named luks (e.g. lukssda2 for /dev/sda2). This is the name mkinitrd's boot init script derives at unlock time; matching it keeps crypttab, boot arguments, and the boot init in agreement. 2. ADDING A LOGICAL VOLUME AFTER INSTALL ----------------------------------------- The installer creates a root LV (vg0-root) and, optionally, a data LV (vg0-data). Ten percent of the volume group is left free so you can take snapshots. If you want another volume, you can carve it out of that free space at any time. 1. Check available free space: vgs # VFree column shows what's unallocated. 2. Create the LV: lvcreate -L 2G -n mydata vg0 3. Format it: mkfs.ext4 -L amosdata /dev/vg0/mydata 4. Mount it somewhere to migrate data, or add it to /etc/fstab: UUID=$(blkid -s UUID -o value /dev/vg0/mydata) echo "UUID=$UUID /mnt/mydata ext4 defaults 1 2" >> /etc/fstab mkdir -p /mnt/mydata mount /mnt/mydata To relocate a service's data directory to the new volume, stop the service, copy the data with cp -a (or rsync -aHAX), update the mount point in /etc/fstab to the service's expected path, and start the service. The root filesystem is untouched. Snapshots work the same way: lvcreate -L 1G -s -n rootsnap /dev/vg0/root # ... do the risky operation ... lvremove /dev/vg0/rootsnap # discard on success # or, on failure: umount / ; lvconvert --merge vg0/rootsnap 3. SHRINKING THE ROOT FILESYSTEM --------------------------------- Shrinking root is only supported on ext4. XFS cannot be shrunk. btrfs can but has its own subtleties; not covered here. The operation must be done offline (root unmounted), so it can only be performed from a rescue environment. The AM·OS install ISO is a rescue environment. The order of operations is non-negotiable: shrink FS -> verify FS -> reduce LV -> grow FS -> verify FS Running lvreduce before resize2fs destroys data. The kernel truncates the block device out from under the filesystem and ext4's metadata gets cut in half. Procedure for shrinking vg0/root from 17 GiB to 10 GiB: 1. Boot the install ISO. Get to the installer shell. Do NOT run setup. 2. Activate LVM. If LUKS, unlock first: # Plain LVM: vgchange -ay vg0 # LUKS + LVM: cryptsetup open /dev/sda2 lukssda2 vgchange -ay vg0 3. Do NOT mount the root LV. 4. Force a full filesystem check: e2fsck -f /dev/vg0/root 5. Check the minimum size the filesystem can shrink to: resize2fs -P /dev/vg0/root If the floor is above your target, you cannot shrink to that size without deleting data first. 6. Shrink the filesystem to slightly below the target LV size. Target LV = 10 GiB, so shrink FS to 9.5 GiB, leaving 0.5 GiB of headroom: resize2fs /dev/vg0/root 9.5G 7. Reduce the LV to 10 GiB: lvreduce -L 10G /dev/vg0/root 8. Grow the filesystem back to fill the LV exactly: resize2fs /dev/vg0/root 9. Verify: e2fsck -f /dev/vg0/root Must pass cleanly. Do not proceed otherwise. 10. Create the new LV with the freed space: lvcreate -L 7G -n data vg0 mkfs.ext4 -L amosdata /dev/vg0/data 11. Reboot. The system boots normally with vg0/root at 10 GiB and vg0/data at 7 GiB. Add vg0/data to /etc/fstab as in section 2. 4. INSTALLING ON AN MDADM RAID ARRAY ------------------------------------- The installer does not have a RAID wizard. Manual mode lets you prepare any block device as root, including an mdadm array. Procedure for RAID1 on two equal disks (/dev/sda, /dev/sdb): 1. Boot the install ISO. Choose Manual mode in the wizard. 2. When prompted, drop to the shell. 3. Create the array: mdadm --create /dev/md0 --level=1 --raid-devices=2 \ --metadata=1.2 /dev/sda /dev/sdb Wait for the initial resync to complete: watch cat /proc/mdstat (Ctrl-C to exit watch.) 4. Format it, or encrypt-and-format: # Plain: mkfs.ext4 -L amosroot /dev/md0 # Encrypted: cryptsetup luksFormat /dev/md0 cryptsetup open /dev/md0 cryptroot mkfs.ext4 -L amosroot /dev/mapper/cryptroot 5. Exit the shell. Select /dev/md0 (or /dev/mapper/cryptroot if encrypted) as the root device when prompted. 6. Finish the wizard and let the installer run. 7. After install, before rebooting, verify /etc/mdadm.conf on the target references the array. If it's missing or empty: mdadm --detail --scan >> /etc/mdadm.conf The initrd's mkinitrd command generator detects the mdadm array via /proc/mdstat and includes the correct modules. Note on degraded boot: if a RAID1 array is missing one disk at boot time, Linux will assemble it in degraded mode by default. You will get a warning but the system will boot from the surviving disk. To repair, replace the failed disk and: mdadm --manage /dev/md0 --add /dev/sdX watch cat /proc/mdstat The array rebuilds in the background. Check periodically with cat /proc/mdstat; look for a "recovery=" line indicating progress. RAID is not backup. A mirror protects against a disk failure. It does not protect against accidental deletion, corruption, ransomware, or theft of the whole machine. Keep independent backups of any data whose loss you cannot tolerate. 5. FURTHER READING ------------------ man lvm man lvcreate man lvresize man resize2fs man e2fsck man mkinitrd man mkinitrd.conf man mdadm man mdadm.conf /usr/share/mkinitrd/mkinitrd_command_generator.sh --help (on the target)