new hdd bootstrap for linux

cmd.list:
n
p
1
 
+128M
n
p
2
 
+10G
n
p
3
 
+8G
n
e
 
 
n
 
+24G
n
 
 
a
1
t
3
82
w

export sdx=sdb;
fdisk /dev/${sdx} < cmd.list
———
mkfs -t ext3 /dev/${sdx}1;
mkfs -t ext4 /dev/${sdx}2;
mkfs -t ext4 /dev/${sdx}5;
mkfs -t ext4 /dev/${sdx}6;
#optimal for raid10:
mkfs -t ext3 -b 4096 -E stride=64,stripe-width=128 /dev/${sdx}1;
mkfs -t ext4 -b 4096 -E stride=64,stripe-width=128 /dev/${sdx}2;
mkfs -t ext4 -b 4096 -E stride=64,stripe-width=128 /dev/${sdx}5;
mkfs -t ext4 -b 4096 -E stride=64,stripe-width=128 /dev/${sdx}6;
tune2fs -m 0 /dev/${sdx}6;
mkswap /dev/${sdx}3;
#—
#mount:
mkdir /mnt/${sdx}2; mount /dev/${sdx}2 /mnt/${sdx}2; mkdir /mnt/${sdx}2/boot; mount /dev/${sdx}1 /mnt/${sdx}2/boot;
mkdir /mnt/${sdx}2/var; mount /dev/${sdx}5 /mnt/${sdx}2/var; mkdir /mnt/${sdx}2/home; mount /dev/${sdx}6 /mnt/${sdx}2/home;
#—
#copy:
ssh root@srv "tar -vpcf - --numeric-owner --exclude=/dev/* --exclude=/proc/* --exclude=/sys/* --exclude /tmp/* --exclude=/var/cache/apt/archives/* / | gzip -1" | gunzip | tar -pxf - --numeric-owner -C /mnt/${sdx}2
#local copy:
#tar -vpcf - --numeric-owner --exclude=/dev --exclude=/proc --exclude=/sys --exclude /tmp --exclude=/mnt/${sdx}2 / | tar -pxf - --numeric-owner -C /mnt/${sdx}2

#or unpack archive:
#scp root@srv:/path/img.tgz . && tar -pxzf img.tgz --numeric-owner -C /mnt/${sdx}2
#—
#sync:
rsync -az -e ssh --delete $syncfrom $syncto
#local sync:
#rsync -av -e ssh --exclude=/home/* --exclude=/mnt/* --exclude=/proc --exclude=/sys --exclude=/dev / /mnt/${sdx}2/

#—
#chroot:
mkdir /mnt/${sdx}2/dev; mkdir /mnt/${sdx}2/proc; sudo mount --bind /dev/ /mnt/${sdx}2/dev; mount --bind /proc/ /mnt/${sdx}2/proc;
chroot /mnt/${sdx}2 /bin/sh; mount sysfs /sys -t sysfs

#—
grub-install /dev/${sdx};
update-grub2

# /etc/fstab corrections usually required !
ls -l /dev/disk/by-uuid/ | awk {'print $9" "$10$11'}
# [!] change ip address and rename server:
/etc/network/interfaces
/etc/postfix/main.cf
/etc/hostname
/etc/hosts
/etc/mailname
/var/run/motd
#—
# remove previous persistent net rules:
rm /etc/udev/rules.d/70-persistent-net.rules
#—
#unchroot: CTRL+D &&
umount /mnt/${sdx}2/home; umount /mnt/${sdx}2/var; umount /mnt/${sdx}2/boot; umount /mnt/${sdx}2
# shutdown -fr now

Leave a Reply

Your email address will not be published. Required fields are marked *